blob: 256212c6f79a5a37b1d6b07c14faba91e5958713 [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;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000226import java.util.Collection;
sandeepjsb6c87872021-09-27 15:34:44 +0000227import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800228import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800229import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800230import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100231import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700233import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800237import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800238import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240/**
241 * Implementation of the ITelephony interface.
242 */
Santos Cordon117fee72014-05-16 17:56:12 -0700243public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 private static final String LOG_TAG = "PhoneInterfaceManager";
245 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
246 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 // Message codes used with mMainThreadHandler
250 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700251 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
252 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 private static final int CMD_OPEN_CHANNEL = 9;
254 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
255 private static final int CMD_CLOSE_CHANNEL = 11;
256 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800257 private static final int CMD_NV_READ_ITEM = 13;
258 private static final int EVENT_NV_READ_ITEM_DONE = 14;
259 private static final int CMD_NV_WRITE_ITEM = 15;
260 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
261 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
262 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_RESET_MODEM_CONFIG = 19;
264 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800265 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
266 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800267 private static final int CMD_SEND_ENVELOPE = 25;
268 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000269 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
270 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700271 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
272 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
273 private static final int CMD_EXCHANGE_SIM_IO = 31;
274 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
276 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700277 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
278 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700279 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
280 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700281 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
282 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
283 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700285 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
286 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
287 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
288 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700289 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800290 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
291 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000292 private static final int CMD_SWITCH_SLOTS = 50;
293 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700294 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
295 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
296 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
297 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
298 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
299 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
300 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
301 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700302 private static final int CMD_GET_ALL_CELL_INFO = 60;
303 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
304 private static final int CMD_GET_CELL_LOCATION = 62;
305 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700306 private static final int CMD_MODEM_REBOOT = 64;
307 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700308 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
309 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800310 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
311 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700312 private static final int CMD_GET_MODEM_STATUS = 70;
313 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700314 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
315 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 private static final int CMD_ERASE_MODEM_CONFIG = 74;
317 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800318 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
319 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
320 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
321 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800322 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
323 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800324 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800325 private static final int CMD_GET_CALL_FORWARDING = 83;
326 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
327 private static final int CMD_SET_CALL_FORWARDING = 85;
328 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
329 private static final int CMD_GET_CALL_WAITING = 87;
330 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
331 private static final int CMD_SET_CALL_WAITING = 89;
332 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700333 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
334 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
335 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
336 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700337 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
338 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800339 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
340 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800341 private static final int CMD_SET_DATA_THROTTLING = 99;
342 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800343 private static final int CMD_SET_SIM_POWER = 101;
344 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800345 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
346 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
347 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
348 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800349 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
350 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000351 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800352 private static final int CMD_GET_SLICING_CONFIG = 110;
353 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800354 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700355 private static final int CMD_ENABLE_VONR = 113;
356 private static final int EVENT_ENABLE_VONR_DONE = 114;
357 private static final int CMD_IS_VONR_ENABLED = 115;
358 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800360 // Parameters of select command.
361 private static final int SELECT_COMMAND = 0xA4;
362 private static final int SELECT_P1 = 0x04;
363 private static final int SELECT_P2 = 0;
364 private static final int SELECT_P3 = 0x10;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /** The singleton instance. */
367 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800368 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800372 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700373 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700375 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800377 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700379 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800380 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 /** User Activity */
383 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
385
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700386 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
387
Derek Tan97ebb422014-09-05 16:55:38 -0700388 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
389 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800390 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800391 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700392
Michelecea4cf22018-12-21 15:00:11 -0800393 // String to store multi SIM allowed
394 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
395
Derek Tan740e1672017-06-27 14:56:27 -0700396 // The AID of ISD-R.
397 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
398
yinxub1bed742017-04-17 11:45:04 -0700399 private NetworkScanRequestTracker mNetworkScanRequestTracker;
400
David Kelly5e06a7f2018-03-12 14:10:59 +0000401 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
402 private static final int MANUFACTURER_CODE_LENGTH = 8;
403
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800405 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406
Derek Tan89e89d42014-07-08 17:00:10 -0700407 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 * Experiment flag to enable erase modem config on reset network, default value is false
409 */
410 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
411 "reset_network_erase_modem_config_enabled";
412
Rambo Wang0f050d82021-02-12 11:43:36 -0800413 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000414 /**
415 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
416 * one ICCID active at the same time.
417 * Apps should use below API signatures if targeting SDK is T and beyond.
418 *
419 * @hide
420 */
421 @ChangeId
422 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
423 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800424
Naina Nallurid63128d2019-09-17 14:10:30 -0700425 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class IccAPDUArgument {
429 public int channel, cla, command, p1, p2, p3;
430 public String data;
431
432 public IccAPDUArgument(int channel, int cla, int command,
433 int p1, int p2, int p3, String data) {
434 this.channel = channel;
435 this.cla = cla;
436 this.command = command;
437 this.p1 = p1;
438 this.p2 = p2;
439 this.p3 = p3;
440 this.data = data;
441 }
442 }
443
444 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class ManualNetworkSelectionArgument {
448 public OperatorInfo operatorInfo;
449 public boolean persistSelection;
450
451 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
452 this.operatorInfo = operatorInfo;
453 this.persistSelection = persistSelection;
454 }
455 }
456
457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
459 * request after sending. The main thread will notify the request when it is complete.
460 */
461 private static final class MainThreadRequest {
462 /** The argument to use for the request */
463 public Object argument;
464 /** The result of the request that is run on the main thread */
465 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800466 // The subscriber id that this request applies to. Defaults to
467 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
468 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Nathan Harold92bed182018-10-12 18:16:49 -0700470 // In cases where subId is unavailable, the caller needs to specify the phone.
471 public Phone phone;
472
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 public WorkSource workSource;
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 public MainThreadRequest(Object argument) {
476 this.argument = argument;
477 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800478
Nathan Harold92bed182018-10-12 18:16:49 -0700479 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
480 this.argument = argument;
481 if (phone != null) {
482 this.phone = phone;
483 }
484 this.workSource = workSource;
485 }
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800489 if (subId != null) {
490 this.subId = subId;
491 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800496 private static final class IncomingThirdPartyCallArgs {
497 public final ComponentName component;
498 public final String callId;
499 public final String callerDisplayName;
500
501 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
502 String callerDisplayName) {
503 this.component = component;
504 this.callId = callId;
505 this.callerDisplayName = callerDisplayName;
506 }
507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 /**
510 * A handler that processes messages on the main thread in the phone process. Since many
511 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
512 * inbound binder threads to the main thread in the phone process. The Binder thread
513 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
514 * on, which will be notified when the operation completes and will contain the result of the
515 * request.
516 *
517 * <p>If a MainThreadRequest object is provided in the msg.obj field,
518 * note that request.result must be set to something non-null for the calling thread to
519 * unblock.
520 */
521 private final class MainThreadHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 MainThreadRequest request;
525 Message onCompleted;
526 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000527 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800529 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
531 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 case CMD_HANDLE_USSD_REQUEST: {
533 request = (MainThreadRequest) msg.obj;
534 final Phone phone = getPhoneFromRequest(request);
535 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
536 String ussdRequest = ussdObject.first;
537 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700538
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 if (!isUssdApiAllowed(request.subId)) {
540 // Carrier does not support use of this API, return failure.
541 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
542 UssdResponse response = new UssdResponse(ussdRequest, null);
543 Bundle returnData = new Bundle();
544 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
545 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700546
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 request.result = true;
548 notifyRequester(request);
549 return;
550 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 try {
553 request.result = phone != null
554 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
555 } catch (CallStateException cse) {
556 request.result = false;
557 }
558 // Wake up the requesting thread
559 notifyRequester(request);
560 break;
pkanwar32d516d2016-10-14 19:37:38 -0700561 }
562
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 final Phone phone = getPhoneFromRequest(request);
566 request.result = phone != null ?
567 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
568 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000577 uiccPort = getUiccPortFromRequest(request);
578 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 loge("iccTransmitApduLogicalChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
584 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000585 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument.channel, iccArgument.cla, iccArgument.command,
587 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
597 } else {
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800601 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800603 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
605 loge("iccTransmitApduLogicalChannel: Unknown exception");
606 }
607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
613 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 uiccPort = getUiccPortFromRequest(request);
615 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 loge("iccTransmitApduBasicChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
621 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000622 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
624 iccArgument.p3, iccArgument.data, onCompleted);
625 }
626 break;
627
628 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("iccTransmitApduBasicChannel: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("iccTransmitApduBasicChannel: CommandException: " +
639 ar.exception);
640 } else {
641 loge("iccTransmitApduBasicChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
647 case CMD_EXCHANGE_SIM_IO:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccExchangeSimIO: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
660 iccArgument.data, onCompleted);
661 }
662 break;
663
664 case EVENT_EXCHANGE_SIM_IO_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
670 request.result = new IccIoResult(0x6f, 0, (byte[])null);
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 break;
674
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 case CMD_SEND_ENVELOPE:
676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("sendEnvelopeWithStatus: No UICC");
680 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
688 case EVENT_SEND_ENVELOPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800693 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700694 request.result = new IccIoResult(0x6F, 0, (byte[])null);
695 if (ar.result == null) {
696 loge("sendEnvelopeWithStatus: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("sendEnvelopeWithStatus: CommandException: " +
699 ar.exception);
700 } else {
701 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 break;
706
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 case CMD_OPEN_CHANNEL:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800710 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800713 request.result = new IccOpenLogicalChannelResponse(-1,
714 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800719 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 break;
722
723 case EVENT_OPEN_CHANNEL_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 int[] result = (int[]) ar.result;
729 int channelId = result[0];
730 byte[] selectResponse = null;
731 if (result.length > 1) {
732 selectResponse = new byte[result.length - 1];
733 for (int i = 1; i < result.length; ++i) {
734 selectResponse[i - 1] = (byte) result[i];
735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700738 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.result == null) {
741 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 if (ar.exception != null) {
744 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
745 }
746
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700747 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700748 if (ar.exception instanceof CommandException) {
749 CommandException.Error error =
750 ((CommandException) (ar.exception)).getCommandError();
751 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700753 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700754 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 }
756 }
757 openChannelResp = new IccOpenLogicalChannelResponse(
758 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700760 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 break;
763
764 case CMD_CLOSE_CHANNEL:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900769 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000773 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 break;
776
777 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800778 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
779 break;
780
781 case CMD_NV_READ_ITEM:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
785 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800791 if (ar.exception == null && ar.result != null) {
792 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800794 request.result = "";
795 if (ar.result == null) {
796 loge("nvReadItem: Empty response");
797 } else if (ar.exception instanceof CommandException) {
798 loge("nvReadItem: CommandException: " +
799 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800801 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 }
803 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
Jake Hambye994d462014-02-03 13:10:13 -0800807 case CMD_NV_WRITE_ITEM:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
810 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700812 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
815 case EVENT_NV_WRITE_ITEM_DONE:
816 handleNullReturnEvent(msg, "nvWriteItem");
817 break;
818
819 case CMD_NV_WRITE_CDMA_PRL:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800822 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800823 break;
824
825 case EVENT_NV_WRITE_CDMA_PRL_DONE:
826 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
827 break;
828
chen xu6dac5ab2018-10-26 17:39:23 -0700829 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800830 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700831 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
chen xu6dac5ab2018-10-26 17:39:23 -0700835 case EVENT_RESET_MODEM_CONFIG_DONE:
836 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800837 break;
838
Sooraj Sasindran37444802020-08-11 10:40:43 -0700839 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
842 request);
843 Phone phone = getPhoneFromRequest(request);
844 if (phone != null) {
845 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
846 } else {
847 loge("isNRDualConnectivityEnabled: No phone object");
848 request.result = false;
849 notifyRequester(request);
850 }
851 break;
852 }
853
854 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 // request.result must be set to something non-null
861 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700862 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700863 request.result = ar.result;
864 } else {
865 request.result = false;
866 }
867 if (ar.result == null) {
868 loge("isNRDualConnectivityEnabled: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("isNRDualConnectivityEnabled: CommandException: "
871 + ar.exception);
872 } else {
873 loge("isNRDualConnectivityEnabled: Unknown exception");
874 }
875 }
876 notifyRequester(request);
877 break;
878
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700879 case CMD_IS_VONR_ENABLED: {
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
882 request);
883 Phone phone = getPhoneFromRequest(request);
884 if (phone != null) {
885 phone.isVoNrEnabled(onCompleted, request.workSource);
886 } else {
887 loge("isVoNrEnabled: No phone object");
888 request.result = false;
889 notifyRequester(request);
890 }
891 break;
892 }
893
894 case EVENT_IS_VONR_ENABLED_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
900 // request.result must be set to something non-null
901 // for the calling thread to unblock
902 if (ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = false;
906 }
907 if (ar.result == null) {
908 loge("isVoNrEnabled: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("isVoNrEnabled: CommandException: "
911 + ar.exception);
912 } else {
913 loge("isVoNrEnabled: Unknown exception");
914 }
915 }
916 notifyRequester(request);
917 break;
918
Sooraj Sasindran37444802020-08-11 10:40:43 -0700919 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
925 request.workSource);
926 } else {
927 loge("enableNrDualConnectivity: No phone object");
928 request.result =
929 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
930 notifyRequester(request);
931 }
932 break;
933 }
934
935 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null) {
939 request.result =
940 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
941 } else {
942 request.result =
943 TelephonyManager
944 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
945 if (ar.exception instanceof CommandException) {
946 CommandException.Error error =
947 ((CommandException) (ar.exception)).getCommandError();
948 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
949 request.result =
950 TelephonyManager
951 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000952 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
953 request.result =
954 TelephonyManager
955 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700956 }
957 loge("enableNrDualConnectivity" + ": CommandException: "
958 + ar.exception);
959 } else {
960 loge("enableNrDualConnectivity" + ": Unknown exception");
961 }
962 }
963 notifyRequester(request);
964 break;
965 }
966
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700967 case CMD_ENABLE_VONR: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("setVoNrEnabled: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_VONR_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
988 } else {
989 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
996 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
997 } else {
998 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
999 }
1000 loge("setVoNrEnabled" + ": CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("setVoNrEnabled" + ": Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008 }
1009
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1013 request);
1014 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null && ar.result != null) {
1021 request.result = ar.result; // Integer
1022 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301023 // request.result must be set to something non-null
1024 // for the calling thread to unblock
1025 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 loge("getAllowedNetworkTypesBitmask: CommandException: "
1030 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 }
1034 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001035 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 break;
1037
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001039 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001040 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1041 request);
1042 Pair<Integer, Long> reasonWithNetworkTypes =
1043 (Pair<Integer, Long>) request.argument;
1044 getPhoneFromRequest(request).setAllowedNetworkTypes(
1045 reasonWithNetworkTypes.first,
1046 reasonWithNetworkTypes.second,
1047 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001048 break;
1049
SongFerngWang3ef3e072020-12-21 16:41:52 +08001050 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1051 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001052 break;
1053
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001054 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1055 request = (MainThreadRequest)msg.obj;
1056 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001057 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001058 break;
1059
1060 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1061 ar = (AsyncResult)msg.obj;
1062 request = (MainThreadRequest)ar.userObj;
1063 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001064 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001065 break;
1066
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001067 case CMD_SET_VOICEMAIL_NUMBER:
1068 request = (MainThreadRequest) msg.obj;
1069 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1070 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001071 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1072 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001073 break;
1074
1075 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1076 handleNullReturnEvent(msg, "setVoicemailNumber");
1077 break;
1078
Stuart Scott54788802015-03-30 13:18:01 -07001079 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1082 request);
1083 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1084 break;
1085
1086 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1087 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1088 break;
1089
Shishir Agrawal302c8692015-06-19 13:49:39 -07001090 case CMD_PERFORM_NETWORK_SCAN:
1091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1093 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1094 break;
1095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001099 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1100 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1101 request.argument;
1102 int callForwardingReason = args.first;
1103 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
Hall Liu27d24262020-09-18 19:04:59 -07001105 }
1106 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001109 TelephonyManager.CallForwardingInfoCallback callback =
1110 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1111 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001113 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1115 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1116 // Service Class is a bit mask per 3gpp 27.007. Search for
1117 // any service for voice call.
1118 if ((callForwardInfo.serviceClass
1119 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001120 callForwardingInfo = new CallForwardingInfo(
1121 callForwardInfo.status
1122 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001123 callForwardInfo.reason,
1124 callForwardInfo.number,
1125 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 break;
1127 }
1128 }
1129 // Didn't find a call forward info for voice call.
1130 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001131 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1132 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 } else {
1136 if (ar.result == null) {
1137 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1138 }
1139 if (ar.exception != null) {
1140 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1141 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001142 int errorCode = TelephonyManager
1143 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001144 if (ar.exception instanceof CommandException) {
1145 CommandException.Error error =
1146 ((CommandException) (ar.exception)).getCommandError();
1147 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001148 errorCode = TelephonyManager
1149 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001150 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001151 errorCode = TelephonyManager
1152 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 }
1154 }
Hall Liu27d24262020-09-18 19:04:59 -07001155 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
Shuo Qian4a594052020-01-23 11:59:30 -08001159
Hall Liu27d24262020-09-18 19:04:59 -07001160 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001163 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001164 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001165 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1166 request.argument).first;
1167 request.phone.setCallForwardingOption(
1168 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001169 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001170 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001171 callForwardingInfoToSet.getReason(),
1172 callForwardingInfoToSet.getNumber(),
1173 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1174 break;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
Shuo Qian4a594052020-01-23 11:59:30 -08001176
Hall Liu27d24262020-09-18 19:04:59 -07001177 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001180 Consumer<Integer> callback =
1181 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1182 request.argument).second;
1183 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001185 int errorCode = TelephonyManager.CallForwardingInfoCallback
1186 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001187 if (ar.exception instanceof CommandException) {
1188 CommandException.Error error =
1189 ((CommandException) (ar.exception)).getCommandError();
1190 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 errorCode = TelephonyManager.CallForwardingInfoCallback
1192 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001193 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager.CallForwardingInfoCallback
1195 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001196 }
1197 }
1198 callback.accept(errorCode);
1199 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202 break;
Hall Liu27d24262020-09-18 19:04:59 -07001203 }
Shuo Qian4a594052020-01-23 11:59:30 -08001204
Hall Liu27d24262020-09-18 19:04:59 -07001205 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1208 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1209 break;
Hall Liu27d24262020-09-18 19:04:59 -07001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211
Hall Liu27d24262020-09-18 19:04:59 -07001212 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001215 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1217 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001218 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 // Service Class is a bit mask per 3gpp 27.007.
1220 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 if (callForwardResults.length > 1
1222 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001224 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001225 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1226 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001228 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 }
1230 } else {
1231 if (ar.result == null) {
1232 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1233 }
1234 if (ar.exception != null) {
1235 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1236 }
1237 if (ar.exception instanceof CommandException) {
1238 CommandException.Error error =
1239 ((CommandException) (ar.exception)).getCommandError();
1240 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1241 callForwardingStatus =
1242 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1243 }
1244 }
1245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249
Hall Liu27d24262020-09-18 19:04:59 -07001250 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001253 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1254 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1262 Consumer<Integer> callback =
1263 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1264 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1271 } else {
1272 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1273 }
1274 } else {
1275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1276 }
1277 } else {
1278 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1279 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001283 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 CellNetworkScanResult cellScanResult;
1287 if (ar.exception == null && ar.result != null) {
1288 cellScanResult = new CellNetworkScanResult(
1289 CellNetworkScanResult.STATUS_SUCCESS,
1290 (List<OperatorInfo>) ar.result);
1291 } else {
1292 if (ar.result == null) {
1293 loge("getCellNetworkScanResults: Empty response");
1294 }
1295 if (ar.exception != null) {
1296 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1297 }
1298 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1304 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1305 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1306 }
1307 }
1308 cellScanResult = new CellNetworkScanResult(errorCode, null);
1309 }
1310 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
1314 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1315 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001316 ManualNetworkSelectionArgument selArg =
1317 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001318 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1319 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001320 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1321 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001322 break;
1323
1324 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 loge("setNetworkSelectionModeManual " + ar.exception);
1332 }
1333 notifyRequester(request);
1334 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 break;
1336
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 case CMD_GET_MODEM_ACTIVITY_INFO:
1338 request = (MainThreadRequest) msg.obj;
1339 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001340 if (defaultPhone != null) {
1341 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 } else {
1343 ResultReceiver result = (ResultReceiver) request.argument;
1344 Bundle bundle = new Bundle();
1345 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001346 new ModemActivityInfo(0, 0, 0,
1347 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001349 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001350 break;
1351
Hall Liud0f208c2020-10-14 16:54:44 -07001352 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001355 ResultReceiver result = (ResultReceiver) request.argument;
1356
Hall Liud0f208c2020-10-14 16:54:44 -07001357 ModemActivityInfo ret = null;
1358 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001359 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 // Update the last modem activity info and the result of the request.
1361 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1362 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001363 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001364 int[] txTimeMs = info.getTransmitTimeMillis();
1365 int[] lastModemTxTimeMs = mLastModemActivityInfo
1366 .getTransmitTimeMillis();
1367 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1368 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1369 }
Hall Liu49656c02020-10-09 19:00:11 -07001370 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001371 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1372 + mLastModemActivityInfo.getSleepTimeMillis());
1373 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1374 + mLastModemActivityInfo.getIdleTimeMillis());
1375 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1376 mLastModemActivityInfo.setReceiveTimeMillis(
1377 info.getReceiveTimeMillis()
1378 + mLastModemActivityInfo.getReceiveTimeMillis());
1379 }
Hall Liu49656c02020-10-09 19:00:11 -07001380 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 mLastModemActivityInfo.getSleepTimeMillis(),
1382 mLastModemActivityInfo.getIdleTimeMillis(),
1383 mLastModemActivityInfo.getTransmitTimeMillis(),
1384 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001385 } else {
1386 if (ar.result == null) {
1387 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001388 error = TelephonyManager.ModemActivityInfoException
1389 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 } else if (ar.exception instanceof CommandException) {
1391 loge("queryModemActivityInfo: CommandException: " +
1392 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001393 error = TelephonyManager.ModemActivityInfoException
1394 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001395 } else {
1396 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001397 error = TelephonyManager.ModemActivityInfoException
1398 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 }
1400 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001402 if (ret != null) {
1403 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1404 } else {
1405 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1406 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 case CMD_SET_ALLOWED_CARRIERS:
1413 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001414 CarrierRestrictionRules argument =
1415 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001417 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null && ar.result != null) {
1424 request.result = ar.result;
1425 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001426 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1427 if (ar.exception instanceof CommandException) {
1428 loge("setAllowedCarriers: CommandException: " + ar.exception);
1429 CommandException.Error error =
1430 ((CommandException) (ar.exception)).getCommandError();
1431 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1432 request.result =
1433 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1434 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 } else {
1436 loge("setAllowedCarriers: Unknown exception");
1437 }
1438 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001440 break;
1441
1442 case CMD_GET_ALLOWED_CARRIERS:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001445 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001446 break;
1447
1448 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null && ar.result != null) {
1452 request.result = ar.result;
1453 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001454 request.result = new IllegalStateException(
1455 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001456 if (ar.result == null) {
1457 loge("getAllowedCarriers: Empty response");
1458 } else if (ar.exception instanceof CommandException) {
1459 loge("getAllowedCarriers: CommandException: " +
1460 ar.exception);
1461 } else {
1462 loge("getAllowedCarriers: Unknown exception");
1463 }
1464 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 break;
1467
Nathan Haroldb3014052017-01-25 15:57:32 -08001468 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception == null && ar.result != null) {
1472 request.result = ar.result;
1473 } else {
1474 request.result = new IllegalArgumentException(
1475 "Failed to retrieve Forbidden Plmns");
1476 if (ar.result == null) {
1477 loge("getForbiddenPlmns: Empty response");
1478 } else {
1479 loge("getForbiddenPlmns: Unknown exception");
1480 }
1481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001483 break;
1484
1485 case CMD_GET_FORBIDDEN_PLMNS:
1486 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001487 uiccPort = getUiccPortFromRequest(request);
1488 if (uiccPort == null) {
1489 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001490 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001491 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001492 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001493 break;
1494 }
1495 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001496 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001497 if (uiccApp == null) {
1498 loge("getForbiddenPlmns() no app with specified type -- "
1499 + appType);
1500 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001502 break;
1503 } else {
1504 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1505 + " specified type -- " + appType);
1506 }
1507 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1508 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1509 onCompleted);
1510 break;
1511
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001512 case CMD_SWITCH_SLOTS:
1513 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001514 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001516 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001517 break;
1518
1519 case EVENT_SWITCH_SLOTS_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_NETWORK_SELECTION_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1528 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1529 break;
1530
1531 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception != null) {
1535 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1536 } else {
1537 int mode = ((int[]) ar.result)[0];
1538 if (mode == 0) {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1540 } else {
1541 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
1545 break;
1546 case CMD_GET_CDMA_ROAMING_MODE:
1547 request = (MainThreadRequest) msg.obj;
1548 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1549 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1550 break;
1551 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception != null) {
1555 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1556 } else {
1557 request.result = ((int[]) ar.result)[0];
1558 }
1559 notifyRequester(request);
1560 break;
1561 case CMD_SET_CDMA_ROAMING_MODE:
1562 request = (MainThreadRequest) msg.obj;
1563 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1564 int mode = (int) request.argument;
1565 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1566 break;
1567 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 request.result = ar.exception == null;
1571 notifyRequester(request);
1572 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001573 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1576 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1577 break;
1578 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 if (ar.exception != null) {
1582 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1583 } else {
1584 request.result = ((int[]) ar.result)[0];
1585 }
1586 notifyRequester(request);
1587 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001588 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1591 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001592 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1593 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001594 break;
1595 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 request.result = ar.exception == null;
1599 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 case CMD_GET_ALL_CELL_INFO:
1602 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001604 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 case EVENT_GET_ALL_CELL_INFO_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001609 // If a timeout occurs, the response will be null
1610 request.result = (ar.exception == null && ar.result != null)
1611 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001612 synchronized (request) {
1613 request.notifyAll();
1614 }
1615 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 case CMD_REQUEST_CELL_INFO_UPDATE:
1617 request = (MainThreadRequest) msg.obj;
1618 request.phone.requestCellInfoUpdate(request.workSource,
1619 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1620 break;
1621 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1625 try {
1626 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001627 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001628 cb.onError(
1629 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1630 ar.exception.getClass().getName(),
1631 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001634 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001635 } else {
1636 // use the result as returned
1637 cb.onCellInfo((List<CellInfo>) ar.result);
1638 }
1639 } catch (RemoteException re) {
1640 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001644 request = (MainThreadRequest) msg.obj;
1645 WorkSource ws = (WorkSource) request.argument;
1646 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001647 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001648 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001649 }
1650 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 if (ar.exception == null) {
1654 request.result = ar.result;
1655 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001656 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001658 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 }
1660
1661 synchronized (request) {
1662 request.notifyAll();
1663 }
1664 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001665 }
chen xu6dac5ab2018-10-26 17:39:23 -07001666 case CMD_MODEM_REBOOT:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001669 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001670 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001671 case EVENT_CMD_MODEM_REBOOT_DONE:
1672 handleNullReturnEvent(msg, "rebootModem");
1673 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001674 case CMD_REQUEST_ENABLE_MODEM:
1675 request = (MainThreadRequest) msg.obj;
1676 boolean enable = (boolean) request.argument;
1677 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001678 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001679 PhoneConfigurationManager.getInstance()
1680 .enablePhone(request.phone, enable, onCompleted);
1681 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001682 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001687 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001688 if ((boolean) request.result) {
1689 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1690 updateModemStateMetrics();
1691 } else {
1692 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1693 + ar.exception);
1694 }
1695 notifyRequester(request);
1696 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001697 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001698 case CMD_GET_MODEM_STATUS:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1701 PhoneConfigurationManager.getInstance()
1702 .getPhoneStatusFromModem(request.phone, onCompleted);
1703 break;
1704 case EVENT_GET_MODEM_STATUS_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 int id = request.phone.getPhoneId();
1708 if (ar.exception == null && ar.result != null) {
1709 request.result = ar.result;
1710 //update the cache as modem status has changed
1711 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1712 (boolean) request.result);
1713 } else {
1714 // Return true if modem status cannot be retrieved. For most cases,
1715 // modem status is on. And for older version modems, GET_MODEM_STATUS
1716 // and disable modem are not supported. Modem is always on.
1717 // TODO: this should be fixed in R to support a third
1718 // status UNKNOWN b/131631629
1719 request.result = true;
1720 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1721 + ar.exception);
1722 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001723 notifyRequester(request);
1724 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001725 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1728 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1729 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1730 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1731 break;
1732 }
1733 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1737 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1738 args.second.accept(ar.exception == null);
1739 notifyRequester(request);
1740 break;
1741 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1745 Phone phone = getPhoneFromRequest(request);
1746 if (phone != null) {
1747 phone.getSystemSelectionChannels(onCompleted);
1748 } else {
1749 loge("getSystemSelectionChannels: No phone object");
1750 request.result = new ArrayList<RadioAccessSpecifier>();
1751 notifyRequester(request);
1752 }
1753 break;
1754 }
1755 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758 if (ar.exception == null && ar.result != null) {
1759 request.result = ar.result;
1760 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001761 request.result = new IllegalStateException(
1762 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001763 if (ar.result == null) {
1764 loge("getSystemSelectionChannels: Empty response");
1765 } else {
1766 loge("getSystemSelectionChannels: Unknown exception");
1767 }
1768 }
1769 notifyRequester(request);
1770 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001771 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1772 ar = (AsyncResult) msg.obj;
1773 request = (MainThreadRequest) ar.userObj;
1774 if (ar.exception == null && ar.result != null) {
1775 request.result = ar.result;
1776 } else {
1777 request.result = -1;
1778 loge("Failed to set Forbidden Plmns");
1779 if (ar.result == null) {
1780 loge("setForbidenPlmns: Empty response");
1781 } else if (ar.exception != null) {
1782 loge("setForbiddenPlmns: Exception: " + ar.exception);
1783 request.result = -1;
1784 } else {
1785 loge("setForbiddenPlmns: Unknown exception");
1786 }
1787 }
1788 notifyRequester(request);
1789 break;
1790 case CMD_SET_FORBIDDEN_PLMNS:
1791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001792 uiccPort = getUiccPortFromRequest(request);
1793 if (uiccPort == null) {
1794 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001795 request.result = -1;
1796 notifyRequester(request);
1797 break;
1798 }
1799 Pair<Integer, List<String>> setFplmnsArgs =
1800 (Pair<Integer, List<String>>) request.argument;
1801 appType = setFplmnsArgs.first;
1802 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001803 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001804 if (uiccApp == null) {
1805 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1806 request.result = -1;
1807 loge("Failed to get UICC App");
1808 notifyRequester(request);
1809 } else {
1810 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1811 ((SIMRecords) uiccApp.getIccRecords())
1812 .setForbiddenPlmns(onCompleted, fplmns);
1813 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001814 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001815 case CMD_ERASE_MODEM_CONFIG:
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1818 defaultPhone.eraseModemConfig(onCompleted);
1819 break;
1820 case EVENT_ERASE_MODEM_CONFIG_DONE:
1821 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001822 break;
zoey chene02881a2019-12-30 16:11:23 +08001823
Kai Shif70f46f2021-03-03 13:59:46 -08001824 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1825 request = (MainThreadRequest) msg.obj;
1826 request.result = defaultPhone.eraseDataInSharedPreferences();
1827 notifyRequester(request);
1828 break;
1829
zoey chene02881a2019-12-30 16:11:23 +08001830 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1833 Pair<String, String> changed = (Pair<String, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1835 changed.first, changed.second, onCompleted);
1836 break;
1837 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 if (ar.exception == null) {
1841 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001842 // If the operation is successful, update the PIN storage
1843 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1844 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001845 UiccController.getInstance().getPinStorage()
1846 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001847 } else {
1848 request.result = msg.arg1;
1849 }
1850 notifyRequester(request);
1851 break;
1852
Michele Berionne5e411512020-11-13 02:36:59 +00001853 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1856 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1857 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1858 enabled.first, enabled.second, onCompleted);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
zoey chene02881a2019-12-30 16:11:23 +08001861 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1862 ar = (AsyncResult) msg.obj;
1863 request = (MainThreadRequest) ar.userObj;
1864 if (ar.exception == null) {
1865 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001866 // If the operation is successful, update the PIN storage
1867 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1868 int phoneId = getPhoneFromRequest(request).getPhoneId();
1869 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001870 UiccController.getInstance().getPinStorage()
1871 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001872 } else {
1873 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1874 }
zoey chene02881a2019-12-30 16:11:23 +08001875 } else {
1876 request.result = msg.arg1;
1877 }
Michele Berionne5e411512020-11-13 02:36:59 +00001878
1879
zoey chene02881a2019-12-30 16:11:23 +08001880 notifyRequester(request);
1881 break;
1882
Peter Wangdafb9ac2020-01-15 14:13:38 -08001883 case MSG_NOTIFY_USER_ACTIVITY:
1884 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001885 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001886 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1887 getDefaultPhone().getContext().sendBroadcastAsUser(
1888 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1889 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001890
1891 case CMD_SET_DATA_THROTTLING: {
1892 request = (MainThreadRequest) msg.obj;
1893 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1894 DataThrottlingRequest dataThrottlingRequest =
1895 (DataThrottlingRequest) request.argument;
1896 Phone phone = getPhoneFromRequest(request);
1897 if (phone != null) {
1898 phone.setDataThrottling(onCompleted,
1899 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1900 dataThrottlingRequest.getCompletionDurationMillis());
1901 } else {
1902 loge("setDataThrottling: No phone object");
1903 request.result =
1904 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 notifyRequester(request);
1906 }
1907
1908 break;
1909 }
1910 case EVENT_SET_DATA_THROTTLING_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913
1914 if (ar.exception == null) {
1915 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1916 } else if (ar.exception instanceof CommandException) {
1917 loge("setDataThrottling: CommandException: " + ar.exception);
1918 CommandException.Error error =
1919 ((CommandException) (ar.exception)).getCommandError();
1920
1921 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1922 request.result = TelephonyManager
1923 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1924 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1925 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001926 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1927 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001928 } else {
1929 request.result =
1930 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1931 }
1932 } else {
1933 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1934 }
1935 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1936 notifyRequester(request);
1937 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001938
1939 case CMD_SET_SIM_POWER: {
1940 request = (MainThreadRequest) msg.obj;
1941 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1942 request = (MainThreadRequest) msg.obj;
1943 int stateToSet =
1944 ((Pair<Integer, IIntegerConsumer>)
1945 request.argument).first;
1946 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1947 break;
1948 }
1949 case EVENT_SET_SIM_POWER_DONE: {
1950 ar = (AsyncResult) msg.obj;
1951 request = (MainThreadRequest) ar.userObj;
1952 IIntegerConsumer callback =
1953 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1954 if (ar.exception != null) {
1955 loge("setSimPower exception: " + ar.exception);
1956 int errorCode = TelephonyManager.CallForwardingInfoCallback
1957 .RESULT_ERROR_UNKNOWN;
1958 if (ar.exception instanceof CommandException) {
1959 CommandException.Error error =
1960 ((CommandException) (ar.exception)).getCommandError();
1961 if (error == CommandException.Error.SIM_ERR) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1963 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1965 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1967 } else {
1968 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1969 }
1970 }
1971 try {
1972 callback.accept(errorCode);
1973 } catch (RemoteException e) {
1974 // Ignore if the remote process is no longer available to call back.
1975 Log.w(LOG_TAG, "setSimPower: callback not available.");
1976 }
1977 } else {
1978 try {
1979 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1980 } catch (RemoteException e) {
1981 // Ignore if the remote process is no longer available to call back.
1982 Log.w(LOG_TAG, "setSimPower: callback not available.");
1983 }
1984 }
1985 break;
1986 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001987 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1988 request = (MainThreadRequest) msg.obj;
1989
1990 final Phone phone = getPhoneFromRequest(request);
1991 if (phone == null || phone.getServiceStateTracker() == null) {
1992 request.result = new IllegalStateException("Phone or SST is null");
1993 notifyRequester(request);
1994 break;
1995 }
1996
1997 Pair<Integer, SignalStrengthUpdateRequest> pair =
1998 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1999 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2000 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002001 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002002 request.subId, pair.first /*callingUid*/,
2003 pair.second /*request*/, onCompleted);
2004 break;
2005 }
2006 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 // request.result will be the exception of ar if present, true otherwise.
2010 // Be cautious not to leave result null which will wait() forever
2011 request.result = ar.exception != null ? ar.exception : true;
2012 notifyRequester(request);
2013 break;
2014 }
2015 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2016 request = (MainThreadRequest) msg.obj;
2017
2018 Phone phone = getPhoneFromRequest(request);
2019 if (phone == null || phone.getServiceStateTracker() == null) {
2020 request.result = new IllegalStateException("Phone or SST is null");
2021 notifyRequester(request);
2022 break;
2023 }
2024
2025 Pair<Integer, SignalStrengthUpdateRequest> pair =
2026 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2027 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2028 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002029 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002030 request.subId, pair.first /*callingUid*/,
2031 pair.second /*request*/, onCompleted);
2032 break;
2033 }
2034 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2035 ar = (AsyncResult) msg.obj;
2036 request = (MainThreadRequest) ar.userObj;
2037 request.result = ar.exception != null ? ar.exception : true;
2038 notifyRequester(request);
2039 break;
2040 }
Jordan Liu109698e2020-11-24 14:50:34 -08002041
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 case CMD_GET_SLICING_CONFIG: {
2043 request = (MainThreadRequest) msg.obj;
2044 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2045 request.phone.getSlicingConfig(onCompleted);
2046 break;
2047 }
2048 case EVENT_GET_SLICING_CONFIG_DONE: {
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051 ResultReceiver result = (ResultReceiver) request.argument;
2052
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002053 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002054 Bundle bundle = new Bundle();
2055 int resultCode = 0;
2056 if (ar.exception != null) {
2057 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2058 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002059 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002060 } else if (ar.result == null) {
2061 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002063 } else {
2064 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002065 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2066 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002067 }
2068
2069 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002070 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002071 }
2072 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2073 result.send(resultCode, bundle);
2074 notifyRequester(request);
2075 break;
2076 }
2077
Michele Berionne5e411512020-11-13 02:36:59 +00002078 case CMD_PREPARE_UNATTENDED_REBOOT:
2079 request = (MainThreadRequest) msg.obj;
2080 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002081 UiccController.getInstance().getPinStorage()
2082 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002083 notifyRequester(request);
2084 break;
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 default:
2087 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2088 break;
2089 }
2090 }
Jake Hambye994d462014-02-03 13:10:13 -08002091
Pengquan Menga1bb6272018-09-06 09:59:22 -07002092 private void notifyRequester(MainThreadRequest request) {
2093 synchronized (request) {
2094 request.notifyAll();
2095 }
2096 }
2097
Jake Hambye994d462014-02-03 13:10:13 -08002098 private void handleNullReturnEvent(Message msg, String command) {
2099 AsyncResult ar = (AsyncResult) msg.obj;
2100 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2101 if (ar.exception == null) {
2102 request.result = true;
2103 } else {
2104 request.result = false;
2105 if (ar.exception instanceof CommandException) {
2106 loge(command + ": CommandException: " + ar.exception);
2107 } else {
2108 loge(command + ": Unknown exception");
2109 }
2110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002111 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
2115 /**
2116 * Posts the specified command to be executed on the main thread,
2117 * waits for the request to complete, and returns the result.
2118 * @see #sendRequestAsync
2119 */
2120 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002121 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2122 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002123 }
2124
2125 /**
2126 * Posts the specified command to be executed on the main thread,
2127 * waits for the request to complete, and returns the result.
2128 * @see #sendRequestAsync
2129 */
2130 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2131 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002132 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002133 }
2134
2135 /**
2136 * Posts the specified command to be executed on the main thread,
2137 * waits for the request to complete, and returns the result.
2138 * @see #sendRequestAsync
2139 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002140 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002141 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2142 }
2143
2144 /**
2145 * Posts the specified command to be executed on the main thread,
2146 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2147 * if not timeout or null otherwise.
2148 * @see #sendRequestAsync
2149 */
2150 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2151 long timeoutInMs) {
2152 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002153 }
2154
2155 /**
2156 * Posts the specified command to be executed on the main thread,
2157 * waits for the request to complete, and returns the result.
2158 * @see #sendRequestAsync
2159 */
Nathan Harold92bed182018-10-12 18:16:49 -07002160 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002161 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002162 }
2163
2164 /**
2165 * Posts the specified command to be executed on the main thread,
2166 * waits for the request to complete, and returns the result.
2167 * @see #sendRequestAsync
2168 */
2169 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002170 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2171 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002172 }
2173
2174 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002175 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2176 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2177 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002178 * @see #sendRequestAsync
2179 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2181 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2183 throw new RuntimeException("This method will deadlock if called from the main thread.");
2184 }
2185
Nathan Harold92bed182018-10-12 18:16:49 -07002186 MainThreadRequest request = null;
2187 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2188 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2189 } else if (phone != null) {
2190 request = new MainThreadRequest(argument, phone, workSource);
2191 } else {
2192 request = new MainThreadRequest(argument, subId, workSource);
2193 }
2194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 Message msg = mMainThreadHandler.obtainMessage(command, request);
2196 msg.sendToTarget();
2197
Rambo Wang0f050d82021-02-12 11:43:36 -08002198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 if (timeoutInMs >= 0) {
2201 // Wait for at least timeoutInMs before returning null request result
2202 long now = SystemClock.elapsedRealtime();
2203 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002204 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 try {
2206 request.wait(deadline - now);
2207 } catch (InterruptedException e) {
2208 // Do nothing, go back and check if request is completed or timeout
2209 } finally {
2210 now = SystemClock.elapsedRealtime();
2211 }
2212 }
2213 } else {
2214 // Wait for the request to complete
2215 while (request.result == null) {
2216 try {
2217 request.wait();
2218 } catch (InterruptedException e) {
2219 // Do nothing, go back and wait until the request is complete
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222 }
2223 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002224 if (request.result == null) {
2225 Log.wtf(LOG_TAG,
2226 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 return request.result;
2229 }
2230
2231 /**
2232 * Asynchronous ("fire and forget") version of sendRequest():
2233 * Posts the specified command to be executed on the main thread, and
2234 * returns immediately.
2235 * @see #sendRequest
2236 */
2237 private void sendRequestAsync(int command) {
2238 mMainThreadHandler.sendEmptyMessage(command);
2239 }
2240
2241 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002242 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002244 */
2245 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002246 sendRequestAsync(command, argument, null, null);
2247 }
2248
2249 /**
2250 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2251 * @see {@link #sendRequest(int,Object)}
2252 */
2253 private void sendRequestAsync(
2254 int command, Object argument, Phone phone, WorkSource workSource) {
2255 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002256 Message msg = mMainThreadHandler.obtainMessage(command, request);
2257 msg.sendToTarget();
2258 }
2259
2260 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 * Initialize the singleton PhoneInterfaceManager instance.
2262 * This is only done once, at startup, from PhoneApp.onCreate().
2263 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 synchronized (PhoneInterfaceManager.class) {
2266 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002267 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 } else {
2269 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2270 }
2271 return sInstance;
2272 }
2273 }
2274
2275 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002276 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002279 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002280 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002282 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002284 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002285 mTelephonySharedPreferences =
2286 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002287 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002288 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002289 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002290 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 publish();
2293 }
2294
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 private Phone getDefaultPhone() {
2296 Phone thePhone = getPhone(getDefaultSubscription());
2297 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2298 }
2299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 private void publish() {
2301 if (DBG) log("publish: " + this);
2302
Peter Wangc035ce42020-01-08 21:00:22 -08002303 TelephonyFrameworkInitializer
2304 .getTelephonyServiceManager()
2305 .getTelephonyServiceRegisterer()
2306 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
Stuart Scott584921c2015-01-15 17:10:34 -08002309 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002310 if (request.phone != null) {
2311 return request.phone;
2312 } else {
2313 return getPhoneFromSubId(request.subId);
2314 }
2315 }
2316
2317 private Phone getPhoneFromSubId(int subId) {
2318 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2319 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002320 }
2321
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002322 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 Phone phone = getPhoneFromRequest(request);
2324 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002325 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002326 }
2327
Wink Saville36469e72014-06-11 15:17:00 -07002328 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002329 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002330 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332
Kai Shif70f46f2021-03-03 13:59:46 -08002333 private void sendEraseModemConfig(@NonNull Phone phone) {
2334 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2335 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2336 }
2337
2338 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2339 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2340 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002341 }
2342
Peter Wang44b186e2020-01-13 23:33:09 -08002343 private boolean isImsAvailableOnDevice() {
2344 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2345 if (pm == null) {
2346 // For some reason package manger is not available.. This will fail internally anyway,
2347 // so do not throw error and allow.
2348 return true;
2349 }
2350 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002354 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
Wink Savilleb564aae2014-10-23 10:18:09 -07002357 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 if (DBG) log("dial: " + number);
2359 // No permission check needed here: This is just a wrapper around the
2360 // ACTION_DIAL intent, which is available to any app since it puts up
2361 // the UI before it does anything.
2362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 String url = createTelUrl(number);
2366 if (url == null) {
2367 return;
2368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 // PENDING: should we just silently fail if phone is offhook or ringing?
2371 PhoneConstants.State state = mCM.getState(subId);
2372 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2373 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2374 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2375 mApp.startActivity(intent);
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380 }
2381
2382 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002383 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002384 }
2385
Wink Savilleb564aae2014-10-23 10:18:09 -07002386 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 if (DBG) log("call: " + number);
2388
2389 // This is just a wrapper around the ACTION_CALL intent, but we still
2390 // need to do a permission check since we're calling startActivity()
2391 // from the context of the phone app.
2392 enforceCallPermission();
2393
Jordan Liu1617b712019-07-10 15:06:26 -07002394 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 != AppOpsManager.MODE_ALLOWED) {
2396 return;
2397 }
2398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 String url = createTelUrl(number);
2402 if (url == null) {
2403 return;
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002406 boolean isValid = false;
2407 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2408 if (slist != null) {
2409 for (SubscriptionInfo subInfoRecord : slist) {
2410 if (subInfoRecord.getSubscriptionId() == subId) {
2411 isValid = true;
2412 break;
2413 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002414 }
Wink Saville08874612014-08-31 19:19:58 -07002415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 if (!isValid) {
2417 return;
2418 }
Wink Saville08874612014-08-31 19:19:58 -07002419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2421 intent.putExtra(SUBSCRIPTION_KEY, subId);
2422 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2423 mApp.startActivity(intent);
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002430 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002431 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2432 }
2433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002435 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002436 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2437 }
2438
Wink Savilleb564aae2014-10-23 10:18:09 -07002439 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002444 Phone phone = getPhone(subId);
2445 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 checkSimPin.start();
2447 return checkSimPin.unlockSim(null, pin);
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452
Wink Savilleb564aae2014-10-23 10:18:09 -07002453 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002458 Phone phone = getPhone(subId);
2459 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 checkSimPuk.start();
2461 return checkSimPuk.unlockSim(puk, pin);
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
2464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
2467 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002468 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 * a synchronous one.
2470 */
2471 private static class UnlockSim extends Thread {
2472
2473 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002474 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475
2476 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002477 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2478 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479
2480 // For replies from SimCard interface
2481 private Handler mHandler;
2482
2483 // For async handler to identify request type
2484 private static final int SUPPLY_PIN_COMPLETE = 100;
2485
Michele Berionne5e411512020-11-13 02:36:59 +00002486 UnlockSim(int phoneId, IccCard simCard) {
2487 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 mSimCard = simCard;
2489 }
2490
2491 @Override
2492 public void run() {
2493 Looper.prepare();
2494 synchronized (UnlockSim.this) {
2495 mHandler = new Handler() {
2496 @Override
2497 public void handleMessage(Message msg) {
2498 AsyncResult ar = (AsyncResult) msg.obj;
2499 switch (msg.what) {
2500 case SUPPLY_PIN_COMPLETE:
2501 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2502 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002503 mRetryCount = msg.arg1;
2504 if (ar.exception != null) {
2505 if (ar.exception instanceof CommandException &&
2506 ((CommandException)(ar.exception)).getCommandError()
2507 == CommandException.Error.PASSWORD_INCORRECT) {
2508 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002509 } //When UiccCardApp dispose,handle message and return exception
2510 else if (ar.exception instanceof CommandException &&
2511 ((CommandException) (ar.exception)).getCommandError()
2512 == CommandException.Error.ABORTED) {
2513 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002514 } else {
2515 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2516 }
2517 } else {
2518 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 mDone = true;
2521 UnlockSim.this.notifyAll();
2522 }
2523 break;
2524 }
2525 }
2526 };
2527 UnlockSim.this.notifyAll();
2528 }
2529 Looper.loop();
2530 }
2531
2532 /*
2533 * Use PIN or PUK to unlock SIM card
2534 *
2535 * If PUK is null, unlock SIM card with PIN
2536 *
2537 * If PUK is not null, unlock SIM card with PUK and set PIN code
2538 */
Wink Saville9de0f752013-10-22 19:04:03 -07002539 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
2541 while (mHandler == null) {
2542 try {
2543 wait();
2544 } catch (InterruptedException e) {
2545 Thread.currentThread().interrupt();
2546 }
2547 }
2548 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2549
2550 if (puk == null) {
2551 mSimCard.supplyPin(pin, callback);
2552 } else {
2553 mSimCard.supplyPuk(puk, pin, callback);
2554 }
2555
2556 while (!mDone) {
2557 try {
2558 Log.d(LOG_TAG, "wait for done");
2559 wait();
2560 } catch (InterruptedException e) {
2561 // Restore the interrupted status
2562 Thread.currentThread().interrupt();
2563 }
2564 }
2565 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002566 int[] resultArray = new int[2];
2567 resultArray[0] = mResult;
2568 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002569
2570 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002571 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002572 }
2573
Wink Saville9de0f752013-10-22 19:04:03 -07002574 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576 }
2577
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002578 /**
2579 * This method has been removed due to privacy and stability concerns.
2580 */
2581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002583 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2584 return;
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
Nathan Harold1f889d82020-06-04 17:05:26 -07002587 @Override
2588 public void updateServiceLocationWithPackageName(String callingPackage) {
2589 mApp.getSystemService(AppOpsManager.class)
2590 .checkPackage(Binder.getCallingUid(), callingPackage);
2591
Nathan Haroldf096d982020-11-18 17:18:06 -08002592 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002593 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2594 // Callers targeting S have no business invoking this method.
2595 return;
2596 }
2597
2598 LocationAccessPolicy.LocationPermissionResult locationResult =
2599 LocationAccessPolicy.checkLocationPermission(mApp,
2600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2601 .setCallingPackage(callingPackage)
2602 .setCallingFeatureId(null)
2603 .setCallingPid(Binder.getCallingPid())
2604 .setCallingUid(Binder.getCallingUid())
2605 .setMethod("updateServiceLocation")
2606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2607 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2608 .build());
2609 // Apps that lack location permission have no business calling this method;
2610 // however, because no permission was declared in the public API, denials must
2611 // all be "soft".
2612 switch (locationResult) {
2613 case DENIED_HARD: /* fall through */
2614 case DENIED_SOFT:
2615 return;
2616 }
2617
2618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002621 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002623 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 @Override
2632 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 return isRadioOnWithFeature(callingPackage, null);
2634 }
2635
2636
2637 @Override
2638 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2639 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2640 callingFeatureId);
2641 }
2642
2643 @Deprecated
2644 @Override
2645 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2646 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2651 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002653 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002654 return false;
2655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 return isRadioOnForSubscriber(subId);
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002663 }
2664
2665 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2671 } else {
2672 return false;
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
2679 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002680 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
Wink Saville36469e72014-06-11 15:17:00 -07002682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = getPhone(subId);
2689 if (phone != null) {
2690 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
2697 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002698 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Wink Savilleb564aae2014-10-23 10:18:09 -07002701 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(subId);
2707 if (phone == null) {
2708 return false;
2709 }
2710 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2711 toggleRadioOnOffForSubscriber(subId);
2712 }
2713 return true;
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
Wink Saville36469e72014-06-11 15:17:00 -07002718
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002719 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002720 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 /*
2722 * If any of the Radios are available, it will need to be
2723 * shutdown. So return true if any Radio is available.
2724 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2728 Phone phone = PhoneFactory.getPhone(i);
2729 if (phone != null && phone.isRadioAvailable()) return true;
2730 }
2731 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2732 return false;
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 }
2737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002739 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 enforceModifyPermission();
2741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2745 logv("Shutting down Phone " + i);
2746 shutdownRadioUsingPhoneId(i);
2747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002750 }
2751 }
2752
2753 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002754 Phone phone = PhoneFactory.getPhone(phoneId);
2755 if (phone != null && phone.isRadioAvailable()) {
2756 phone.shutdownRadio();
2757 }
2758 }
2759
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2766 if (defaultPhone != null) {
2767 defaultPhone.setRadioPower(turnOn);
2768 return true;
2769 } else {
2770 loge("There's no default phone.");
2771 return false;
2772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002775 }
Wink Saville36469e72014-06-11 15:17:00 -07002776 }
2777
Wink Savilleb564aae2014-10-23 10:18:09 -07002778 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 final Phone phone = getPhone(subId);
2784 if (phone != null) {
2785 phone.setRadioPower(turnOn);
2786 return true;
2787 } else {
2788 return false;
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
Wink Saville36469e72014-06-11 15:17:00 -07002795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean enableDataConnectivity() {
2798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 int subId = mSubscriptionController.getDefaultDataSubId();
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002805 phone.getDataEnabledSettings().setDataEnabled(
2806 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 return true;
2808 } else {
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Wink Saville36469e72014-06-11 15:17:00 -07002816 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 public boolean disableDataConnectivity() {
2819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 int subId = mSubscriptionController.getDefaultDataSubId();
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002826 phone.getDataEnabledSettings().setDataEnabled(
2827 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 return true;
2829 } else {
2830 return false;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002838 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002843 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 } else {
2845 return false;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002853 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
pkanwarae03a6b2016-11-06 20:37:09 -08002856 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 enforceCallPermission();
2858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2862 return;
2863 }
2864 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2865 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
pkanwar32d516d2016-10-14 19:37:38 -07002869 };
2870
Wink Savilleb564aae2014-10-23 10:18:09 -07002871 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2877 return false;
2878 }
2879 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002885 /**
2886 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2887 * tag on getCallState Binder call.
2888 */
2889 @Deprecated
2890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002892 if (CompatChanges.isChangeEnabled(
2893 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2894 Binder.getCallingUid())) {
2895 // Do not allow this API to be called on API version 31+, it should only be
2896 // called on old apps using this Binder call directly.
2897 throw new SecurityException("This method can only be used for applications "
2898 + "targeting API version 30 or less.");
2899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002902 Phone phone = getPhone(getDefaultSubscription());
2903 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2904 PhoneConstantConversions.convertCallState(phone.getState());
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
2911 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2912 if (CompatChanges.isChangeEnabled(
2913 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2914 Binder.getCallingUid())) {
2915 // Check READ_PHONE_STATE for API version 31+
2916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2917 featureId, "getCallStateForSubscription")) {
2918 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2919 + "targeting API level 31+.");
2920 }
2921 }
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2926 PhoneConstantConversions.convertCallState(phone.getState());
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002933 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002934 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2935 }
2936
2937 @Override
2938 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002941 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002943 if (phone.isUsingNewDataStack()) {
2944 return phone.getDataNetworkController().getInternetDataNetworkState();
2945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2947 } else {
2948 return PhoneConstantConversions.convertDataState(
2949 PhoneConstants.DataState.DISCONNECTED);
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002957 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002958 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2959 }
2960
2961 @Override
2962 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 final long identity = Binder.clearCallingIdentity();
2964 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002965 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 if (phone != null) {
2967 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2968 } else {
2969 return TelephonyManager.DATA_ACTIVITY_NONE;
2970 }
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
2976 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002977 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002979 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002980
2981 LocationAccessPolicy.LocationPermissionResult locationResult =
2982 LocationAccessPolicy.checkLocationPermission(mApp,
2983 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2984 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002985 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002986 .setCallingPid(Binder.getCallingPid())
2987 .setCallingUid(Binder.getCallingUid())
2988 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002989 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002990 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2991 .build());
2992 switch (locationResult) {
2993 case DENIED_HARD:
2994 throw new SecurityException("Not allowed to access cell location");
2995 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002996 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2997 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 }
2999
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003004 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003005 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Svetoslav64fad262015-04-14 14:35:21 -07003009 }
3010
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003012 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003013 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3014 // registered cell info, so return a NULL country instead.
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003017 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3018 // Get default phone in this case.
3019 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3020 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003021 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003023 if (phone == null) return "";
3024 ServiceStateTracker sst = phone.getServiceStateTracker();
3025 if (sst == null) return "";
3026 LocaleTracker lt = sst.getLocaleTracker();
3027 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003028 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003032 }
3033
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003034 /**
3035 * This method was removed due to potential issues caused by performing partial
3036 * updates of service state, and lack of a credible use case.
3037 *
3038 * This has the ability to break the telephony implementation by disabling notification of
3039 * changes in device connectivity. DO NOT USE THIS!
3040 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003041 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 public void enableLocationUpdates() {
3043 mApp.enforceCallingOrSelfPermission(
3044 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 }
3046
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003047 /**
3048 * This method was removed due to potential issues caused by performing partial
3049 * updates of service state, and lack of a credible use case.
3050 *
3051 * This has the ability to break the telephony implementation by disabling notification of
3052 * changes in device connectivity. DO NOT USE THIS!
3053 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 @Override
3055 public void disableLocationUpdates() {
3056 mApp.enforceCallingOrSelfPermission(
3057 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
3060 @Override
3061 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003062 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3063 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003064 try {
3065 mApp.getSystemService(AppOpsManager.class)
3066 .checkPackage(Binder.getCallingUid(), callingPackage);
3067 } catch (SecurityException e) {
3068 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3069 throw e;
3070 }
3071
Nathan Haroldf096d982020-11-18 17:18:06 -08003072 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003073 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3074 throw new SecurityException(
3075 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3076 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003077
Jordan Liu1617b712019-07-10 15:06:26 -07003078 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3080 return null;
3081 }
Svetoslav64fad262015-04-14 14:35:21 -07003082
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003083 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003085 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003086 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087
Nathan Haroldf180aac2018-06-01 18:43:55 -07003088 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3089 for (CellInfo ci : info) {
3090 if (ci instanceof CellInfoGsm) {
3091 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3092 } else if (ci instanceof CellInfoWcdma) {
3093 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003096 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 }
3098
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003099 private List<CellInfo> getCachedCellInfo() {
3100 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3101 for (Phone phone : PhoneFactory.getPhones()) {
3102 List<CellInfo> info = phone.getAllCellInfo();
3103 if (info != null) cellInfos.addAll(info);
3104 }
3105 return cellInfos;
3106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107
3108 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003109 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003110 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003111 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003112
3113 LocationAccessPolicy.LocationPermissionResult locationResult =
3114 LocationAccessPolicy.checkLocationPermission(mApp,
3115 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3116 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003117 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003118 .setCallingPid(Binder.getCallingPid())
3119 .setCallingUid(Binder.getCallingUid())
3120 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003121 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003122 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3123 .build());
3124 switch (locationResult) {
3125 case DENIED_HARD:
3126 throw new SecurityException("Not allowed to access cell info");
3127 case DENIED_SOFT:
3128 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130
Nathan Haroldf096d982020-11-18 17:18:06 -08003131 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003132 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3133 return getCachedCellInfo();
3134 }
3135
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003136 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3141 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003142 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003143 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 if (info != null) cellInfos.addAll(info);
3145 }
3146 return cellInfos;
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 }
3150 }
3151
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003152 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003153 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3154 String callingFeatureId) {
3155 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3156 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003157 }
3158
3159 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3161 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003163 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003164 }
3165
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003166 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3167 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003170
3171 LocationAccessPolicy.LocationPermissionResult locationResult =
3172 LocationAccessPolicy.checkLocationPermission(mApp,
3173 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3174 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003176 .setCallingPid(Binder.getCallingPid())
3177 .setCallingUid(Binder.getCallingUid())
3178 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3180 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .build());
3182 switch (locationResult) {
3183 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003184 if (TelephonyPermissions
3185 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003186 // Safetynet logging for b/154934934
3187 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3188 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003191 if (TelephonyPermissions
3192 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003193 // Safetynet logging for b/154934934
3194 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3195 }
Nathan Harold5320c422019-05-09 10:26:08 -07003196 try {
3197 cb.onCellInfo(new ArrayList<CellInfo>());
3198 } catch (RemoteException re) {
3199 // Drop without consequences
3200 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003201 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003202 }
3203
Nathan Harolda939a962019-05-09 10:13:47 -07003204
3205 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3207
3208 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3209 }
3210
3211 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003213 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223
Shishir Agrawala9f32182016-04-12 12:00:16 -07003224 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003225 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003226 Phone phone = PhoneFactory.getPhone(slotIndex);
3227 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003228 return null;
3229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003230 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003231 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003232 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003233 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003234 return null;
3235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return phone.getImei();
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003243 }
3244
3245 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003246 public String getTypeAllocationCodeForSlot(int slotIndex) {
3247 Phone phone = PhoneFactory.getPhone(slotIndex);
3248 String tac = null;
3249 if (phone != null) {
3250 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003251 try {
3252 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3253 } catch (IndexOutOfBoundsException e) {
3254 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3255 return null;
3256 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003257 }
3258 return tac;
3259 }
3260
3261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003262 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003263 try {
3264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3265 } catch (SecurityException se) {
3266 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3267 throw new SecurityException("Package " + callingPackage + " does not belong to "
3268 + Binder.getCallingUid());
3269 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003270 Phone phone = PhoneFactory.getPhone(slotIndex);
3271 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003272 return null;
3273 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003276 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003278 return null;
3279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 return phone.getMeid();
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
Jack Yu2af8d712017-03-15 17:14:14 -07003287 }
3288
3289 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003290 public String getManufacturerCodeForSlot(int slotIndex) {
3291 Phone phone = PhoneFactory.getPhone(slotIndex);
3292 String manufacturerCode = null;
3293 if (phone != null) {
3294 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003295 try {
3296 manufacturerCode =
3297 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3298 } catch (IndexOutOfBoundsException e) {
3299 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3300 return null;
3301 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 }
3303 return manufacturerCode;
3304 }
3305
3306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003307 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3308 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003309 Phone phone = PhoneFactory.getPhone(slotIndex);
3310 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003311 return null;
3312 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003313 int subId = phone.getSubId();
3314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003315 mApp, subId, callingPackage, callingFeatureId,
3316 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003317 return null;
3318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 return phone.getDeviceSvn();
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003326 }
3327
fionaxu43304da2017-11-27 22:51:16 -08003328 @Override
3329 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
3333 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
fionaxu43304da2017-11-27 22:51:16 -08003337 }
3338
3339 @Override
3340 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
3344 return phone == null ? null : phone.getCarrierName();
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
fionaxu43304da2017-11-27 22:51:16 -08003348 }
3349
calvinpanffe225e2018-11-01 19:43:06 +08003350 @Override
chen xu0026ca62019-03-06 15:28:50 -08003351 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 final Phone phone = getPhone(subId);
3355 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003356 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
3360 }
3361
3362 @Override
chen xu0026ca62019-03-06 15:28:50 -08003363 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003367 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
chen xu651eec72018-11-11 19:03:44 -08003373 @Override
chen xu864e11c2018-12-06 22:10:03 -08003374 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3375 if (!isSubscriptionMccMnc) {
3376 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3377 }
chen xu651eec72018-11-11 19:03:44 -08003378 final Phone phone = PhoneFactory.getPhone(slotIndex);
3379 if (phone == null) {
3380 return TelephonyManager.UNKNOWN_CARRIER_ID;
3381 }
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
3388 }
3389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 //
3391 // Internal helper methods.
3392 //
3393
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003394 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003395 * Make sure the caller is the calling package itself
3396 *
3397 * @throws SecurityException if the caller is not the calling package
3398 */
3399 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3400 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003401 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3402 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003403 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003404 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003405 } catch (PackageManager.NameNotFoundException e) {
3406 // packageUid is -1
3407 }
3408 if (packageUid != callingUid) {
3409 throw new SecurityException(message + ": Package " + callingPackage
3410 + " does not belong to " + callingUid);
3411 }
3412 }
3413
3414 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3416 *
3417 * @throws SecurityException if the caller does not have the required permission
3418 */
3419 private void enforceModifyPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3421 }
3422
Shuo Qian3b6ee772019-11-13 17:43:31 -08003423 private void enforceActiveEmergencySessionPermission() {
3424 mApp.enforceCallingOrSelfPermission(
3425 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3426 }
3427
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 /**
3429 * Make sure the caller has the CALL_PHONE permission.
3430 *
3431 * @throws SecurityException if the caller does not have the required permission
3432 */
3433 private void enforceCallPermission() {
3434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3435 }
3436
paulhu5a773602019-08-23 19:17:33 +08003437 private void enforceSettingsPermission() {
3438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003439 }
3440
Michele Berionne5e411512020-11-13 02:36:59 +00003441 private void enforceRebootPermission() {
3442 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3443 }
3444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 private String createTelUrl(String number) {
3446 if (TextUtils.isEmpty(number)) {
3447 return null;
3448 }
3449
Jake Hambye994d462014-02-03 13:10:13 -08003450 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452
Ihab Awadf9e92732013-12-05 18:02:52 -08003453 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3455 }
3456
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003457 private static void logv(String msg) {
3458 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3459 }
3460
Ihab Awadf9e92732013-12-05 18:02:52 -08003461 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3463 }
3464
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003465 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003467 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003468 }
3469
Sanket Padawe356d7632015-06-22 14:03:32 -07003470 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003471 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = PhoneFactory.getPhone(slotIndex);
3475 if (phone == null) {
3476 return PhoneConstants.PHONE_TYPE_NONE;
3477 } else {
3478 return phone.getPhoneType();
3479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
3486 * Returns the CDMA ERI icon index to display
3487 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3490 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3491 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003492 }
3493
Sanket Padawe356d7632015-06-22 14:03:32 -07003494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3496 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003498 mApp, subId, callingPackage, callingFeatureId,
3499 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 return -1;
3501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 final Phone phone = getPhone(subId);
3506 if (phone != null) {
3507 return phone.getCdmaEriIconIndex();
3508 } else {
3509 return -1;
3510 }
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
3516 /**
3517 * Returns the CDMA ERI icon mode,
3518 * 0 - ON
3519 * 1 - FLASHING
3520 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003522 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3523 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3524 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003525 }
3526
Sanket Padawe356d7632015-06-22 14:03:32 -07003527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003528 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3529 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 mApp, subId, callingPackage, callingFeatureId,
3532 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 return -1;
3534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 return phone.getCdmaEriIconMode();
3541 } else {
3542 return -1;
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003547 }
3548
3549 /**
3550 * Returns the CDMA ERI text,
3551 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3554 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3555 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003556 }
3557
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3560 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003562 mApp, subId, callingPackage, callingFeatureId,
3563 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 return null;
3565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 final Phone phone = getPhone(subId);
3570 if (phone != null) {
3571 return phone.getCdmaEriText();
3572 } else {
3573 return null;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003578 }
3579
3580 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003581 * Returns the CDMA MDN.
3582 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003584 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3586 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 return phone.getLine1Number();
3593 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003594 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 return null;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003599 }
3600 }
3601
3602 /**
3603 * Returns the CDMA MIN.
3604 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003606 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3608 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3614 return phone.getCdmaMin();
3615 } else {
3616 return null;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003620 }
3621 }
3622
Hall Liud892bec2018-11-30 14:51:45 -08003623 @Override
3624 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3625 INumberVerificationCallback callback, String callingPackage) {
3626 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3627 != PERMISSION_GRANTED) {
3628 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3629 }
3630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3631
3632 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3633 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003634 throw new SecurityException("Calling package must be configured in the device config: "
3635 + "calling package: " + callingPackage
3636 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003637 }
3638
3639 if (range == null) {
3640 throw new NullPointerException("Range must be non-null");
3641 }
3642
3643 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003644 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003645
3646 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3647 }
3648
Junda Liuca05d5d2014-08-14 22:36:34 -07003649 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 * Returns true if CDMA provisioning needs to run.
3651 */
3652 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
3661 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003662 * Sets the voice mail number of a given subId.
3663 */
3664 @Override
3665 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3667 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3672 new Pair<String, String>(alphaTag, number), new Integer(subId));
3673 return success;
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003677 }
3678
Ta-wei Yen87c49842016-05-13 21:19:52 -07003679 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003680 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3683 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003684 if (!TextUtils.equals(callingPackage, systemDialer)) {
3685 throw new SecurityException("caller must be system dialer");
3686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3691 if (phoneAccountHandle == null) {
3692 return null;
3693 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003694 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003697 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003698 }
3699
3700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3702 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 mApp, subId, callingPackage, callingFeatureId,
3706 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003707 return null;
3708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003710 final long identity = Binder.clearCallingIdentity();
3711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003716 }
3717
3718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003719 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3720 VisualVoicemailSmsFilterSettings settings) {
3721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003730 }
3731
3732 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003733 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003743 }
3744
3745 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003746 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3747 String callingPackage, int subId) {
3748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003757 }
3758
3759 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003760 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003766 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003770 }
3771
3772 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003773 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3774 String callingAttributionTag, int subId, String number, int port, String text,
3775 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003777 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003778 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003779 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003780 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3781 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003782 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003783
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003784 /**
fionaxu0152e512016-11-14 13:36:14 -08003785 * Sets the voice activation state of a given subId.
3786 */
3787 @Override
3788 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 if (phone != null) {
3796 phone.setVoiceActivationState(activationState);
3797 } else {
3798 loge("setVoiceActivationState fails with invalid subId: " + subId);
3799 }
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003802 }
3803 }
3804
3805 /**
3806 * Sets the data activation state of a given subId.
3807 */
3808 @Override
3809 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3811 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 if (phone != null) {
3817 phone.setDataActivationState(activationState);
3818 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003819 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003823 }
3824 }
3825
3826 /**
3827 * Returns the voice activation state of a given subId.
3828 */
3829 @Override
3830 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
fionaxu0152e512016-11-14 13:36:14 -08003833 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 if (phone != null) {
3837 return phone.getVoiceActivationState();
3838 } else {
3839 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003843 }
3844 }
3845
3846 /**
3847 * Returns the data activation state of a given subId.
3848 */
3849 @Override
3850 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852
fionaxu0152e512016-11-14 13:36:14 -08003853 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 if (phone != null) {
3857 return phone.getDataActivationState();
3858 } else {
3859 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3860 }
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003863 }
3864 }
3865
3866 /**
Wink Saville36469e72014-06-11 15:17:00 -07003867 * Returns the unread count of voicemails for a subId
3868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003870 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3871 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003873 mApp, subId, callingPackage, callingFeatureId,
3874 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003875 return 0;
3876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 final Phone phone = getPhone(subId);
3880 if (phone != null) {
3881 return phone.getVoiceMessageCount();
3882 } else {
3883 return 0;
3884 }
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 }
3889
3890 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003891 * returns true, if the device is in a state where both voice and data
3892 * are supported simultaneously. This can change based on location or network condition.
3893 */
3894 @Override
3895 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = getPhone(subId);
3899 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003903 }
3904
3905 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003906 * Send the dialer code if called from the current default dialer or the caller has
3907 * carrier privilege.
3908 * @param inputCode The dialer code to send
3909 */
3910 @Override
3911 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003913 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003914 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3915 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003916 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003917 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
fionaxu235cc5e2017-03-06 22:25:57 -08003927 }
3928
Pengquan Menga1bb6272018-09-06 09:59:22 -07003929 @Override
3930 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003931 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003932 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003933 mApp, subId, "getNetworkSelectionMode");
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 if (!isActiveSubscription(subId)) {
3937 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3938 }
3939 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003943 }
3944
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003946 public boolean isInEmergencySmsMode() {
3947 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 for (Phone phone : PhoneFactory.getPhones()) {
3951 if (phone.isInEmergencySmsMode()) {
3952 return true;
3953 }
3954 }
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 return false;
3959 }
3960
shilu366312e2019-12-17 09:28:10 -08003961 /**
3962 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3963 * @param subId The subscription to use to check the configuration.
3964 * @param c The callback that will be used to send the result.
3965 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003967 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3968 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003969 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003971
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3974 "IMS not available on device.");
3975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 final long token = Binder.clearCallingIdentity();
3977 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003978 int slotId = getSlotIndexOrException(subId);
3979 verifyImsMmTelConfiguredOrThrow(slotId);
3980 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003981 } catch (ImsException e) {
3982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 } finally {
3984 Binder.restoreCallingIdentity(token);
3985 }
3986 }
3987
shilu366312e2019-12-17 09:28:10 -08003988 /**
3989 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3990 * @param subId The subscription to use to check the configuration.
3991 * @param c The callback that will be used to send the result.
3992 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003994 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003995 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003996 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003997 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3998 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3999 }
Meng Wangafbc5852019-09-19 17:37:13 -07004000 final long token = Binder.clearCallingIdentity();
4001 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4003 .removeRegistrationCallbackForSubscription(c, subId);
4004 } catch (ImsException e) {
4005 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4006 + "is inactive, ignoring unregister.");
4007 // If the subscription is no longer active, just return, since the callback
4008 // will already have been removed internally.
4009 } finally {
4010 Binder.restoreCallingIdentity(token);
4011 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 }
4013
Brad Ebingera34a6c22019-10-22 17:36:18 -07004014 /**
4015 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4016 */
4017 @Override
4018 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4019 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4022 "IMS not available on device.");
4023 }
4024 final long token = Binder.clearCallingIdentity();
4025 try {
4026 Phone phone = getPhone(subId);
4027 if (phone == null) {
4028 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4029 + subId + "'");
4030 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4031 }
4032 phone.getImsRegistrationState(regState -> {
4033 try {
4034 consumer.accept((regState == null)
4035 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4036 } catch (RemoteException e) {
4037 // Ignore if the remote process is no longer available to call back.
4038 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4039 }
4040 });
4041 } finally {
4042 Binder.restoreCallingIdentity(token);
4043 }
4044 }
4045
4046 /**
4047 * Get the transport type for the IMS service registration state.
4048 */
4049 @Override
4050 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004053 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4055 "IMS not available on device.");
4056 }
4057 final long token = Binder.clearCallingIdentity();
4058 try {
4059 Phone phone = getPhone(subId);
4060 if (phone == null) {
4061 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4062 + subId + "'");
4063 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4064 }
4065 phone.getImsRegistrationTech(regTech -> {
4066 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4067 int regTechConverted = (regTech == null)
4068 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4069 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4070 regTechConverted);
4071 try {
4072 consumer.accept(regTechConverted);
4073 } catch (RemoteException e) {
4074 // Ignore if the remote process is no longer available to call back.
4075 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4076 }
4077 });
4078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
4084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4085 * @param subId The subscription to use to check the configuration.
4086 * @param c The callback that will be used to send the result.
4087 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004089 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4090 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004091 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004092 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004093 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4095 "IMS not available on device.");
4096 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 final long token = Binder.clearCallingIdentity();
4098 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004099 int slotId = getSlotIndexOrException(subId);
4100 verifyImsMmTelConfiguredOrThrow(slotId);
4101 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004102 } catch (ImsException e) {
4103 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
4107 }
4108
shilu366312e2019-12-17 09:28:10 -08004109 /**
4110 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4111 * @param subId The subscription to use to check the configuration.
4112 * @param c The callback that will be used to send the result.
4113 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004115 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004116 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004117 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004118 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4119 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4120 }
Meng Wangafbc5852019-09-19 17:37:13 -07004121
4122 final long token = Binder.clearCallingIdentity();
4123 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004125 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004126 } catch (ImsException e) {
4127 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4128 + "is inactive, ignoring unregister.");
4129 // If the subscription is no longer active, just return, since the callback
4130 // will already have been removed internally.
4131 } finally {
4132 Binder.restoreCallingIdentity(token);
4133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 }
4135
4136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004137 public boolean isCapable(int subId, int capability, int regTech) {
4138 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 final long token = Binder.clearCallingIdentity();
4140 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004141 int slotId = getSlotIndexOrException(subId);
4142 verifyImsMmTelConfiguredOrThrow(slotId);
4143 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4146 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004148 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(token);
4152 }
4153 }
4154
4155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004156 public boolean isAvailable(int subId, int capability, int regTech) {
4157 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 final long token = Binder.clearCallingIdentity();
4159 try {
4160 Phone phone = getPhone(subId);
4161 if (phone == null) return false;
4162 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004163 } catch (com.android.ims.ImsException e) {
4164 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4165 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(token);
4168 }
4169 }
4170
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004171 /**
4172 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4173 * subscription.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param callback The callback that will be used to send the result.
4176 * @param capability The MmTelFeature capability that will be used to send the result.
4177 * @param transportType The transport type of the MmTelFeature capability.
4178 */
4179 @Override
4180 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4181 int transportType) {
4182 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4183 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4184 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4185 "IMS not available on device.");
4186 }
4187 final long token = Binder.clearCallingIdentity();
4188 try {
4189 int slotId = getSlotIndex(subId);
4190 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4191 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4192 + subId + "'");
4193 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4194 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004195 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004196 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4197 transportType, aBoolean -> {
4198 try {
4199 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4200 } catch (RemoteException e) {
4201 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4202 + "running. Ignore");
4203 }
4204 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004207 } finally {
4208 Binder.restoreCallingIdentity(token);
4209 }
4210 }
4211
shilu366312e2019-12-17 09:28:10 -08004212 /**
4213 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4214 * @param subId The subscription to use to check the configuration.
4215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 @Override
4217 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004218 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004219 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004220
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004224 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 } catch (ImsException e) {
4227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 } finally {
4229 Binder.restoreCallingIdentity(token);
4230 }
4231 }
4232
4233 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004234 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004236 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 final long identity = Binder.clearCallingIdentity();
4238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004240 // This setting doesn't require an active ImsService connection, so do not verify. The
4241 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
4244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
shilu366312e2019-12-17 09:28:10 -08004250 /**
4251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4252 * @param subId The subscription to use to check the configuration.
4253 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004255 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004257 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004261 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
4268 }
4269
4270 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004271 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004273 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004277 // This setting doesn't require an active ImsService connection, so do not verify. The
4278 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
shilu366312e2019-12-17 09:28:10 -08004287 /**
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 @Override
4292 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004294 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004325 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4326 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4327 * @param subId The subscription to use to check the configuration.
4328 */
4329 @Override
4330 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004332 mApp, subId, "isCrossSimCallingEnabledByUser");
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
4345 /**
4346 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4347 * Requires MODIFY_PHONE_STATE permission.
4348 * @param subId The subscription to use to check the configuration.
4349 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4350 * false otherwise
4351 */
4352 @Override
4353 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4355 "setCrossSimCallingEnabled");
4356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify. The
4360 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 /**
shilu366312e2019-12-17 09:28:10 -08004370 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4371 * @param subId The subscription to use to check the configuration.
4372 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004374
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004376 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004377 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004381 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004383 } catch (ImsException e) {
4384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
4388 }
4389
4390 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004391 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004393 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004397 // This setting doesn't require an active ImsService connection, so do not verify. The
4398 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
4407 @Override
4408 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4410 "setVoWiFiNonPersistent");
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004414 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004416 } catch (ImsException e) {
4417 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
shilu366312e2019-12-17 09:28:10 -08004423 /**
4424 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4425 * @param subId The subscription to use to check the configuration.
4426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 @Override
4428 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004429 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004430 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004436 } catch (ImsException e) {
4437 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
4441 }
4442
4443 @Override
4444 public void setVoWiFiModeSetting(int subId, int mode) {
4445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4446 "setVoWiFiModeSetting");
4447 final long identity = Binder.clearCallingIdentity();
4448 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004450 // This setting doesn't require an active ImsService connection, so do not verify. The
4451 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
4461 public int getVoWiFiRoamingModeSetting(int subId) {
4462 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004465 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004466 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004468 } catch (ImsException e) {
4469 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
4475 @Override
4476 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4478 "setVoWiFiRoamingModeSetting");
4479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify. The
4483 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004484 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004485 } catch (ImsException e) {
4486 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
4490 }
4491
4492 @Override
4493 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4495 "setRttCapabilityEnabled");
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004499 // This setting doesn't require an active ImsService connection, so do not verify. The
4500 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (ImsException e) {
4503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
shilu366312e2019-12-17 09:28:10 -08004509 /**
4510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4511 * @param subId The subscription to use to check the configuration.
4512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 @Override
4514 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004515 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004516 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004520 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004529 @Override
4530 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4531 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004534 if (!isImsAvailableOnDevice()) {
4535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4536 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004537 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
4539 verifyImsMmTelConfiguredOrThrow(slotId);
4540 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004541 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
4549 @Override
4550 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4551 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4552 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004553 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4554 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4555 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004556 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004557 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004558 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004560 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4561 + "is inactive, ignoring unregister.");
4562 // If the subscription is no longer active, just return, since the callback will already
4563 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
allenwtsu99c623b2020-01-03 18:24:23 +08004569
4570 private void checkModifyPhoneStatePermission(int subId, String message) {
4571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4572 message);
4573 }
4574
4575 private boolean isImsProvisioningRequired(int subId, int capability,
4576 boolean isMmtelCapability) {
4577 Phone phone = getPhone(subId);
4578 if (phone == null) {
4579 loge("phone instance null for subid " + subId);
4580 return false;
4581 }
4582 if (isMmtelCapability) {
4583 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4584 return false;
4585 }
4586 } else {
4587 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4588 return false;
4589 }
4590 }
4591 return true;
4592 }
4593
4594 @Override
4595 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4596 boolean isProvisioned) {
4597 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4598
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4602 if (!isImsProvisioningRequired(subId, capability, false)) {
4603 return;
4604 }
4605
4606 // this capability requires provisioning, route to the correct API.
4607 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4608 switch (capability) {
4609 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4610 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4611 ims.setEabProvisioned(isProvisioned);
4612 break;
4613 default: {
4614 throw new IllegalArgumentException("Tried to set provisioning for "
4615 + "rcs capability '" + capability + "', which does not require "
4616 + "provisioning.");
4617 }
4618 }
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622
4623 }
4624
4625
4626 @Override
4627 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4628 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4629 final long identity = Binder.clearCallingIdentity();
4630 try {
4631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4632 if (!isImsProvisioningRequired(subId, capability, false)) {
4633 return true;
4634 }
4635
4636 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4637 switch (capability) {
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4639 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4640 return ims.isEabProvisionedOnDevice();
4641
4642 default: {
4643 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4644 + "capability '" + capability + "', which does not require "
4645 + "provisioning.");
4646 }
4647 }
4648
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
4652 }
4653
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004654 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4656 boolean isProvisioned) {
4657 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004658 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4660 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4662 }
allenwtsu99c623b2020-01-03 18:24:23 +08004663 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004667 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004668 return;
4669 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004670 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4671 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4672 loge("setImsProvisioningStatusForCapability: called for technology that does "
4673 + "not support provisioning - " + tech);
4674 return;
4675 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676
4677 // this capability requires provisioning, route to the correct API.
4678 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4679 switch (capability) {
4680 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4681 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4682 ims.setVolteProvisioned(isProvisioned);
4683 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4684 ims.setWfcProvisioned(isProvisioned);
4685 }
4686 break;
4687 }
4688 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4689 // There is currently no difference in VT provisioning type.
4690 ims.setVtProvisioned(isProvisioned);
4691 break;
4692 }
4693 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4694 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4695 // change the capability of the feature instead if needed.
4696 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4697 == isProvisioned) {
4698 // No change in provisioning.
4699 return;
4700 }
4701 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4702 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004703 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004704 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4706 + ", Exception" + e.getMessage());
4707 }
4708 break;
4709 }
4710 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004711 throw new IllegalArgumentException("Tried to set provisioning for "
4712 + "MmTel capability '" + capability + "', which does not require "
4713 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 }
4715 }
4716
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
4720 }
4721
4722 @Override
4723 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4724 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004725 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4729 }
4730 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004734 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 return true;
4736 }
4737
Brad Ebinger0d79c572021-04-17 15:20:49 -07004738 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4739 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4740 loge("getImsProvisioningStatusForCapability: called for technology that does "
4741 + "not support provisioning - " + tech);
4742 return true;
4743 }
4744
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4746 switch (capability) {
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4748 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4749 return ims.isVolteProvisionedOnDevice();
4750 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4751 return ims.isWfcProvisionedOnDevice();
4752 }
4753 // This should never happen, since we are checking tech above to make sure it
4754 // is either LTE or IWLAN.
4755 throw new IllegalArgumentException("Invalid radio technology for voice "
4756 + "capability.");
4757 }
4758 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4759 // There is currently no difference in VT provisioning type.
4760 return ims.isVtProvisionedOnDevice();
4761 }
4762 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4763 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4764 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4765 }
4766 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004767 throw new IllegalArgumentException(
4768 "Tried to get provisioning for MmTel capability '" + capability
4769 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 }
4771 }
4772
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
4779 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4780 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4781 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4782 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4783 }
4784 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4785 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4786 return (provisionedBits & capability) > 0;
4787 }
4788
4789 @Override
4790 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4791 boolean isProvisioned) {
4792 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4793 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4794 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4795 }
4796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4797 "setProvisioningStatusForCapability");
4798 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4799 // If the current provisioning status for capability already matches isProvisioned,
4800 // do nothing.
4801 if (((provisionedBits & capability) > 0) == isProvisioned) {
4802 return;
4803 }
4804 if (isProvisioned) {
4805 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4806 } else {
4807 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4808 }
4809 }
4810
4811 /**
4812 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4813 * technology. The bitfield should mirror the bitfield defined by
4814 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4815 */
4816 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4817 String key = getMmTelProvisioningKey(subId, tech);
4818 // Default is no capabilities are provisioned.
4819 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4820 }
4821
4822 /**
4823 * Sets the MmTel capability provisioning bitfield (defined by
4824 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4825 * technology specified.
4826 *
4827 * Note: This is a synchronous command and should not be called on UI thread.
4828 */
4829 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4830 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4831 String key = getMmTelProvisioningKey(subId, tech);
4832 editor.putInt(key, newField);
4833 editor.commit();
4834 }
4835
4836 private static String getMmTelProvisioningKey(int subId, int tech) {
4837 // resulting key is provision_ims_mmtel_{subId}_{tech}
4838 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4839 }
4840
4841 /**
4842 * Query CarrierConfig to see if the specified capability requires provisioning for the
4843 * carrier associated with the subscription id.
4844 */
4845 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4846 int capability) {
4847 CarrierConfigManager configManager = new CarrierConfigManager(context);
4848 PersistableBundle c = configManager.getConfigForSubId(subId);
4849 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004850 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4852 false);
4853 boolean requireVoiceVtProvisioning = c.getBoolean(
4854 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4855
4856 // First check to make sure that the capability requires provisioning.
4857 switch (capability) {
4858 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4859 // intentional fallthrough
4860 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4861 if (requireVoiceVtProvisioning) {
4862 // Voice and Video requires provisioning
4863 return true;
4864 }
4865 break;
4866 }
4867 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4868 if (requireUtProvisioning) {
4869 // UT requires provisioning
4870 return true;
4871 }
4872 break;
4873 }
4874 }
4875 return false;
4876 }
4877
allenwtsu99c623b2020-01-03 18:24:23 +08004878 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4879 int capability) {
4880 CarrierConfigManager configManager = new CarrierConfigManager(context);
4881 PersistableBundle c = configManager.getConfigForSubId(subId);
4882
4883 boolean requireRcsProvisioning = c.getBoolean(
4884 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4885
4886 // First check to make sure that the capability requires provisioning.
4887 switch (capability) {
4888 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4889 // intentional fallthrough
4890 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4891 if (requireRcsProvisioning) {
4892 // OPTION or PRESENCE requires provisioning
4893 return true;
4894 }
4895 break;
4896 }
4897 }
4898 return false;
4899 }
4900
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004902 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4904 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4905 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 enforceReadPrivilegedPermission("getImsProvisioningInt");
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 int slotId = getSlotIndex(subId);
4911 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4912 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4913 + subId + "' for key:" + key);
4914 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4915 }
calvinpanb5a34062021-02-08 19:59:36 +08004916 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004917 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4919 + subId + "' for key:" + key);
4920 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
4926 @Override
4927 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4929 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4930 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004931 enforceReadPrivilegedPermission("getImsProvisioningString");
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 int slotId = getSlotIndex(subId);
4936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4937 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4938 + subId + "' for key:" + key);
4939 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4940 }
calvinpanb5a34062021-02-08 19:59:36 +08004941 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4944 + subId + "' for key:" + key);
4945 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 @Override
4952 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4954 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4955 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4957 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 int slotId = getSlotIndex(subId);
4962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4963 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4964 + subId + "' for key:" + key);
4965 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4966 }
calvinpanb5a34062021-02-08 19:59:36 +08004967 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4968 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004970 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
4977 @Override
4978 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004979 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4980 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4981 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4983 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 int slotId = getSlotIndex(subId);
4988 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4989 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4990 + subId + "' for key:" + key);
4991 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4992 }
calvinpanb5a34062021-02-08 19:59:36 +08004993 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4994 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004995 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004996 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004997 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
5001 }
5002
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 /**
5004 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5005 * for the given slot ID or no ImsResolver instance has been created.
5006 * @param slotId The slot ID that the IMS service is created for.
5007 * @throws ImsException If there is no ImsService configured for this slot.
5008 */
5009 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5010 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5011 ImsFeature.FEATURE_MMTEL)) {
5012 throw new ImsException("This subscription does not support MMTEL over IMS",
5013 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5014 }
5015 }
5016
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 int slotId = SubscriptionManager.getSlotIndex(subId);
5019 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5021 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 }
5023 return slotId;
5024 }
5025
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005026 private int getSlotIndex(int subId) {
5027 int slotId = SubscriptionManager.getSlotIndex(subId);
5028 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5029 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5030 }
5031 return slotId;
5032 }
5033
Wink Saville36469e72014-06-11 15:17:00 -07005034 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005035 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005036 */
5037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005040 try {
5041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5042 } catch (SecurityException se) {
5043 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5044 throw new SecurityException("Package " + callingPackage + " does not belong to "
5045 + Binder.getCallingUid());
5046 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005047 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005048 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005049 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005050 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005051 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 mApp, subId, callingPackage, callingFeatureId,
5053 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005054 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5055 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 final Phone phone = getPhone(subId);
5060 if (phone != null) {
5061 return phone.getServiceState().getDataNetworkType();
5062 } else {
5063 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5064 }
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005068 }
5069
5070 /**
5071 * Returns the data network type
5072 */
5073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005074 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005075 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5076 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005077 }
5078
5079 /**
5080 * Returns the data network type for a subId
5081 */
5082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5084 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 mApp, subId, callingPackage, callingFeatureId,
5087 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005088 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5089 }
5090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 final Phone phone = getPhone(subId);
5094 if (phone != null) {
5095 return phone.getServiceState().getDataNetworkType();
5096 } else {
5097 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5098 }
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005102 }
5103
5104 /**
Wink Saville36469e72014-06-11 15:17:00 -07005105 * Returns the Voice network type for a subId
5106 */
5107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005111 mApp, subId, callingPackage, callingFeatureId,
5112 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5114 }
5115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = getPhone(subId);
5119 if (phone != null) {
5120 return phone.getServiceState().getVoiceNetworkType();
5121 } else {
5122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005127 }
5128
5129 /**
5130 * @return true if a ICC card is present
5131 */
5132 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005133 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005134 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5135 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
5138 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005139 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005140 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005142 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 final Phone phone = PhoneFactory.getPhone(slotIndex);
5146 if (phone != null) {
5147 return phone.getIccCard().hasIccCard();
5148 } else {
5149 return false;
5150 }
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005154 }
5155
5156 /**
5157 * Return if the current radio is LTE on CDMA. This
5158 * is a tri-state return value as for a period of time
5159 * the mode may be unknown.
5160 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005162 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005163 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5167 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5168 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
Sanket Padawe356d7632015-06-22 14:03:32 -07005171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5173 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005174 try {
5175 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5176 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005177 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5178 }
5179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 final Phone phone = getPhone(subId);
5183 if (phone == null) {
5184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5185 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005186 return TelephonyProperties.lte_on_cdma_device()
5187 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 }
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005191 }
Wink Saville36469e72014-06-11 15:17:00 -07005192 }
5193
Wink Saville36469e72014-06-11 15:17:00 -07005194 /**
5195 * {@hide}
5196 * Returns Default subId, 0 in the case of single standby.
5197 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005198 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005199 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005200 }
5201
Shishir Agrawala9f32182016-04-12 12:00:16 -07005202 private int getSlotForDefaultSubscription() {
5203 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5204 }
5205
Wink Savilleb564aae2014-10-23 10:18:09 -07005206 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005207 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005208 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005209
Pengquan Menge92a50d2018-09-21 15:54:48 -07005210 private boolean isActiveSubscription(int subId) {
5211 return mSubscriptionController.isActiveSubId(subId);
5212 }
5213
Ihab Awadf2177b72013-11-25 13:33:23 -08005214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5222 getWhenToMakeWifiCallsDefaultPreference());
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005226 }
5227
5228 /**
5229 * @see android.telephony.TelephonyManager.WifiCallingChoices
5230 */
5231 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005240 }
5241
Sailesh Nepald1e68152013-12-12 19:08:02 -08005242 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005243 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005244 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005245 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005246
Jordan Liu4c733742019-02-28 12:03:40 -08005247 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5248 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5249 if (phoneId == -1) {
5250 throw new IllegalArgumentException("Given slot index: " + slotIndex
5251 + " does not correspond to an active phone");
5252 }
5253 return PhoneFactory.getPhone(phoneId);
5254 }
5255
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005257 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5258 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5260 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005262 if (DBG) {
5263 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5264 }
5265 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5266 p2);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269
5270 @Override
5271 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5272 int slotIndex, String callingPackage, String aid, int p2) {
5273 enforceModifyPermission();
5274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5275 if (DBG) {
5276 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5277 }
5278 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5279 callingPackage, aid, p2);
5280 }
5281
5282 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5283 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (TextUtils.equals(ISDR_AID, aid)) {
5287 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5289 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 if (bestComponent == null
5291 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5292 loge("The calling package is not allowed to access ISD-R.");
5293 throw new SecurityException(
5294 "The calling package is not allowed to access ISD-R.");
5295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296 }
Derek Tan740e1672017-06-27 14:56:27 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005299 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5300 null /* workSource */);
5301 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 return response;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306 }
5307
5308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005309 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5313 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315
Jordan Liu4c733742019-02-28 12:03:40 -08005316 @Override
5317 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5318 enforceModifyPermission();
5319 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5320 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5321 channel);
5322 }
5323
5324 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 if (channel < 0) {
5328 return false;
5329 }
Jordan Liu4c733742019-02-28 12:03:40 -08005330 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5331 null /* workSource */);
5332 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return success;
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337 }
5338
5339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005340 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5343 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005344 if (DBG) {
5345 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5346 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5347 + p3 + " data=" + data);
5348 }
5349 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5350 command, p1, p2, p3, data);
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Jordan Liu4c733742019-02-28 12:03:40 -08005353 @Override
5354 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5355 int command, int p1, int p2, int p3, String data) {
5356 enforceModifyPermission();
5357 if (DBG) {
5358 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5359 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5360 + p3 + " data=" + data);
5361 }
5362 return iccTransmitApduLogicalChannelWithPermission(
5363 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5364 data);
5365 }
5366
5367 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5368 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005371 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 return "";
5373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005376 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5377 null /* workSource */);
5378 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 // Append the returned status code to the end of the response payload.
5381 String s = Integer.toHexString(
5382 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5383 if (response.payload != null) {
5384 s = IccUtils.bytesToHexString(response.payload) + s;
5385 }
5386 return s;
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005389 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005390 }
Jake Hambye994d462014-02-03 13:10:13 -08005391
Evan Charltonc66da362014-05-16 14:06:40 -07005392 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005393 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5396 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005398 if (DBG) {
5399 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5400 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5401 }
5402 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5403 cla, command, p1, p2, p3, data);
5404 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405
Jordan Liu4c733742019-02-28 12:03:40 -08005406 @Override
5407 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5408 int command, int p1, int p2, int p3, String data) {
5409 enforceModifyPermission();
5410 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5411 if (DBG) {
5412 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5413 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5414 + " data=" + data);
5415 }
5416
5417 return iccTransmitApduBasicChannelWithPermission(
5418 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5419 p2, p3, data);
5420 }
5421
5422 // open APDU basic channel assuming the caller has sufficient permissions
5423 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5424 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5428 && TextUtils.equals(ISDR_AID, data)) {
5429 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005430 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5431 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 if (bestComponent == null
5433 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5434 loge("The calling package is not allowed to select ISD-R.");
5435 throw new SecurityException(
5436 "The calling package is not allowed to select ISD-R.");
5437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005441 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5442 null /* workSource */);
5443 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 // Append the returned status code to the end of the response payload.
5446 String s = Integer.toHexString(
5447 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5448 if (response.payload != null) {
5449 s = IccUtils.bytesToHexString(response.payload) + s;
5450 }
5451 return s;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 }
5456
5457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005458 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005459 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (DBG) {
5466 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5467 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5468 }
5469
5470 IccIoResult response =
5471 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5472 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5473 subId);
5474
5475 if (DBG) {
5476 log("Exchange SIM_IO [R]" + response);
5477 }
5478
5479 byte[] result = null;
5480 int length = 2;
5481 if (response.payload != null) {
5482 length = 2 + response.payload.length;
5483 result = new byte[length];
5484 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5485 } else {
5486 result = new byte[length];
5487 }
5488
5489 result[length - 1] = (byte) response.sw2;
5490 result[length - 2] = (byte) response.sw1;
5491 return result;
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005495 }
5496
Nathan Haroldb3014052017-01-25 15:57:32 -08005497 /**
5498 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5499 * on a particular subscription
5500 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005501 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5502 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005504 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005505 return null;
5506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (appType != TelephonyManager.APPTYPE_USIM
5511 && appType != TelephonyManager.APPTYPE_SIM) {
5512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5513 return null;
5514 }
5515 Object response = sendRequest(
5516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5517 if (response instanceof String[]) {
5518 return (String[]) response;
5519 }
yincheng zhao2737e882019-09-06 17:06:54 -07005520 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005522 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005526 }
5527
yincheng zhao2737e882019-09-06 17:06:54 -07005528 /**
5529 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5530 * subscription.
5531 *
5532 * @param subId the id of the subscription.
5533 * @param appType the uicc app type, must be USIM or SIM.
5534 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5535 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005536 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005537 * @return number of fplmns that is successfully written to the SIM.
5538 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005539 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5540 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5542 mApp, subId, "setForbiddenPlmns");
5543
yincheng zhao2737e882019-09-06 17:06:54 -07005544 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5545 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5546 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5547 }
5548 if (fplmns == null) {
5549 throw new IllegalArgumentException("Fplmn List provided is null");
5550 }
5551 for (String fplmn : fplmns) {
5552 if (!CellIdentity.isValidPlmn(fplmn)) {
5553 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5554 }
5555 }
5556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 Object response = sendRequest(
5559 CMD_SET_FORBIDDEN_PLMNS,
5560 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5561 subId);
5562 return (int) response;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
5566 }
5567
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005568 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005569 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5571 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5576 if (response.payload == null) {
5577 return "";
5578 }
Evan Charltonc66da362014-05-16 14:06:40 -07005579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 // Append the returned status code to the end of the response payload.
5581 String s = Integer.toHexString(
5582 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5583 s = IccUtils.bytesToHexString(response.payload) + s;
5584 return s;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Evan Charltonc66da362014-05-16 14:06:40 -07005588 }
5589
Jake Hambye994d462014-02-03 13:10:13 -08005590 /**
5591 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5592 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5593 *
5594 * @param itemID the ID of the item to read
5595 * @return the NV item as a String, or null on error.
5596 */
5597 @Override
5598 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005606 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5608 return value;
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
Jake Hambye994d462014-02-03 13:10:13 -08005612 }
5613
5614 /**
5615 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5616 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5617 *
5618 * @param itemID the ID of the item to read
5619 * @param itemValue the value to write, as a String
5620 * @return true on success; false on any failure
5621 */
5622 @Override
5623 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5631 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005632 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5634 return success;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Jake Hambye994d462014-02-03 13:10:13 -08005638 }
5639
5640 /**
5641 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5642 * Used for device configuration by some CDMA operators.
5643 *
5644 * @param preferredRoamingList byte array containing the new PRL
5645 * @return true on success; false on any failure
5646 */
5647 @Override
5648 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5650 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5655 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5656 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5657 return success;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Jake Hambye994d462014-02-03 13:10:13 -08005661 }
5662
5663 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005664 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005665 * Used for device configuration by some CDMA operators.
5666 *
chen xu6dac5ab2018-10-26 17:39:23 -07005667 * @param slotIndex - device slot.
5668 *
Jake Hambye994d462014-02-03 13:10:13 -08005669 * @return true on success; false on any failure
5670 */
5671 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005672 public boolean resetModemConfig(int slotIndex) {
5673 Phone phone = PhoneFactory.getPhone(slotIndex);
5674 if (phone != null) {
5675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5676 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
chen xu6dac5ab2018-10-26 17:39:23 -07005678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5681 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5682 return success;
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 }
chen xu6dac5ab2018-10-26 17:39:23 -07005687 return false;
5688 }
5689
5690 /**
5691 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5692 *
5693 * @param slotIndex - device slot.
5694 *
5695 * @return true on success; false on any failure
5696 */
5697 @Override
5698 public boolean rebootModem(int slotIndex) {
5699 Phone phone = PhoneFactory.getPhone(slotIndex);
5700 if (phone != null) {
5701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5702 mApp, phone.getSubId(), "rebootModem");
5703
5704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5707 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5708 return success;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005714 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005715
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005716 public String[] getPcscfAddress(String apnType, String callingPackage,
5717 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5720 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005721 return new String[0];
5722 }
5723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005726 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Wink Saville36469e72014-06-11 15:17:00 -07005730 }
5731
Brad Ebinger51f743a2017-01-23 13:50:20 -08005732 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005733 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5734 * {@link #disableIms(int)}.
5735 * @param slotIndex device slot.
5736 */
5737 public void resetIms(int slotIndex) {
5738 enforceModifyPermission();
5739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 if (mImsResolver == null) {
5743 // may happen if the does not support IMS.
5744 return;
5745 }
5746 mImsResolver.disableIms(slotIndex);
5747 mImsResolver.enableIms(slotIndex);
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
5751 }
5752
5753 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005754 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5755 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005756 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005757 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
5761 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 // may happen if the device does not support IMS.
5764 return;
5765 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005770 }
5771
5772 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005773 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5774 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005775 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 public void disableIms(int slotId) {
5777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778
5779 final long identity = Binder.clearCallingIdentity();
5780 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 // may happen if the device does not support IMS.
5783 return;
5784 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005789 }
5790
5791 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005792 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5793 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005794 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005795 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005796 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5803 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005805 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005809 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005810 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005811 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5812 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005813 @Override
5814 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005815 enforceModifyPermission();
5816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005820 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005827 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005828 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005829 */
5830 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005836 // may happen if the device does not support IMS.
5837 return null;
5838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 } finally {
5841 Binder.restoreCallingIdentity(identity);
5842 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005843 }
5844
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005845 /**
5846 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005847 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005848 */
5849 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005855 // may happen if the device does not support IMS.
5856 return null;
5857 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005862 }
5863
Brad Ebinger884c07b2018-02-15 16:17:40 -08005864 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 * Sets the ImsService Package Name that Telephony will bind to.
5866 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 * @param slotIndex the slot ID that the ImsService should bind for.
5868 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005869 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 * @param featureTypes An integer array of feature types associated with a packageName.
5871 * @param packageName The name of the package that the current configuration will be replaced
5872 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5876 int[] featureTypes, String packageName) {
5877 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5880 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return false;
5888 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 Map<Integer, String> featureConfig = new HashMap<>();
5890 for (int featureType : featureTypes) {
5891 featureConfig.put(featureType, packageName);
5892 }
5893 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5894 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005898 }
5899
5900 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005901 * Clears any carrier ImsService overrides for the slot index specified that were previously
5902 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5903 *
5904 * This should only be used for testing.
5905 *
5906 * @param slotIndex the slot ID that the ImsService should bind for.
5907 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5908 */
5909 @Override
5910 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5911 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5913 "clearCarrierImsServiceOverride");
5914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5915 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5916 "clearCarrierImsServiceOverride");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (mImsResolver == null) {
5921 // may happen if the device does not support IMS.
5922 return false;
5923 }
5924 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005932 *
5933 * @param slotId The slot that the ImsService is associated with.
5934 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5935 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005937 * @return the package name of the ImsService configuration.
5938 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5940 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005941 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005943 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5945 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005950 // may happen if the device does not support IMS.
5951 return "";
5952 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005953 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5955 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005959 }
5960
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005961 /**
5962 * Get the MmTelFeature state associated with the requested subscription id.
5963 * @param subId The subscription that the MmTelFeature is associated with.
5964 * @param callback A callback with an integer containing the
5965 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5966 */
5967 @Override
5968 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5969 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5970 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5971 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5972 "IMS not available on device.");
5973 }
5974 final long token = Binder.clearCallingIdentity();
5975 try {
5976 int slotId = getSlotIndex(subId);
5977 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5978 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5979 + subId + "'");
5980 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5981 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005982 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005983 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5984 try {
5985 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5986 } catch (RemoteException e) {
5987 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5988 + "Ignore");
5989 }
5990 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005991 } catch (ImsException e) {
5992 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005993 } finally {
5994 Binder.restoreCallingIdentity(token);
5995 }
5996 }
5997
Daniel Brightbb5840b2021-01-12 15:48:18 -08005998 /**
5999 * Sets the ims registration state on all valid {@link Phone}s.
6000 */
6001 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006006 // NOTE: Before S, this method only set the default phone.
6007 for (final Phone phone : PhoneFactory.getPhones()) {
6008 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6009 phone.setImsRegistrationState(registered);
6010 }
6011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Wink Saville36469e72014-06-11 15:17:00 -07006015 }
6016
6017 /**
Stuart Scott54788802015-03-30 13:18:01 -07006018 * Set the network selection mode to automatic.
6019 *
6020 */
6021 @Override
6022 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
shilufc958392020-01-20 11:36:01 -08006028 if (!isActiveSubscription(subId)) {
6029 return;
6030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006032 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6033 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Stuart Scott54788802015-03-30 13:18:01 -07006037 }
6038
Jack Yud10cdd42020-09-28 20:28:01 -07006039 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 * Ask the radio to connect to the input network and change selection mode to manual.
6041 *
6042 * @param subId the id of the subscription.
6043 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6044 * the operator to attach to.
6045 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6046 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6047 * normal network selection next time.
6048 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006049 */
6050 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006051 public boolean setNetworkSelectionModeManual(
6052 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6054 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006055
6056 if (!isActiveSubscription(subId)) {
6057 return false;
6058 }
6059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006062 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 if (DBG) {
6065 log("setNetworkSelectionModeManual: subId: " + subId
6066 + " operator: " + operatorInfo);
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006072 }
shilu84f6e8b2019-12-19 13:58:01 -08006073 /**
6074 * Get the manual network selection
6075 *
6076 * @param subId the id of the subscription.
6077 *
6078 * @return the previously saved user selected PLMN
6079 */
6080 @Override
6081 public String getManualNetworkSelectionPlmn(int subId) {
6082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006083 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006084 mApp, subId, "getManualNetworkSelectionPlmn");
6085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006089 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006090 }
6091
6092 final Phone phone = getPhone(subId);
6093 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006094 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006095 }
6096 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6097 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6098 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006103
6104 /**
6105 * Scans for available networks.
6106 */
6107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006108 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006112 LocationAccessPolicy.LocationPermissionResult locationResult =
6113 LocationAccessPolicy.checkLocationPermission(mApp,
6114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 .setCallingPid(Binder.getCallingPid())
6118 .setCallingUid(Binder.getCallingUid())
6119 .setMethod("getCellNetworkScanResults")
6120 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006121 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6122 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006123 .build());
6124 switch (locationResult) {
6125 case DENIED_HARD:
6126 throw new SecurityException("Not allowed to access scan results -- location");
6127 case DENIED_SOFT:
6128 return null;
6129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
Pengquan Menga1bb6272018-09-06 09:59:22 -07006131 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 try {
6133 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006134 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006139 }
6140
6141 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006142 * Get the call forwarding info, given the call forwarding reason.
6143 */
6144 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006145 public void getCallForwarding(int subId, int callForwardingReason,
6146 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006147 enforceReadPrivilegedPermission("getCallForwarding");
6148 long identity = Binder.clearCallingIdentity();
6149 try {
6150 if (DBG) {
6151 log("getCallForwarding: subId " + subId
6152 + " callForwardingReason" + callForwardingReason);
6153 }
Hall Liu27d24262020-09-18 19:04:59 -07006154
6155 Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006158 callback.onError(
6159 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 return;
6164 }
6165
6166 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6167 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6168 @Override
6169 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6170 try {
6171 callback.onCallForwardingInfoAvailable(info);
6172 } catch (RemoteException e) {
6173 // ignore
6174 }
6175 }
6176
6177 @Override
6178 public void onError(int error) {
6179 try {
6180 callback.onError(error);
6181 } catch (RemoteException e) {
6182 // ignore
6183 }
6184 }
6185 });
6186 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
6193 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6194 * reason, the number to forward, and the timeout before the forwarding is attempted.
6195 */
6196 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006197 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6198 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006199 enforceModifyPermission();
6200 long identity = Binder.clearCallingIdentity();
6201 try {
6202 if (DBG) {
6203 log("setCallForwarding: subId " + subId
6204 + " callForwardingInfo" + callForwardingInfo);
6205 }
Hall Liu27d24262020-09-18 19:04:59 -07006206
6207 Phone phone = getPhone(subId);
6208 if (phone == null) {
6209 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006210 callback.accept(
6211 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006212 } catch (RemoteException e) {
6213 // ignore
6214 }
6215 return;
6216 }
6217
6218 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6219 FunctionalUtils.ignoreRemoteException(callback::accept));
6220
6221 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
6225 }
6226
6227 /**
Hall Liu27d24262020-09-18 19:04:59 -07006228 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006229 */
6230 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006231 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006232 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006233 long identity = Binder.clearCallingIdentity();
6234 try {
Hall Liu27d24262020-09-18 19:04:59 -07006235 Phone phone = getPhone(subId);
6236 if (phone == null) {
6237 try {
6238 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6239 } catch (RemoteException e) {
6240 // ignore
6241 }
6242 return;
6243 }
SongFerngWang0e767992021-03-31 22:08:45 +08006244 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6245 PersistableBundle c = configManager.getConfigForSubId(subId);
6246 boolean requireUssd = c.getBoolean(
6247 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006248
Shuo Qian4a594052020-01-23 11:59:30 -08006249 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006250 if (requireUssd) {
6251 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6252 getSubscriptionCarrierId(subId));
6253 String newUssdCommand = "";
6254 try {
6255 newUssdCommand = carrierXmlParser.getFeature(
6256 CarrierXmlParser.FEATURE_CALL_WAITING)
6257 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6258 } catch (NullPointerException e) {
6259 loge("Failed to generate USSD number" + e);
6260 }
6261 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6262 mMainThreadHandler, callback, carrierXmlParser,
6263 CarrierXmlParser.SsEntry.SSAction.QUERY);
6264 final String ussdCommand = newUssdCommand;
6265 Executors.newSingleThreadExecutor().execute(() -> {
6266 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6267 });
6268 } else {
6269 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6270 callback::accept);
6271 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6272 }
Shuo Qian4a594052020-01-23 11:59:30 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
6276 }
6277
6278 /**
Hall Liu27d24262020-09-18 19:04:59 -07006279 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006280 */
6281 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006282 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006283 enforceModifyPermission();
6284 long identity = Binder.clearCallingIdentity();
6285 try {
Hall Liu27d24262020-09-18 19:04:59 -07006286 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6287
6288 Phone phone = getPhone(subId);
6289 if (phone == null) {
6290 try {
6291 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6292 } catch (RemoteException e) {
6293 // ignore
6294 }
6295 return;
6296 }
6297
SongFerngWang0e767992021-03-31 22:08:45 +08006298 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6299 PersistableBundle c = configManager.getConfigForSubId(subId);
6300 boolean requireUssd = c.getBoolean(
6301 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006302
SongFerngWang0e767992021-03-31 22:08:45 +08006303 if (DBG) log("getCallWaitingStatus: subId " + subId);
6304 if (requireUssd) {
6305 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6306 getSubscriptionCarrierId(subId));
6307 CarrierXmlParser.SsEntry.SSAction ssAction =
6308 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6309 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6310 String newUssdCommand = "";
6311 try {
6312 newUssdCommand = carrierXmlParser.getFeature(
6313 CarrierXmlParser.FEATURE_CALL_WAITING)
6314 .makeCommand(ssAction, null);
6315 } catch (NullPointerException e) {
6316 loge("Failed to generate USSD number" + e);
6317 }
6318 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6319 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6320 final String ussdCommand = newUssdCommand;
6321 Executors.newSingleThreadExecutor().execute(() -> {
6322 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6323 });
6324 } else {
6325 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6326 FunctionalUtils.ignoreRemoteException(callback::accept));
6327
6328 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6329 }
Shuo Qian4a594052020-01-23 11:59:30 -08006330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
6333 }
6334
6335 /**
yinxub1bed742017-04-17 11:45:04 -07006336 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006337 *
yinxub1bed742017-04-17 11:45:04 -07006338 * @param subId id of the subscription
6339 * @param request contains the radio access networks with bands/channels to scan
6340 * @param messenger callback messenger for scan results or errors
6341 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006342 * @return the id of the requested scan which can be used to stop the scan.
6343 */
6344 @Override
6345 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006346 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6348 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006349 LocationAccessPolicy.LocationPermissionResult locationResult =
6350 LocationAccessPolicy.checkLocationPermission(mApp,
6351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6352 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006353 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006354 .setCallingPid(Binder.getCallingPid())
6355 .setCallingUid(Binder.getCallingUid())
6356 .setMethod("requestNetworkScan")
6357 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006358 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6359 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006360 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006362 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6363 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 if (e != null) {
6365 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6366 throw e;
6367 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006368 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 return TelephonyScanManager.INVALID_SCAN_ID;
6370 }
6371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 }
Hall Liu912dfd32019-04-25 14:02:26 -07006373 int callingUid = Binder.getCallingUid();
6374 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 return mNetworkScanRequestTracker.startNetworkScan(
6378 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006379 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
yinxu504e1392017-04-12 16:03:22 -07006383 }
6384
Hall Liub2ac8ef2019-02-28 15:56:23 -08006385 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006386 NetworkScanRequest request, int subId, String callingPackage) {
6387 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006388 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6389 boolean hasNetworkScanPermission =
6390 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6391 == PERMISSION_GRANTED;
6392
6393 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6394 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6395 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006396 }
6397
6398 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6399 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006400 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6401 return new SecurityException("Specific channels must not be"
6402 + " scanned without location access.");
6403 }
6404 }
6405 }
6406
Hall Liub2ac8ef2019-02-28 15:56:23 -08006407 return null;
6408 }
6409
yinxu504e1392017-04-12 16:03:22 -07006410 /**
6411 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006412 *
6413 * @param subId id of the subscription
6414 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006415 */
6416 @Override
6417 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6419 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
Hall Liu912dfd32019-04-25 14:02:26 -07006421 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 final long identity = Binder.clearCallingIdentity();
6423 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006424 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
yinxu504e1392017-04-12 16:03:22 -07006428 }
6429
6430 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006432 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006433 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006434 */
6435 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006436 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006437 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006438 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006439 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006443 if (DBG) log("getAllowedNetworkTypesBitmask");
6444 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6445 int networkTypesBitmask = (result != null ? result[0] : -1);
6446 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6447 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006451 }
6452
6453 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 * Get the allowed network types for certain reason.
6455 *
6456 * @param subId the id of the subscription.
6457 * @param reason the reason the allowed network type change is taking place
6458 * @return the allowed network types.
6459 */
6460 @Override
6461 public long getAllowedNetworkTypesForReason(int subId,
6462 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006463 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006464 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006474 * Enable/Disable E-UTRA-NR Dual Connectivity
6475 * @param subId subscription id of the sim card
6476 * @param nrDualConnectivityState expected NR dual connectivity state
6477 * This can be passed following states
6478 * <ol>
6479 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6480 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6481 * <li>Disable NR dual connectivity and force secondary cell to be released
6482 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6483 * </ol>
6484 * @return operation result.
6485 */
6486 @Override
6487 public int setNrDualConnectivityState(int subId,
6488 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6490 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006491 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006492 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6493 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6494 }
6495
Sooraj Sasindran37444802020-08-11 10:40:43 -07006496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6500 nrDualConnectivityState, subId,
6501 workSource);
6502 if (DBG) log("enableNRDualConnectivity result: " + result);
6503 return result;
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
6507 }
6508
6509 /**
6510 * Is E-UTRA-NR Dual Connectivity enabled
6511 * @return true if dual connectivity is enabled else false
6512 */
6513 @Override
6514 public boolean isNrDualConnectivityEnabled(int subId) {
6515 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006516 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006517 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006518 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006519 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6520 return false;
6521 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6526 null, subId, workSource);
6527 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6528 return isEnabled;
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006535 * Set the allowed network types of the device and
6536 * provide the reason triggering the allowed network change.
6537 *
6538 * @param subId the id of the subscription.
6539 * @param reason the reason the allowed network type change is taking place
6540 * @param allowedNetworkTypes the allowed network types.
6541 * @return true on success; false on any failure.
6542 */
6543 @Override
6544 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 @TelephonyManager.AllowedNetworkTypesReason int reason,
6546 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6548 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006550 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6551 return false;
6552 }
6553 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6554 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006555 return false;
6556 }
6557
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6559 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6560
6561
6562 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6563 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6564 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006565 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006566
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 final long identity = Binder.clearCallingIdentity();
6568 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006569 Boolean success = (Boolean) sendRequest(
6570 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6571 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6572
6573 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6574 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
6578 }
6579
6580 /**
Miaoa84611c2019-03-15 09:21:10 +08006581 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006582 *
Miaoa84611c2019-03-15 09:21:10 +08006583 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006584 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006585 * @hide
6586 */
6587 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006588 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 try {
Miaoa84611c2019-03-15 09:21:10 +08006593 if (phone != null) {
6594 return phone.hasMatchedTetherApnSetting();
6595 } else {
6596 return false;
6597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 } finally {
6599 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006600 }
Junda Liu475951f2014-11-07 16:45:03 -08006601 }
6602
6603 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006604 * Get the user enabled state of Mobile Data.
6605 *
6606 * TODO: remove and use isUserDataEnabled.
6607 * This can't be removed now because some vendor codes
6608 * calls through ITelephony directly while they should
6609 * use TelephonyManager.
6610 *
6611 * @return true on enabled
6612 */
6613 @Override
6614 public boolean getDataEnabled(int subId) {
6615 return isUserDataEnabled(subId);
6616 }
6617
6618 /**
6619 * Get whether mobile data is enabled per user setting.
6620 *
6621 * There are other factors deciding whether mobile data is actually enabled, but they are
6622 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006623 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006624 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006625 *
6626 * @return {@code true} if data is enabled else {@code false}
6627 */
6628 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006629 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006630 try {
6631 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6632 null);
6633 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6635 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 int phoneId = mSubscriptionController.getPhoneId(subId);
6641 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6642 Phone phone = PhoneFactory.getPhone(phoneId);
6643 if (phone != null) {
6644 boolean retVal = phone.isUserDataEnabled();
6645 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6646 return retVal;
6647 } else {
6648 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6649 return false;
6650 }
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006653 }
6654 }
6655
6656 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006657 * Checks if the device is capable of mobile data by considering whether whether the
6658 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6659 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006660 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006661 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006662 */
6663 @Override
6664 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 try {
6666 try {
6667 mApp.enforceCallingOrSelfPermission(
6668 android.Manifest.permission.ACCESS_NETWORK_STATE,
6669 null);
6670 } catch (Exception e) {
6671 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6672 "isDataEnabled");
6673 }
6674 } catch (Exception e) {
6675 enforceReadPrivilegedPermission("isDataEnabled");
6676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 int phoneId = mSubscriptionController.getPhoneId(subId);
6681 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6682 Phone phone = PhoneFactory.getPhone(phoneId);
6683 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006684 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6686 return retVal;
6687 } else {
6688 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6689 return false;
6690 }
6691 } finally {
6692 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006693 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006694 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006695
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006696 /**
6697 * Check if data is enabled for a specific reason
6698 * @param subId Subscription index
6699 * @param reason the reason the data enable change is taking place
6700 * @return {@code true} if the overall data is enabled; {@code false} if not.
6701 */
6702 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006703 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006704 @TelephonyManager.DataEnabledReason int reason) {
6705 try {
6706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6707 null);
6708 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006709 try {
6710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6711 "isDataEnabledForReason");
6712 } catch (Exception e2) {
6713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6714 mApp, subId, "isDataEnabledForReason");
6715 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 }
6717
6718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 int phoneId = mSubscriptionController.getPhoneId(subId);
6722 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006723 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006724 + " reason=" + reason);
6725 }
6726 Phone phone = PhoneFactory.getPhone(phoneId);
6727 if (phone != null) {
6728 boolean retVal;
6729 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6730 retVal = phone.isUserDataEnabled();
6731 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006732 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006733 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006734 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006735 return retVal;
6736 } else {
6737 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006738 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006739 + subId + " retVal=false");
6740 }
6741 return false;
6742 }
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006748 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006749 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006750 if (uid == Process.PHONE_UID) {
6751 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6752 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6754 }
6755
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006756 //load access rules from carrier configs, and check those as well: b/139133814
6757 SubscriptionController subController = SubscriptionController.getInstance();
6758 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6759 || subController == null) return privilegeFromSim;
6760
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006761 PackageManager pkgMgr = phone.getContext().getPackageManager();
6762 String[] packages = pkgMgr.getPackagesForUid(uid);
6763
6764 final long identity = Binder.clearCallingIdentity();
6765 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006766 int subId = phone.getSubId();
6767 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6768 // A test override is in place for the privileges for this subId, so don't try to
6769 // read the subscription privileges.
6770 return privilegeFromSim;
6771 }
6772 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773 SubscriptionManager subManager = (SubscriptionManager)
6774 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6775 for (String pkg : packages) {
6776 if (subManager.canManageSubscription(subInfo, pkg)) {
6777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6778 }
6779 }
6780 return privilegeFromSim;
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
6785
6786 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6787 String pkgName) {
6788 //load access rules from carrier configs, and check those as well: b/139133814
6789 SubscriptionController subController = SubscriptionController.getInstance();
6790 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6791 || subController == null) return privilegeFromSim;
6792
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006795 int subId = phone.getSubId();
6796 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6797 // A test override is in place for the privileges for this subId, so don't try to
6798 // read the subscription privileges.
6799 return privilegeFromSim;
6800 }
6801 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006802 SubscriptionManager subManager = (SubscriptionManager)
6803 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6804 return subManager.canManageSubscription(subInfo, pkgName)
6805 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
6809 }
6810
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006811 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006812 public int getCarrierPrivilegeStatus(int subId) {
6813 final Phone phone = getPhone(subId);
6814 if (phone == null) {
6815 loge("getCarrierPrivilegeStatus: Invalid subId");
6816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6817 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006818 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6819 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006820 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6822 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006823
6824 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006825 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006826 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006827 }
Junda Liu29340342014-07-10 15:23:27 -07006828
6829 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006831 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006832 final Phone phone = getPhone(subId);
6833 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006834 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6836 }
6837 UiccProfile profile =
6838 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6839 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006840 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006841 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6842 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006843 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006844 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006845 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 }
6847
6848 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006849 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006850 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006851 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006853 }
6854
6855 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6857 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006858 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6860 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006861 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006862 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006863 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006864 }
6865
6866 @Override
6867 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006868 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006869 if (TextUtils.isEmpty(pkgName))
6870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006871 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6872 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006873 UiccPort port = UiccController.getInstance().getUiccPort(i);
6874 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006875 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 continue;
6877 }
6878
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006879 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006880 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006881 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006882 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6883 break;
6884 }
6885 }
6886
6887 return result;
Junda Liu29340342014-07-10 15:23:27 -07006888 }
Derek Tan89e89d42014-07-08 17:00:10 -07006889
6890 @Override
Junda Liue64de782015-04-16 17:19:16 -07006891 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006892 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006893 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6894 loge("phoneId " + phoneId + " is not valid.");
6895 return null;
6896 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006897 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6898 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006899 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006900 return null ;
6901 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006902 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006903 }
6904
Amith Yamasani6e118872016-02-19 12:53:51 -08006905 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006906 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006908 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006909 List<String> privilegedPackages = new ArrayList<>();
6910 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006911 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006912 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006913 if (port != null) {
6914 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006915 if (packages == null) {
6916 // Only check packages in user 0 for now
6917 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006918 PackageManager.MATCH_DISABLED_COMPONENTS
6919 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006920 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006921 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006922 }
6923 for (int p = packages.size() - 1; p >= 0; p--) {
6924 PackageInfo pkgInfo = packages.get(p);
6925 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006926 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6927 port.getCarrierPrivilegeStatus(pkgInfo),
6928 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006929 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006930 privilegedPackages.add(pkgInfo.packageName);
6931 }
6932 }
6933 }
6934 }
6935 return privilegedPackages;
6936 }
6937
chen xuf7e9fe82019-05-09 19:31:02 -07006938 @Override
6939 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006940 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6941
6942 final long identity = Binder.clearCallingIdentity();
6943
chen xuf7e9fe82019-05-09 19:31:02 -07006944 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006945 try {
6946 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6947 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6948 }
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006951 }
6952 return privilegedPackages;
6953 }
6954
Wink Savilleb564aae2014-10-23 10:18:09 -07006955 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006956 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006957 UiccPort port = phone == null ? null : phone.getUiccPort();
6958 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006959 return null;
6960 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006961 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006962 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006963 return null;
6964 }
6965 return iccId;
6966 }
6967
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006968 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006969 public void setCallComposerStatus(int subId, int status) {
6970 enforceModifyPermission();
6971
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 Phone phone = getPhone(subId);
6975 if (phone != null) {
6976 Phone defaultPhone = phone.getImsPhone();
6977 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6978 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6979 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006980 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6981 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006982 }
6983 }
Shuo Qian284ae752020-12-22 19:10:14 -08006984 } catch (ImsException e) {
6985 throw new ServiceSpecificException(e.getCode());
6986 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006987 Binder.restoreCallingIdentity(identity);
6988 }
6989 }
6990
6991 @Override
6992 public int getCallComposerStatus(int subId) {
6993 enforceReadPrivilegedPermission("getCallComposerStatus");
6994
6995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 Phone phone = getPhone(subId);
6998 if (phone != null) {
6999 Phone defaultPhone = phone.getImsPhone();
7000 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7001 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7002 return imsPhone.getCallComposerStatus();
7003 }
7004 }
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7009 }
7010
7011 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007012 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7013 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007015 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 final String iccId = getIccId(subId);
7020 final Phone phone = getPhone(subId);
7021 if (phone == null) {
7022 return false;
7023 }
7024 final String subscriberId = phone.getSubscriberId();
7025
7026 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007027 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 + subscriberId + " to " + number);
7029 }
7030
7031 if (TextUtils.isEmpty(iccId)) {
7032 return false;
7033 }
7034
7035 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7036
7037 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7038 if (alphaTag == null) {
7039 editor.remove(alphaTagPrefKey);
7040 } else {
7041 editor.putString(alphaTagPrefKey, alphaTag);
7042 }
7043
7044 // Record both the line number and IMSI for this ICCID, since we need to
7045 // track all merged IMSIs based on line number
7046 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7047 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7048 if (number == null) {
7049 editor.remove(numberPrefKey);
7050 editor.remove(subscriberPrefKey);
7051 } else {
7052 editor.putString(numberPrefKey, number);
7053 editor.putString(subscriberPrefKey, subscriberId);
7054 }
7055
7056 editor.commit();
7057 return true;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007060 }
Derek Tan7226c842014-07-02 17:42:23 -07007061 }
7062
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public String getLine1NumberForDisplay(int subId, String callingPackage,
7065 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007066 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007068 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007069 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007070 return null;
7071 }
Derek Tan97ebb422014-09-05 16:55:38 -07007072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
7075 String iccId = getIccId(subId);
7076 if (iccId != null) {
7077 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7078 if (DBG_MERGE) {
7079 log("getLine1NumberForDisplay returning "
7080 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7081 }
7082 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7085 return null;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007088 }
Derek Tan7226c842014-07-02 17:42:23 -07007089 }
7090
7091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007092 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007095 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007096 return null;
7097 }
Derek Tan97ebb422014-09-05 16:55:38 -07007098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 final long identity = Binder.clearCallingIdentity();
7100 try {
7101 String iccId = getIccId(subId);
7102 if (iccId != null) {
7103 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7104 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7105 }
7106 return null;
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007109 }
Derek Tan7226c842014-07-02 17:42:23 -07007110 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007111
7112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007113 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7114 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007115 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7116 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007118 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007120 return null;
7121 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007122
Jordan Liub49b04b2019-05-06 14:45:15 -07007123 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7124 // the process, where TelephonyManager was instantiated.
7125 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007126 final long identity = Binder.clearCallingIdentity();
7127 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007128 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 final TelephonyManager tele = TelephonyManager.from(context);
7130 final SubscriptionManager sub = SubscriptionManager.from(context);
7131
7132 // Figure out what subscribers are currently active
7133 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134
Jordan Liub49b04b2019-05-06 14:45:15 -07007135 // Only consider subs which match the current subId
7136 // This logic can be simplified. See b/131189269 for progress.
7137 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007138 activeSubscriberIds.add(tele.getSubscriberId(subId));
7139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140
7141 // First pass, find a number override for an active subscriber
7142 String mergeNumber = null;
7143 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7144 for (String key : prefs.keySet()) {
7145 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7146 final String subscriberId = (String) prefs.get(key);
7147 if (activeSubscriberIds.contains(subscriberId)) {
7148 final String iccId = key.substring(
7149 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7150 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7151 mergeNumber = (String) prefs.get(numberKey);
7152 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007153 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 + " for active subscriber " + subscriberId);
7155 }
7156 if (!TextUtils.isEmpty(mergeNumber)) {
7157 break;
7158 }
7159 }
7160 }
7161 }
7162
7163 // Shortcut when no active merged subscribers
7164 if (TextUtils.isEmpty(mergeNumber)) {
7165 return null;
7166 }
7167
7168 // Second pass, find all subscribers under that line override
7169 final ArraySet<String> result = new ArraySet<>();
7170 for (String key : prefs.keySet()) {
7171 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7172 final String number = (String) prefs.get(key);
7173 if (mergeNumber.equals(number)) {
7174 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7175 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7176 final String subscriberId = (String) prefs.get(subscriberKey);
7177 if (!TextUtils.isEmpty(subscriberId)) {
7178 result.add(subscriberId);
7179 }
7180 }
7181 }
7182 }
7183
7184 final String[] resultArray = result.toArray(new String[result.size()]);
7185 Arrays.sort(resultArray);
7186 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007187 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7189 }
7190 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007191 } finally {
7192 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007193 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007194 }
7195
7196 @Override
zoey chen38003472019-12-13 17:16:31 +08007197 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7198 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007199
7200 final long identity = Binder.clearCallingIdentity();
7201 try {
7202 final TelephonyManager telephonyManager = mApp.getSystemService(
7203 TelephonyManager.class);
7204 String subscriberId = telephonyManager.getSubscriberId(subId);
7205 if (subscriberId == null) {
7206 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007207 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007208 + subId);
7209 }
7210 return null;
7211 }
7212
7213 final SubscriptionInfo info = SubscriptionController.getInstance()
7214 .getSubscriptionInfo(subId);
7215 final ParcelUuid groupUuid = info.getGroupUuid();
7216 // If it doesn't belong to any group, return just subscriberId of itself.
7217 if (groupUuid == null) {
7218 return new String[]{subscriberId};
7219 }
7220
7221 // Get all subscriberIds from the group.
7222 final List<String> mergedSubscriberIds = new ArrayList<>();
7223 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007224 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007225 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007226 for (SubscriptionInfo subInfo : groupInfos) {
7227 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7228 if (subscriberId != null) {
7229 mergedSubscriberIds.add(subscriberId);
7230 }
7231 }
7232
7233 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236
7237 }
7238 }
7239
7240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007241 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007242 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007243 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 final Phone phone = getPhone(subId);
7248 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007252 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007253
7254 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007255 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007256 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7257 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7259 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 final Phone phone = getPhone(subId);
7264 if (phone == null) {
7265 return false;
7266 }
7267 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7268 cdmaNonRoamingList);
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007271 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007272 }
7273
7274 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007275 @Deprecated
7276 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7277 enforceModifyPermission();
7278
7279 int returnValue = 0;
7280 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007281 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007282 if(result.exception == null) {
7283 if (result.result != null) {
7284 byte[] responseData = (byte[])(result.result);
7285 if(responseData.length > oemResp.length) {
7286 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7287 responseData.length + "bytes. Buffer Size is " +
7288 oemResp.length + "bytes.");
7289 }
7290 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7291 returnValue = responseData.length;
7292 }
7293 } else {
7294 CommandException ex = (CommandException) result.exception;
7295 returnValue = ex.getCommandError().ordinal();
7296 if(returnValue > 0) returnValue *= -1;
7297 }
7298 } catch (RuntimeException e) {
7299 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7300 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7301 if(returnValue > 0) returnValue *= -1;
7302 }
7303
7304 return returnValue;
7305 }
7306
7307 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007308 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007309 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007310 try {
7311 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007312 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007313 mApp, phone.getSubId(), "getRadioAccessFamily");
7314 } catch (SecurityException e) {
7315 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7316 throw e;
7317 }
chen xub97461a2018-10-26 14:17:57 -07007318 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007319 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007320 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
chen xub97461a2018-10-26 14:17:57 -07007324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007326 mApp, phone.getSubId(), "getRadioAccessFamily");
7327 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 } finally {
7329 Binder.restoreCallingIdentity(identity);
7330 }
chen xub97461a2018-10-26 14:17:57 -07007331 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007332 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007333
7334 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007335 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007336 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007337 try {
7338 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7339 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007340 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007341 }
7342 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007343 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007344 }
7345 RoleManager rm = mApp.getSystemService(RoleManager.class);
7346 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7347 if (!dialerRoleHolders.contains(callingPackage)) {
7348 throw new SecurityException("App must be the dialer role holder to"
7349 + " upload a call composer pic");
7350 }
7351
7352 Executors.newSingleThreadExecutor().execute(() -> {
7353 ByteArrayOutputStream output = new ByteArrayOutputStream(
7354 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7355 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7356 boolean readUntilEnd = false;
7357 int totalBytesRead = 0;
7358 byte[] buffer = new byte[16 * 1024];
7359 while (true) {
7360 int numRead;
7361 try {
7362 numRead = input.read(buffer);
7363 } catch (IOException e) {
7364 try {
7365 fd.checkError();
7366 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7367 null);
7368 } catch (IOException e1) {
7369 // This means that the other side closed explicitly with an error. If this
7370 // happens, log and ignore.
7371 loge("Remote end of call composer picture pipe closed: " + e1);
7372 }
7373 break;
7374 }
7375 if (numRead == -1) {
7376 readUntilEnd = true;
7377 break;
7378 }
7379 totalBytesRead += numRead;
7380 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7381 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7382 try {
7383 input.close();
7384 } catch (IOException e) {
7385 // ignore
7386 }
7387 break;
7388 }
7389 output.write(buffer, 0, numRead);
7390 }
7391 // Generally, the remote end will close the file descriptors. The only case where we
7392 // close is above, where the picture size is too big.
7393
7394 try {
7395 fd.checkError();
7396 } catch (IOException e) {
7397 loge("Remote end for call composer closed with an error: " + e);
7398 return;
7399 }
7400
Hall Liuaa4211e2021-01-20 15:43:39 -08007401 if (!readUntilEnd) {
7402 loge("Did not finish reading entire image; aborting");
7403 return;
7404 }
Hall Liu82694d52020-12-11 18:22:04 -08007405
Hall Liuaa4211e2021-01-20 15:43:39 -08007406 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7407 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7408 new CallComposerPictureTransfer.Factory() {},
7409 imageData,
7410 (result) -> {
7411 if (result.first != null) {
7412 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7413 Bundle outputResult = new Bundle();
7414 outputResult.putParcelable(
7415 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7416 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7417 outputResult);
7418 } else {
7419 callback.send(result.second, null);
7420 }
7421 }
7422 );
Hall Liu82694d52020-12-11 18:22:04 -08007423 });
7424 }
7425
7426 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007427 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007429 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430
7431 final long identity = Binder.clearCallingIdentity();
7432 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 ImsManager.getInstance(defaultPhone.getContext(),
7434 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007438 }
7439
7440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7444 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007445 return false;
7446 }
Svet Ganovb320e182015-04-16 12:30:10 -07007447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 // Check the user preference and the system-level IMS setting. Even if the user has
7451 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7452 // In the long run, we may instead need to check if there exists a connection service
7453 // which can support video calling.
7454 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 return imsManager.isVtEnabledByPlatform()
7457 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7458 && imsManager.isVtEnabledByUser();
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007462 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007463
Andrew Leea1239f22015-03-02 17:44:07 -08007464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007465 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7466 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007468 mApp, subId, callingPackage, callingFeatureId,
7469 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 return false;
7471 }
7472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
7475 CarrierConfigManager configManager =
7476 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
Andrew Leea1239f22015-03-02 17:44:07 -08007482 }
7483
7484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 return false;
7489 }
7490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 CarrierConfigManager configManager =
7494 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007495 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Andrew Leea1239f22015-03-02 17:44:07 -08007500 }
7501
Andrew Lee9431b832015-03-09 18:46:45 -07007502 @Override
7503 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007504 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007505 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007506 }
7507
7508 @Override
7509 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 final long identity = Binder.clearCallingIdentity();
7511 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007512 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Lee9431b832015-03-09 18:46:45 -07007516 }
7517
Hall Liuf6668912018-10-31 17:05:23 -07007518 /**
7519 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7520 * support for the feature and device firmware support.
7521 *
7522 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7523 */
7524 @Override
7525 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 final Phone phone = getPhone(subscriptionId);
7528 if (phone == null) {
7529 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7530 return false;
7531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007533 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7535 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 return isCarrierSupported && isDeviceSupported;
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
Hall Liu98187582018-01-22 19:15:32 -08007541 }
7542
Hall Liuf6668912018-10-31 17:05:23 -07007543 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007544 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7545 * RTT setting, will return true if the device and carrier both support RTT.
7546 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007547 */
7548 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 final long identity = Binder.clearCallingIdentity();
7550 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007551 boolean isRttSupported = isRttSupported(subscriptionId);
7552 boolean isUserRttSettingOn = Settings.Secure.getInt(
7553 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7554 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7555 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7556 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007560 }
7561
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007562 @Deprecated
7563 @Override
7564 public String getDeviceId(String callingPackage) {
7565 return getDeviceIdWithFeature(callingPackage, null);
7566 }
7567
Sanket Padawe7310cc72015-01-14 09:53:20 -08007568 /**
7569 * Returns the unique device ID of phone, for example, the IMEI for
7570 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7571 *
7572 * <p>Requires Permission:
7573 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7574 */
7575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007577 try {
7578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7579 } catch (SecurityException se) {
7580 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7581 throw new SecurityException("Package " + callingPackage + " does not belong to "
7582 + Binder.getCallingUid());
7583 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007584 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007585 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007586 return null;
7587 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007588 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007589 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007590 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007591 return null;
7592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 return phone.getDeviceId();
7597 } finally {
7598 Binder.restoreCallingIdentity(identity);
7599 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007600 }
7601
Ping Sunc67b7c22016-03-02 19:16:45 +08007602 /**
7603 * {@hide}
7604 * Returns the IMS Registration Status on a particular subid
7605 *
7606 * @param subId
7607 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007608 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007609 Phone phone = getPhone(subId);
7610 if (phone != null) {
7611 return phone.isImsRegistered();
7612 } else {
7613 return false;
7614 }
7615 }
7616
Santos Cordon7a1885b2015-02-03 11:15:19 -08007617 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007618 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007619 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007622 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7623 }
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
7629 }
7630 }
7631
7632 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007633 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007634 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007635 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007636 mApp,
7637 subscriptionId,
7638 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007639 final long identity = Binder.clearCallingIdentity();
7640 try {
7641 Phone phone = getPhone(subscriptionId);
7642 if (phone == null) {
7643 return null;
7644 }
7645 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7646 } finally {
7647 Binder.restoreCallingIdentity(identity);
7648 }
7649 }
7650
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007651 /**
7652 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007653 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007654 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 Phone phone = getPhone(subId);
7658 if (phone != null) {
7659 return phone.isWifiCallingEnabled();
7660 } else {
7661 return false;
7662 }
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007665 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007666 }
7667
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007668 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007669 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007670 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 Phone phone = getPhone(subId);
7675 if (phone != null) {
7676 return phone.isVideoEnabled();
7677 } else {
7678 return false;
7679 }
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 }
7683 }
7684
7685 /**
7686 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7687 * defined in {@link ImsRegistrationImplBase}.
7688 */
7689 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 Phone phone = getPhone(subId);
7693 if (phone != null) {
7694 return phone.getImsRegistrationTech();
7695 } else {
7696 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7697 }
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007700 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007701 }
7702
Stuart Scott8eef64f2015-04-08 15:13:54 -07007703 @Override
7704 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007705 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007706 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7707 return;
7708 }
Kai Shif70f46f2021-03-03 13:59:46 -08007709 Phone defaultPhone = getDefaultPhone();
7710 if (defaultPhone != null) {
7711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7712 mApp, getDefaultPhone().getSubId(), "factoryReset");
7713 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007714 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007715
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007717 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7718 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007719 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007720 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007721 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007722 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007723 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007725 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007726 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007727 // There has been issues when Sms raw table somehow stores orphan
7728 // fragments. They lead to garbled message when new fragments come
7729 // in and combined with those stale ones. In case this happens again,
7730 // user can reset all network settings which will clean up this table.
7731 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007732 // Clean up IMS settings as well here.
7733 int slotId = getSlotIndex(subId);
7734 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7735 ImsManager.getInstance(mApp, slotId).factoryReset();
7736 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007737
Kai Shif70f46f2021-03-03 13:59:46 -08007738 if (defaultPhone == null) {
7739 return;
7740 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007741 // Erase modem config if erase modem on network setting is enabled.
7742 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7743 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7744 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007745 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007746 }
Kai Shif70f46f2021-03-03 13:59:46 -08007747
7748 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007749 } finally {
7750 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007751 }
7752 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007753
SongFerngWangfd89b102021-05-27 22:44:54 +08007754 @VisibleForTesting
7755 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7756 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7757 return;
7758 }
7759 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7760 RILConstants.PREFERRED_NETWORK_MODE);
7761 SubscriptionManager.setSubscriptionProperty(subId,
7762 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7763 "user=" + defaultNetworkType);
7764 phone.loadAllowedNetworksFromSubscriptionDatabase();
7765 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7766 defaultNetworkType, null);
7767 }
7768
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007769 private void cleanUpSmsRawTable(Context context) {
7770 ContentResolver resolver = context.getContentResolver();
7771 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7772 resolver.delete(uri, null, null);
7773 }
7774
Narayan Kamath1c496c22015-04-16 14:40:19 +01007775 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007776 public String getSimLocaleForSubscriber(int subId) {
7777 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7778 final Phone phone = getPhone(subId);
7779 if (phone == null) {
7780 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007781 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 final long identity = Binder.clearCallingIdentity();
7784 try {
chen xu5d3637b2019-01-21 23:31:38 -08007785 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007786 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007787 if (info == null) {
7788 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7789 return null;
7790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 // Try and fetch the locale from the carrier properties or from the SIM language
7792 // preferences (EF-PL and EF-LI)...
7793 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007795 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7796 if (localeFromDefaultSim != null) {
7797 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7798 if (DBG) log("Using locale from subId: " + subId + " locale: "
7799 + localeFromDefaultSim);
7800 return localeFromDefaultSim.toLanguageTag();
7801 } else {
7802 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 }
7804 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 // The SIM language preferences only store a language (e.g. fr = French), not an
7807 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7808 // the SIM and carrier preferences does not include a country we add the country
7809 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007810 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007812 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 return mccLocale.toLanguageTag();
7814 }
7815
7816 if (DBG) log("No locale found - returning null");
7817 return null;
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007821 }
7822
7823 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007824 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007825 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007826 }
7827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 /**
7829 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7830 */
7831 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007832 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007833 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007834 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007835
Chenjie Yu1ba97252018-01-11 18:16:20 -08007836 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007837 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007839 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007840 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7841 * representing the state of the modem.
7842 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007843 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7844 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007845 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007846 */
7847 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007848 public void requestModemActivityInfo(ResultReceiver result) {
7849 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851
7852 final long identity = Binder.clearCallingIdentity();
7853 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007854 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007855 } finally {
7856 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007857 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007858 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007859
Siddharth Rayb8114062018-06-17 15:02:38 -07007860 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7861 // less than total activity duration.
7862 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7863 if (info == null) {
7864 return false;
7865 }
7866 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007867 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7868 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7869
Siddharth Rayb8114062018-06-17 15:02:38 -07007870 return (info.isValid()
7871 && (info.getSleepTimeMillis() <= activityDurationMs)
7872 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007873 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007874 && (totalTxTimeMs <= activityDurationMs));
7875 }
7876
Jack Yu85bd38a2015-11-09 11:34:32 -08007877 /**
7878 * {@hide}
7879 * Returns the service state information on specified subscription.
7880 */
7881 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007882 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7883 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007885 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007886 return null;
7887 }
7888
Hall Liuf19c44f2018-11-27 14:38:17 -08007889 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7890 LocationAccessPolicy.checkLocationPermission(mApp,
7891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7892 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007893 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007894 .setCallingPid(Binder.getCallingPid())
7895 .setCallingUid(Binder.getCallingUid())
7896 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007897 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007899 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7900 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007901 .build());
7902
7903 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7904 LocationAccessPolicy.checkLocationPermission(mApp,
7905 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7906 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007907 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007908 .setCallingPid(Binder.getCallingPid())
7909 .setCallingUid(Binder.getCallingUid())
7910 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007911 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007912 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007913 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7914 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007915 .build());
7916 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7917 boolean hasFinePermission =
7918 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7919 boolean hasCoarsePermission =
7920 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7921
Jack Yu479f40e2020-10-27 21:29:25 -07007922 final Phone phone = getPhone(subId);
7923 if (phone == null) {
7924 return null;
7925 }
7926
Jordan Liu0f2bc442020-11-18 16:47:37 -08007927 final long identity = Binder.clearCallingIdentity();
7928
Jack Yu479f40e2020-10-27 21:29:25 -07007929 boolean isCallingPackageDataService = phone.getDataServicePackages()
7930 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007932 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7933 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7934 Rlog.d(LOG_TAG,
7935 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7936 return null;
7937 }
7938
Hall Liuf19c44f2018-11-27 14:38:17 -08007939 ServiceState ss = phone.getServiceState();
7940
7941 // Scrub out the location info in ServiceState depending on what level of access
7942 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007943 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007944 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7945 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 } finally {
7947 Binder.restoreCallingIdentity(identity);
7948 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007949 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007950
7951 /**
7952 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7953 *
7954 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7955 * voicemail ringtone.
7956 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7957 * PhoneAccount.
7958 */
7959 @Override
7960 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 final long identity = Binder.clearCallingIdentity();
7962 try {
7963 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7964 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007965 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
7971 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007972 }
7973
7974 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007975 * Sets the per-account voicemail ringtone.
7976 *
7977 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7978 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7979 *
7980 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7981 * voicemail ringtone.
7982 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7983 * PhoneAccount.
7984 */
7985 @Override
7986 public void setVoicemailRingtoneUri(String callingPackage,
7987 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007990 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7991 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7993 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7994 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8000 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 }
8003 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
8008
8009 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008010 * Returns whether vibration is set for voicemail notification in Phone settings.
8011 *
8012 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8013 * voicemail vibration setting.
8014 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8015 */
8016 @Override
8017 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8021 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008022 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
8028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008029 }
8030
Youhan Wange64578a2016-05-02 15:32:42 -07008031 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 * Sets the per-account voicemail vibration.
8033 *
8034 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8035 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8036 *
8037 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8038 * voicemail vibration setting.
8039 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8040 * specific PhoneAccount.
8041 */
8042 @Override
8043 public void setVoicemailVibrationEnabled(String callingPackage,
8044 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008047 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8048 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8050 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8051 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 }
8053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8057 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008058 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 }
8060 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8061 } finally {
8062 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
8066 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008067 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8068 *
8069 * @throws SecurityException if the caller does not have the required permission
8070 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008071 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008074 }
8075
8076 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008077 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8078 * permission.
8079 *
8080 * @throws SecurityException if the caller does not have the required permission
8081 */
8082 private void enforceSendSmsPermission() {
8083 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8084 }
8085
8086 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008087 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008088 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008089 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008090 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008091 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008095 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 if (componentName == null) {
8097 throw new SecurityException(
8098 "Caller not current active visual voicemail package[null]");
8099 }
8100 String vvmPackage = componentName.getPackageName();
8101 if (!callingPackage.equals(vvmPackage)) {
8102 throw new SecurityException("Caller not current active visual voicemail package["
8103 + vvmPackage + "]");
8104 }
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008107 }
8108 }
8109
8110 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008111 * Return the application ID for the app type.
8112 *
8113 * @param subId the subscription ID that this request applies to.
8114 * @param appType the uicc app type.
8115 * @return Application ID for specificied app type, or null if no uicc.
8116 */
8117 @Override
8118 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008119 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008120 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121
8122 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008123 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 if (phone == null) {
8125 return null;
8126 }
8127 String aid = null;
8128 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008129 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 .getApplicationByType(appType).getAid();
8131 } catch (Exception e) {
8132 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8133 }
8134 return aid;
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008137 }
Youhan Wange64578a2016-05-02 15:32:42 -07008138 }
8139
Youhan Wang4001d252016-05-11 10:29:41 -07008140 /**
8141 * Return the Electronic Serial Number.
8142 *
8143 * @param subId the subscription ID that this request applies to.
8144 * @return ESN or null if error.
8145 */
8146 @Override
8147 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008148 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008149 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150
8151 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008152 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 if (phone == null) {
8154 return null;
8155 }
8156 String esn = null;
8157 try {
8158 esn = phone.getEsn();
8159 } catch (Exception e) {
8160 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8161 }
8162 return esn;
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008165 }
Youhan Wang4001d252016-05-11 10:29:41 -07008166 }
8167
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008168 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008169 * Return the Preferred Roaming List Version.
8170 *
8171 * @param subId the subscription ID that this request applies to.
8172 * @return PRLVersion or null if error.
8173 */
8174 @Override
8175 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008176 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178
8179 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 if (phone == null) {
8182 return null;
8183 }
8184 String cdmaPrlVersion = null;
8185 try {
8186 cdmaPrlVersion = phone.getCdmaPrlVersion();
8187 } catch (Exception e) {
8188 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8189 }
8190 return cdmaPrlVersion;
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008193 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008194 }
8195
8196 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008197 * Get snapshot of Telephony histograms
8198 * @return List of Telephony histograms
8199 * @hide
8200 */
8201 @Override
8202 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8204 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205
8206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 return RIL.getTelephonyRILTimingHistograms();
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008212 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213
8214 /**
8215 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008216 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8217 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008218 * Require system privileges. In the future we may add this to carrier APIs.
8219 *
Michele Berionne482f8202018-11-27 18:57:59 -08008220 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008221 */
8222 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008223 @TelephonyManager.SetCarrierRestrictionResult
8224 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008227
Michele Berionne482f8202018-11-27 18:57:59 -08008228 if (carrierRestrictionRules == null) {
8229 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008230 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 final long identity = Binder.clearCallingIdentity();
8233 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008234 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008235 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008239 }
8240
8241 /**
8242 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008243 * Get the allowed carrier list and the excluded carrier list, including the priority between
8244 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 * Require system privileges. In the future we may add this to carrier APIs.
8246 *
Michele Berionne482f8202018-11-27 18:57:59 -08008247 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 */
8249 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008250 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008251 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008252 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253
8254 final long identity = Binder.clearCallingIdentity();
8255 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008256 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8257 if (response instanceof CarrierRestrictionRules) {
8258 return (CarrierRestrictionRules) response;
8259 }
8260 // Response is an Exception of some kind,
8261 // which is signalled to the user as a NULL retval
8262 return null;
8263 } catch (Exception e) {
8264 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8265 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008269 }
8270
fionaxu59545b42016-05-25 15:53:37 -07008271 /**
fionaxu59545b42016-05-25 15:53:37 -07008272 * Action set from carrier signalling broadcast receivers to enable/disable radio
8273 * @param subId the subscription ID that this action applies to.
8274 * @param enabled control enable or disable radio.
8275 * {@hide}
8276 */
8277 @Override
8278 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8279 enforceModifyPermission();
8280 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281
8282 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008283 if (phone == null) {
8284 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8285 return;
8286 }
8287 try {
8288 phone.carrierActionSetRadioEnabled(enabled);
8289 } catch (Exception e) {
8290 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 } finally {
8292 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008293 }
8294 }
8295
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008296 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008297 * Enable or disable Voice over NR (VoNR)
8298 * @param subId the subscription ID that this action applies to.
8299 * @param enabled enable or disable VoNR.
8300 * @return operation result.
8301 */
8302 @Override
8303 public int setVoNrEnabled(int subId, boolean enabled) {
8304 enforceModifyPermission();
8305 final Phone phone = getPhone(subId);
8306
8307 final long identity = Binder.clearCallingIdentity();
8308 if (phone == null) {
8309 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8310 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8311 }
8312
8313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8314 try {
8315 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8316 workSource);
8317 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008318
8319 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8320 if (DBG) {
8321 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8322 }
8323 SubscriptionManager.setSubscriptionProperty(
8324 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8325 (enabled ? "1" : "0"));
8326 }
8327
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008328 return result;
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
8332 }
8333
8334 /**
8335 * Is voice over NR enabled
8336 * @return true if VoNR is enabled else false
8337 */
8338 @Override
8339 public boolean isVoNrEnabled(int subId) {
8340 enforceReadPrivilegedPermission("isVoNrEnabled");
8341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8345 null, subId, workSource);
8346 if (DBG) log("isVoNrEnabled: " + isEnabled);
8347 return isEnabled;
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
8351 }
8352
8353 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008354 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8355 * network status based on which carrier apps could apply actions accordingly,
8356 * enable/disable default url handler for example.
8357 *
8358 * @param subId the subscription ID that this action applies to.
8359 * @param report control start/stop reporting the default network status.
8360 * {@hide}
8361 */
8362 @Override
8363 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8364 enforceModifyPermission();
8365 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366
8367 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008368 if (phone == null) {
8369 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8370 return;
8371 }
8372 try {
8373 phone.carrierActionReportDefaultNetworkStatus(report);
8374 } catch (Exception e) {
8375 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 } finally {
8377 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008378 }
8379 }
8380
8381 /**
fionaxud9622282017-07-17 17:51:30 -07008382 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8383 * @param subId the subscription ID that this action applies to.
8384 * {@hide}
8385 */
8386 @Override
8387 public void carrierActionResetAll(int subId) {
8388 enforceModifyPermission();
8389 final Phone phone = getPhone(subId);
8390 if (phone == null) {
8391 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8392 return;
8393 }
8394 try {
8395 phone.carrierActionResetAll();
8396 } catch (Exception e) {
8397 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8398 }
8399 }
8400
8401 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008402 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8403 * bug report is being generated.
8404 */
8405 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008406 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8408 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008409 writer.println("Permission Denial: can't dump Phone from pid="
8410 + Binder.getCallingPid()
8411 + ", uid=" + Binder.getCallingUid()
8412 + "without permission "
8413 + android.Manifest.permission.DUMP);
8414 return;
8415 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008416 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008417 }
Jack Yueb89b242016-06-22 13:27:47 -07008418
Brad Ebingerdac2f002018-04-03 15:17:52 -07008419 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008420 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8421 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8422 @NonNull String[] args) {
8423 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8424 this, in.getFileDescriptor(), out.getFileDescriptor(),
8425 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008426 }
8427
Jack Yueb89b242016-06-22 13:27:47 -07008428 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008430 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 * @param reason the reason the data enable change is taking place
8432 * @param enabled True if enabling the data, otherwise disabling.
8433 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008434 */
8435 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008436 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008437 boolean enabled) {
8438 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8439 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8440 try {
8441 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008442 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008443 } catch (SecurityException se) {
8444 enforceModifyPermission();
8445 }
8446 } else {
8447 enforceModifyPermission();
8448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 Phone phone = getPhone(subId);
8453 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008454 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8455 phone.carrierActionSetMeteredApnsEnabled(enabled);
8456 } else {
8457 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 }
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008462 }
8463 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008464
8465 /**
8466 * Get Client request stats
8467 * @return List of Client Request Stats
8468 * @hide
8469 */
8470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008471 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8472 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008474 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008475 return null;
8476 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 if (phone != null) {
8482 return phone.getClientRequestStats();
8483 }
8484
8485 return null;
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
8488 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008489 }
8490
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008491 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008492 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008493 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008494 }
Jack Yueb4124c2017-02-16 15:32:43 -08008495
8496 /**
Grace Chen70990072017-03-24 17:21:30 -07008497 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008498 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008499 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008500 * @param state State of SIM (power down, power up, pass through)
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008504 *
8505 **/
8506 @Override
Grace Chen70990072017-03-24 17:21:30 -07008507 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008508 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008509 Phone phone = PhoneFactory.getPhone(slotIndex);
8510
vagdeviaf9a5b92018-08-15 16:01:53 -07008511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008516 phone.setSimPowerState(state, null, workSource);
8517 }
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
8523 /**
8524 * Set SIM card power state.
8525 *
8526 * @param slotIndex SIM slot id.
8527 * @param state State of SIM (power down, power up, pass through)
8528 * @param callback callback to trigger after success or failure
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8532 *
8533 **/
8534 @Override
8535 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8536 IIntegerConsumer callback) {
8537 enforceModifyPermission();
8538 Phone phone = PhoneFactory.getPhone(slotIndex);
8539
8540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8541
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 if (phone != null) {
8545 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8546 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 }
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008550 }
8551 }
Shuo Qiandd210312017-04-12 22:11:33 +00008552
Tyler Gunn65d45c22017-06-05 11:22:26 -07008553 private boolean isUssdApiAllowed(int subId) {
8554 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008555 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008556 if (configManager == null) {
8557 return false;
8558 }
8559 PersistableBundle pb = configManager.getConfigForSubId(subId);
8560 if (pb == null) {
8561 return false;
8562 }
8563 return pb.getBoolean(
8564 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8565 }
8566
Shuo Qiandd210312017-04-12 22:11:33 +00008567 /**
8568 * Check if phone is in emergency callback mode
8569 * @return true if phone is in emergency callback mode
8570 * @param subId sub id
8571 */
goneil9c5f4872017-12-05 14:07:56 -08008572 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008573 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008574 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 if (phone != null) {
8580 return phone.isInEcm();
8581 } else {
8582 return false;
8583 }
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008586 }
8587 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008588
8589 /**
8590 * Get the current signal strength information for the given subscription.
8591 * Because this information is not updated when the device is in a low power state
8592 * it should not be relied-upon to be current.
8593 * @param subId Subscription index
8594 * @return the most recent cached signal strength info from the modem
8595 */
8596 @Override
8597 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 Phone p = getPhone(subId);
8601 if (p == null) {
8602 return null;
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 return p.getSignalStrength();
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008609 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008610
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008612 * Get the current modem radio state for the given slot.
8613 * @param slotIndex slot index.
8614 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008616 * @return the current radio power state from the modem
8617 */
8618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008619 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008620 Phone phone = PhoneFactory.getPhone(slotIndex);
8621 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8623 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008624 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8625 }
8626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 return phone.getRadioPowerState();
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8635 }
8636
8637 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8639 *
8640 * <p>Requires one of the following permissions:
8641 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8642 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8643 * privileges.
8644 *
8645 * @param subId subscription id
8646 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8647 * {@code false}.
8648 */
8649 @Override
8650 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008651 try {
8652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8653 null);
8654 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008655 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008656 mApp, subId, "isDataRoamingEnabled");
8657 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008658
Pengquan Menga1bb6272018-09-06 09:59:22 -07008659 boolean isEnabled = false;
8660 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008661 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008662 Phone phone = getPhone(subId);
8663 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008664 } finally {
8665 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008668 }
8669
8670
8671 /**
8672 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8673 *
8674 * <p> Requires permission:
8675 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8676 * privileges.
8677 *
8678 * @param subId subscription id
8679 * @param isEnabled {@code true} means enable, {@code false} means disable.
8680 */
8681 @Override
8682 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8684 mApp, subId, "setDataRoamingEnabled");
8685
Pengquan Menga1bb6272018-09-06 09:59:22 -07008686 final long identity = Binder.clearCallingIdentity();
8687 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 Phone phone = getPhone(subId);
8689 if (phone != null) {
8690 phone.setDataRoamingEnabled(isEnabled);
8691 }
8692 } finally {
8693 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008694 }
8695 }
8696
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008697 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008698 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008699 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008700 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008701 mApp, subId, "isManualNetworkSelectionAllowed");
8702
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008703 boolean isAllowed = true;
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008706 Phone phone = getPhone(subId);
8707 if (phone != null) {
8708 isAllowed = phone.isCspPlmnEnabled();
8709 }
8710 } finally {
8711 Binder.restoreCallingIdentity(identity);
8712 }
8713 return isAllowed;
8714 }
8715
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008716 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8717 UiccProfile profile = port.getUiccProfile();
8718 if (profile == null ||
8719 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8720 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8721 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008722 }
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 Reddyeb809e32021-11-19 03:07:54 +00008766 if (card == null) {
8767 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008768 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008769 continue;
8770 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008771 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8772 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008773 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008774 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008776 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8777 for (UiccPortInfo portInfo : portInfos) {
8778 UiccPort port = uiccController.getUiccPortForSlot(
8779 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8780 if (port == null) {
8781 // assume no access if port is null
8782 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8783 continue;
8784 }
8785 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8786 uiccPortInfos.add(portInfo);
8787 } else {
8788 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8789 }
8790 }
8791 filteredInfos.add(new UiccCardInfo(
8792 cardInfo.isEuicc(),
8793 cardInfo.getCardId(),
8794 null,
8795 cardInfo.getPhysicalSlotIndex(),
8796 cardInfo.isRemovable(),
8797 cardInfo.isMultipleEnabledProfilesSupported(),
8798 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008799 }
8800 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805
sandeepjsb6c87872021-09-27 15:34:44 +00008806 /**
8807 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8808 * generally private and require carrier privileges to view.
8809 *
8810 * @hide
8811 */
8812 @NonNull
8813 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8814 List<UiccPortInfo> portinfo = new ArrayList<>();
8815 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8816 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8817 }
8818 return new UiccCardInfo(
8819 cardInfo.isEuicc(),
8820 cardInfo.getCardId(),
8821 null,
8822 cardInfo.getPhysicalSlotIndex(),
8823 cardInfo.isRemovable(),
8824 cardInfo.isMultipleEnabledProfilesSupported(),
8825 portinfo
8826 );
8827 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008828
sandeepjsb6c87872021-09-27 15:34:44 +00008829 /**
8830 * @hide
8831 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8832 * These values are generally private and require carrier privileges to view.
8833 */
8834 @NonNull
8835 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8836 return new UiccPortInfo(
8837 UiccPortInfo.ICCID_REDACTED,
8838 portInfo.getPortIndex(),
8839 portInfo.getLogicalSlotIndex(),
8840 portInfo.isActive()
8841 );
8842 }
8843 @Override
8844 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008845 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008846 mApp.getSystemService(AppOpsManager.class)
8847 .checkPackage(Binder.getCallingUid(), callingPackage);
8848
8849 boolean hasReadPermission = false;
8850 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008851
8852 try {
8853 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8854 hasReadPermission = true;
8855 } catch (SecurityException e) {
8856 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8857 // has carrier privileges on an active UICC
8858 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8860 hasReadPermission = true;
8861 }
8862 }
8863
8864 // checking compatibility, if calling app's target SDK is T and beyond.
8865 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8866 Binder.getCallingUid())) {
8867 isLogicalSlotAccessRestricted = true;
8868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 final long identity = Binder.clearCallingIdentity();
8870 try {
8871 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8872 if (slots == null) {
8873 Rlog.i(LOG_TAG, "slots is null.");
8874 return null;
8875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8877 for (int i = 0; i < slots.length; i++) {
8878 UiccSlot slot = slots[i];
8879 if (slot == null) {
8880 continue;
8881 }
8882
Jordan Liu7be7e652019-05-06 18:55:02 +00008883 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 UiccCard card = slot.getUiccCard();
8885 if (card != null) {
8886 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008887 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008888 cardId = slot.getEid();
8889 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008890 // If cardId is null, use iccId of default port as cardId. Check if has
8891 // read permission otherwise set to null.(card is null which means no
8892 // carrier permission)
8893 cardId = hasReadPermission ? slot.getIccId(
8894 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 }
8897
Jordan Liu857451f2019-05-09 16:35:35 -07008898 if (cardId != null) {
8899 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8900 // if cardId is an EID, it's all digits so this is fine
8901 cardId = IccUtils.stripTrailingFs(cardId);
8902 }
8903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 int cardState = 0;
8905 switch (slot.getCardState()) {
8906 case CARDSTATE_ABSENT:
8907 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8908 break;
8909 case CARDSTATE_PRESENT:
8910 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8911 break;
8912 case CARDSTATE_ERROR:
8913 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8914 break;
8915 case CARDSTATE_RESTRICTED:
8916 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8917 break;
8918 default:
8919 break;
8920
8921 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008922 List<UiccPortInfo> portInfos = new ArrayList<>();
8923 int[] portIndexes = slot.getPortList();
8924 for (int portIdx : portIndexes) {
8925 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8926 callingPackage, hasReadPermission));
8927 if (slot.isPortActive(portIdx)) {
8928 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8929 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8930 port.getPhoneId(), true));
8931 } else {
8932 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8933 }
8934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 slot.isEuicc(),
8937 cardId,
8938 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008939 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008940 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008941 //setting the value after compatibility check
8942 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 }
8944 return infos;
8945 } finally {
8946 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008947 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008948 }
8949
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008950 /* Returns null if doesn't have read permission or carrier privilege access. */
8951 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8952 boolean hasReadPermission) {
8953 String iccId = slot.getIccId(portIndex);
8954 if (hasReadPermission) { // if has read permission
8955 return iccId;
8956 } else {
8957 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8958 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8959 // if no read permission, checking carrier privilege access
8960 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8961 return iccId;
8962 }
8963 }
8964 }
8965 // No read permission or carrier privilege access.
8966 return UiccPortInfo.ICCID_REDACTED;
8967 }
8968
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008969 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008970 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008971 public boolean switchSlots(int[] physicalSlots) {
8972 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008976 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8977 for (int i = 0; i < physicalSlots.length; i++) {
8978 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8979 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8980 physicalSlots[i], i));
8981 }
8982 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008986 }
Jack Yu4c988042018-02-27 15:30:01 -08008987
8988 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008989 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8990 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8991 enforceModifyPermission();
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008995 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009002 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009003 final long identity = Binder.clearCallingIdentity();
9004 try {
9005 return UiccController.getInstance().getCardIdForDefaultEuicc();
9006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
9009 }
9010
Pengquan Meng85728fb2018-03-12 16:31:21 -07009011 /**
goneil47ffb6e2018-04-06 15:40:58 -07009012 * A test API to reload the UICC profile.
9013 *
9014 * <p>Requires that the calling app has permission
9015 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9016 * @hide
9017 */
9018 @Override
9019 public void refreshUiccProfile(int subId) {
9020 enforceModifyPermission();
9021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 Phone phone = getPhone(subId);
9025 if (phone == null) {
9026 return;
9027 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009028 UiccPort uiccPort = phone.getUiccPort();
9029 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009030 return;
9031 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009032 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009033 if (uiccProfile == null) {
9034 return;
9035 }
9036 uiccProfile.refresh();
9037 } finally {
9038 Binder.restoreCallingIdentity(identity);
9039 }
9040 }
9041
9042 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009043 * Returns false if the mobile data is disabled by default, otherwise return true.
9044 */
9045 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009046 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009047 }
9048
9049 /**
9050 * Returns true if the data roaming is enabled by default, i.e the system property
9051 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9052 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9053 */
9054 private boolean getDefaultDataRoamingEnabled(int subId) {
9055 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009056 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009057 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009058 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9059 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9060 return isDataRoamingEnabled;
9061 }
9062
9063 /**
9064 * Returns the default network type for the given {@code subId}, if the default network type is
9065 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9066 */
9067 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009068 List<Integer> list = TelephonyProperties.default_network();
9069 int phoneId = mSubscriptionController.getPhoneId(subId);
9070 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9071 return list.get(phoneId);
9072 }
9073 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009074 }
fionaxua13278b2018-03-21 00:08:13 -07009075
9076 @Override
9077 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009078 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080
9081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 final Phone phone = getPhone(subId);
9084 if (phone == null) {
9085 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9086 return;
9087 }
chen xueaba88a2019-03-15 13:15:10 -07009088 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9089 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009090 if (carrierPrivilegeRules == null) {
9091 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9092 } else {
9093 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009095 } finally {
9096 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009097 }
fionaxua13278b2018-03-21 00:08:13 -07009098 }
9099
9100 @Override
9101 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009102 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 final Phone phone = getPhone(subId);
9107 if (phone == null) {
9108 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9109 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9110 }
9111 return phone.getCarrierIdListVersion();
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009114 }
fionaxua13278b2018-03-21 00:08:13 -07009115 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009116
9117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009118 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9119 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009121 mApp, subId, callingPackage, callingFeatureId,
9122 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009123 return -1;
9124 }
9125
9126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
9131 }
9132 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133
9134 @Override
9135 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009136 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009137 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 mApp, subId, "getCdmaRoamingMode");
9139
9140 final long identity = Binder.clearCallingIdentity();
9141 try {
9142 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
9147
9148 @Override
9149 public boolean setCdmaRoamingMode(int subId, int mode) {
9150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9151 mApp, subId, "setCdmaRoamingMode");
9152
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
9159 }
9160
9161 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009162 public int getCdmaSubscriptionMode(int subId) {
9163 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009164 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009165 mApp, subId, "getCdmaSubscriptionMode");
9166
9167 final long identity = Binder.clearCallingIdentity();
9168 try {
9169 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009176 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9178 mApp, subId, "setCdmaSubscriptionMode");
9179
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009187
sqianc5eccab2018-10-19 18:46:41 -07009188 @Override
sqian8c685422019-02-22 15:55:18 -08009189 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009190 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009192 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9193 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009194 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9195 }
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
sqian854d44b2018-12-12 16:48:18 -08009198 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9199 for (Phone phone: PhoneFactory.getPhones()) {
9200 if (phone.getEmergencyNumberTracker() != null
9201 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9202 emergencyNumberListInternal.put(
9203 phone.getSubId(),
9204 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9205 }
sqian11b7a0e2018-12-05 18:48:28 -08009206 }
sqian854d44b2018-12-12 16:48:18 -08009207 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009208 } finally {
9209 Binder.restoreCallingIdentity(identity);
9210 }
sqianc5eccab2018-10-19 18:46:41 -07009211 }
9212
9213 @Override
sqian8c685422019-02-22 15:55:18 -08009214 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009215 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009216 if (!exactMatch) {
9217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009219 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009220 }
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
sqian854d44b2018-12-12 16:48:18 -08009223 for (Phone phone: PhoneFactory.getPhones()) {
9224 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009225 && phone.getEmergencyNumberTracker()
9226 .isEmergencyNumber(number, exactMatch)) {
9227 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009228 }
sqian11b7a0e2018-12-05 18:48:28 -08009229 }
9230 return false;
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
sqianf4ca7ed2019-01-15 18:32:07 -08009236 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009237 * Start emergency callback mode for GsmCdmaPhone for testing.
9238 */
9239 @Override
9240 public void startEmergencyCallbackMode() {
9241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9242 "startEmergencyCallbackMode");
9243 enforceModifyPermission();
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 for (Phone phone : PhoneFactory.getPhones()) {
9247 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9248 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9249 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9250 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9251 gsmCdmaPhone.obtainMessage(
9252 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9253 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9254 }
9255 }
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
9261 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009262 * Update emergency number list for test mode.
9263 */
9264 @Override
9265 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9267 "updateEmergencyNumberListTestMode");
9268
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
9271 for (Phone phone: PhoneFactory.getPhones()) {
9272 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9273 if (tracker != null) {
9274 tracker.executeEmergencyNumberTestModeCommand(action, num);
9275 }
9276 }
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
9282 /**
9283 * Get the full emergency number list for test mode.
9284 */
9285 @Override
9286 public List<String> getEmergencyNumberListTestMode() {
9287 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9288 "getEmergencyNumberListTestMode");
9289
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 Set<String> emergencyNumbers = new HashSet<>();
9293 for (Phone phone: PhoneFactory.getPhones()) {
9294 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9295 if (tracker != null) {
9296 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9297 emergencyNumbers.add(num.getNumber());
9298 }
9299 }
9300 }
9301 return new ArrayList<>(emergencyNumbers);
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
chen xud6b45bd2018-10-30 22:27:10 -07009307 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009308 public int getEmergencyNumberDbVersion(int subId) {
9309 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 final Phone phone = getPhone(subId);
9314 if (phone == null) {
9315 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9316 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9317 }
9318 return phone.getEmergencyNumberDbVersion();
9319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 }
9323
9324 @Override
9325 public void notifyOtaEmergencyNumberDbInstalled() {
9326 enforceModifyPermission();
9327
9328 final long identity = Binder.clearCallingIdentity();
9329 try {
9330 for (Phone phone: PhoneFactory.getPhones()) {
9331 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9332 if (tracker != null) {
9333 tracker.updateOtaEmergencyNumberDatabase();
9334 }
9335 }
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 }
9340
9341 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009342 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009343 enforceActiveEmergencySessionPermission();
9344
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
9347 for (Phone phone: PhoneFactory.getPhones()) {
9348 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9349 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009350 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9351 }
9352 }
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
9358 @Override
9359 public void resetOtaEmergencyNumberDbFilePath() {
9360 enforceActiveEmergencySessionPermission();
9361
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
9364 for (Phone phone: PhoneFactory.getPhones()) {
9365 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9366 if (tracker != null) {
9367 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009368 }
9369 }
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009376 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9377 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9378 Phone phone = getPhone(subId);
9379 if (phone == null) {
9380 return null;
9381 }
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
9384 UiccProfile profile = UiccController.getInstance()
9385 .getUiccProfileForPhone(phone.getPhoneId());
9386 if (profile != null) {
9387 return profile.getCertsFromCarrierPrivilegeAccessRules();
9388 }
9389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
9392 return null;
9393 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009394
9395 /**
9396 * Enable or disable a modem stack.
9397 */
9398 @Override
9399 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9400 enforceModifyPermission();
9401
9402 final long identity = Binder.clearCallingIdentity();
9403 try {
9404 Phone phone = PhoneFactory.getPhone(slotIndex);
9405 if (phone == null) {
9406 return false;
9407 } else {
9408 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9409 }
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
9413 }
Michelecea4cf22018-12-21 15:00:11 -08009414
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009415 /**
9416 * Whether a modem stack is enabled or not.
9417 */
9418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009419 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9420 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009421 Phone phone = PhoneFactory.getPhone(slotIndex);
9422 if (phone == null) return false;
9423
9424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009425 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9426 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009427 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9428 }
9429
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009432 try {
9433 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9434 } catch (NoSuchElementException ex) {
9435 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9436 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
Michelecea4cf22018-12-21 15:00:11 -08009442 @Override
Michele0ea7d782019-03-19 14:58:42 -07009443 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009444 enforceModifyPermission();
9445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
9448 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009449 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009450 .commit();
9451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 @Override
Michele0ea7d782019-03-19 14:58:42 -07009457 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009458 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009460 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9461 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009462 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009463 }
Michelecea4cf22018-12-21 15:00:11 -08009464
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
Michele0ea7d782019-03-19 14:58:42 -07009467 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009472
Michele0ea7d782019-03-19 14:58:42 -07009473 @TelephonyManager.IsMultiSimSupportedResult
9474 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009475 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9476 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9477 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009478 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9479 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009480 }
9481 // Check if the hardware supports multisim functionality. If usage of multisim is not
9482 // supported by the modem, indicate that it is restricted.
9483 PhoneCapability staticCapability =
9484 mPhoneConfigurationManager.getStaticPhoneCapability();
9485 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009486 loge("isMultiSimSupportedInternal: no static configuration available");
9487 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009488 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009489 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009490 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009492 }
9493 // Check if support of multiple SIMs is restricted by carrier
9494 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009495 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009496 }
9497
Michele0ea7d782019-03-19 14:58:42 -07009498 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009499 }
9500
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009501 /**
9502 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009503 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9504 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9505 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009506 * @param numOfSims number of active sims we want to switch to
9507 */
9508 @Override
9509 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009510 if (numOfSims == 1) {
9511 enforceModifyPermission();
9512 } else {
9513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9514 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9515 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009516 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009517
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009518 try {
Michele30b57b22019-03-01 12:01:14 -08009519 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009520 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009521 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9522 return;
9523 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009524 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
9527 }
9528 }
9529
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009530 @Override
9531 public boolean isApplicationOnUicc(int subId, int appType) {
9532 enforceReadPrivilegedPermission("isApplicationOnUicc");
9533 Phone phone = getPhone(subId);
9534 if (phone == null) {
9535 return false;
9536 }
9537 final long identity = Binder.clearCallingIdentity();
9538 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009539 UiccPort uiccPort = phone.getUiccPort();
9540 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009541 return false;
9542 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009543 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009544 if (uiccProfile == null) {
9545 return false;
9546 }
9547 if (TelephonyManager.APPTYPE_SIM <= appType
9548 && appType <= TelephonyManager.APPTYPE_ISIM) {
9549 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9550 }
9551 return false;
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 }
9556
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009557 /**
chen xub4baa772019-04-03 10:23:41 -07009558 * Get whether making changes to modem configurations will trigger reboot.
9559 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009560 */
9561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009562 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9563 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009565 mApp, subId, callingPackage, callingFeatureId,
9566 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009567 return false;
9568 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
9576
Nathan Harold29f5f052019-02-15 13:41:57 -08009577 private void updateModemStateMetrics() {
9578 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9579 // TODO: check the state for each modem if the api is ready.
9580 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9581 }
9582
Pengquan Meng3889a572019-01-23 11:16:29 -08009583 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009584 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009585 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009586 // Verify that the callingPackage belongs to the calling UID
9587 mApp.getSystemService(AppOpsManager.class)
9588 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009589 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009590 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009591 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009592 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9593 if (slotInfos != null) {
9594 for (int i = 0; i < slotInfos.length; i++) {
9595 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9596 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9597 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9598 portInfo.getLogicalSlotIndex()));
9599 }
9600 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009601 }
9602 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009603 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009608
9609 /**
9610 * Get the IRadio HAL Version
9611 */
9612 @Override
9613 public int getRadioHalVersion() {
9614 Phone phone = getDefaultPhone();
9615 if (phone == null) return -1;
9616 HalVersion hv = phone.getHalVersion();
9617 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9618 return hv.major * 100 + hv.minor;
9619 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009620
9621 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009622 * Get the current calling package name.
9623 * @return the current calling package name
9624 */
9625 @Override
9626 public String getCurrentPackageName() {
9627 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9628 }
9629
9630 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009631 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9632 * corresponding network requests on a subId.
9633 *
9634 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009635 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009636 * 2) APN is un-metered for this subscription, or
9637 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009638 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009639 *
9640 * @return whether data is allowed for a apn type.
9641 *
9642 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009643 */
9644 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009645 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009646 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9647 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009648
9649 // Now that all security checks passes, perform the operation as ourselves.
9650 final long identity = Binder.clearCallingIdentity();
9651 try {
9652 Phone phone = getPhone(subId);
9653 if (phone == null) return false;
9654
Jack Yu41407ee2019-05-13 16:54:09 -07009655 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009656 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
9661
9662 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009663 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009664 enforceReadPrivilegedPermission("isApnMetered");
9665
9666 // Now that all security checks passes, perform the operation as ourselves.
9667 final long identity = Binder.clearCallingIdentity();
9668 try {
9669 Phone phone = getPhone(subId);
9670 if (phone == null) return true; // By default return true.
9671
Jack Yu41407ee2019-05-13 16:54:09 -07009672 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009673 } finally {
9674 Binder.restoreCallingIdentity(identity);
9675 }
9676 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009677
9678 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009679 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9680 int subscriptionId, IBooleanConsumer resultCallback) {
9681 enforceModifyPermission();
9682 long token = Binder.clearCallingIdentity();
9683 try {
9684 Phone phone = getPhone(subscriptionId);
9685 if (phone == null) {
9686 try {
9687 if (resultCallback != null) {
9688 resultCallback.accept(false);
9689 }
9690 } catch (RemoteException e) {
9691 // ignore
9692 }
9693 return;
9694 }
9695 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9696 Pair.create(specifiers, (x) -> {
9697 try {
9698 if (resultCallback != null) {
9699 resultCallback.accept(x);
9700 }
9701 } catch (RemoteException e) {
9702 // ignore
9703 }
9704 });
9705 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9706 } finally {
9707 Binder.restoreCallingIdentity(token);
9708 }
9709 }
9710
9711 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009712 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9713 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009714 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009715 mApp, subId, "getSystemSelectionChannels");
9716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9717 final long identity = Binder.clearCallingIdentity();
9718 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009719 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9720 if (result instanceof IllegalStateException) {
9721 throw (IllegalStateException) result;
9722 }
9723 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009724 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9725 return specifiers;
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009732 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009733 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009734 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9735 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9736 if (iccRecords == null) {
9737 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9738 return false;
9739 }
9740 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9741 }
9742
9743 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009744 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9745 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009746 if (callingPackage == null) {
9747 callingPackage = getCurrentPackageName();
9748 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009749 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9750 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009751 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9752 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009753 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9754 }
9755 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9756 Intent intent = new Intent();
9757 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9758 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9759 // Bring up choose default SMS subscription dialog right now
9760 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9761 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9762 mApp.startActivity(intent);
9763 }
chen xud5ca2d52019-05-28 15:20:57 -07009764
9765 @Override
9766 public String getMmsUAProfUrl(int subId) {
9767 //TODO investigate if this API should require proper permission check in R b/133791609
9768 final long identity = Binder.clearCallingIdentity();
9769 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009770 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9771 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9772 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9773 return carrierUAProfUrl;
9774 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009775 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9776 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 @Override
9783 public String getMmsUserAgent(int subId) {
9784 //TODO investigate if this API should require proper permission check in R b/133791609
9785 final long identity = Binder.clearCallingIdentity();
9786 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009787 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9788 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9789 if (!TextUtils.isEmpty(carrierUserAgent)) {
9790 return carrierUserAgent;
9791 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009792 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9793 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 }
Jack Yub07d4972019-05-28 16:12:25 -07009798
9799 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009800 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9801 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009802
Jack Yub07d4972019-05-28 16:12:25 -07009803 final long identity = Binder.clearCallingIdentity();
9804 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009805 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009806 if (phone == null) return false;
9807
Hall Liua62f5da2020-09-25 10:42:19 -07009808 switch (policy) {
9809 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9810 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9811 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9812 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9813 default:
9814 throw new IllegalArgumentException(policy + " is not a valid policy");
9815 }
Jack Yub07d4972019-05-28 16:12:25 -07009816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
9820
9821 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009822 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009823 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009824 enforceModifyPermission();
9825
changbettyd5c246e2019-12-24 15:40:37 +08009826 final long identity = Binder.clearCallingIdentity();
9827 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009828 Phone phone = getPhone(subscriptionId);
9829 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009830
Hall Liua62f5da2020-09-25 10:42:19 -07009831 switch (policy) {
9832 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9833 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9834 break;
9835 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9836 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9837 break;
9838 default:
9839 throw new IllegalArgumentException(policy + " is not a valid policy");
9840 }
changbettyd5c246e2019-12-24 15:40:37 +08009841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 }
9845
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009846 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009847 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009848 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9849 * otherwise.
9850 */
9851 @Override
9852 public void setCepEnabled(boolean isCepEnabled) {
9853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9854
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
9857 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9858 for (Phone phone : PhoneFactory.getPhones()) {
9859 Phone defaultPhone = phone.getImsPhone();
9860 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9861 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9862 ImsPhoneCallTracker imsPhoneCallTracker =
9863 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9864 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9865 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9866 + imsPhone.getMsisdn());
9867 }
9868 }
9869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
allenwtsu46dcc572020-01-08 18:24:03 +08009873
9874 /**
9875 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9876 *
9877 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9878 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9879 * before being read.
9880 */
9881 @Override
9882 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9883 isCompressed) {
9884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9885 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9887 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9888 }
9889 if (!isImsAvailableOnDevice()) {
9890 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9891 "IMS not available on device.");
9892 }
9893
9894 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009895 try {
Hui Wang761a6682020-10-31 05:12:53 +00009896 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009899 }
9900 }
zoey chene02881a2019-12-30 16:11:23 +08009901
9902 @Override
9903 public boolean isIccLockEnabled(int subId) {
9904 enforceReadPrivilegedPermission("isIccLockEnabled");
9905
9906 // Now that all security checks passes, perform the operation as ourselves.
9907 final long identity = Binder.clearCallingIdentity();
9908 try {
9909 Phone phone = getPhone(subId);
9910 if (phone != null && phone.getIccCard() != null) {
9911 return phone.getIccCard().getIccLockEnabled();
9912 } else {
9913 return false;
9914 }
9915 } finally {
9916 Binder.restoreCallingIdentity(identity);
9917 }
9918 }
9919
9920 /**
9921 * Set the ICC pin lock enabled or disabled.
9922 *
9923 * @return an integer representing the status of IccLock enabled or disabled in the following
9924 * three cases:
9925 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9926 * successfully.
9927 * - Positive number and zero for remaining password attempts.
9928 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9929 *
9930 */
9931 @Override
9932 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9933 enforceModifyPermission();
9934
9935 Phone phone = getPhone(subId);
9936 if (phone == null) {
9937 return 0;
9938 }
9939 // Now that all security checks passes, perform the operation as ourselves.
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9943 new Pair<Boolean, String>(enabled, password), phone, null);
9944 return attemptsRemaining;
9945
9946 } catch (Exception e) {
9947 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 return 0;
9952 }
9953
9954 /**
9955 * Change the ICC password used in ICC pin lock.
9956 *
9957 * @return an integer representing the status of IccLock changed in the following three cases:
9958 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9959 * - Positive number and zero for remaining password attempts.
9960 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9961 *
9962 */
9963 @Override
9964 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9965 enforceModifyPermission();
9966
9967 Phone phone = getPhone(subId);
9968 if (phone == null) {
9969 return 0;
9970 }
9971 // Now that all security checks passes, perform the operation as ourselves.
9972 final long identity = Binder.clearCallingIdentity();
9973 try {
9974 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9975 new Pair<String, String>(oldPassword, newPassword), phone, null);
9976 return attemptsRemaining;
9977
9978 } catch (Exception e) {
9979 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 return 0;
9984 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009985
9986 /**
9987 * Request for receiving user activity notification
9988 */
9989 @Override
9990 public void requestUserActivityNotification() {
9991 if (!mNotifyUserActivity.get()
9992 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9993 mNotifyUserActivity.set(true);
9994 }
9995 }
9996
9997 /**
9998 * Called when userActivity is signalled in the power manager.
9999 * This is safe to call from any thread, with any window manager locks held or not.
10000 */
10001 @Override
10002 public void userActivity() {
10003 // ***************************************
10004 // * Inherited from PhoneWindowManager *
10005 // ***************************************
10006 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10007 // WITH ITS LOCKS HELD.
10008 //
10009 // This code must be VERY careful about the locks
10010 // it acquires.
10011 // In fact, the current code acquires way too many,
10012 // and probably has lurking deadlocks.
10013
10014 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10015 throw new SecurityException("Only the OS may call notifyUserActivity()");
10016 }
10017
10018 if (mNotifyUserActivity.getAndSet(false)) {
10019 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10020 USER_ACTIVITY_NOTIFICATION_DELAY);
10021 }
10022 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010023
10024 @Override
10025 public boolean canConnectTo5GInDsdsMode() {
10026 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10027 }
Jack Yud10cdd42020-09-28 20:28:01 -070010028
10029 @Override
10030 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10031 String callingFeatureId) {
10032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10033 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10034 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10035 }
10036
10037 Phone phone = getPhone(subId);
10038 if (phone == null) {
10039 throw new RuntimeException("phone is not available");
10040 }
10041 // Now that all security checks passes, perform the operation as ourselves.
10042 final long identity = Binder.clearCallingIdentity();
10043 try {
10044 return phone.getEquivalentHomePlmns();
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 }
Daniel Bright59e67312020-11-13 11:49:37 -080010049
10050 @Override
10051 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010052 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10053 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010054 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010055 if (radioInterfaceCapabilities == null) {
10056 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010057 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010058 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010059 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010060
Hui Wang641e81c2020-10-12 12:14:23 -070010061 @Override
10062 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10063 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010064 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10065 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10066 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10067 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10068 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010069 if (DBG) {
10070 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10071 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10072 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10073 }
10074
10075 if (!SubscriptionManager.isValidSubscriptionId(subId)
10076 || appType < TelephonyManager.APPTYPE_UNKNOWN
10077 || appType > TelephonyManager.APPTYPE_ISIM
10078 || nafUrl == null || securityProtocol == null || callback == null) {
10079 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10080 if (callback != null) {
10081 try {
10082 callback.onAuthenticationFailure(
10083 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10084 } catch (RemoteException exception) {
10085 log("Fail to notify onAuthenticationFailure due to " + exception);
10086 }
10087 return;
10088 }
10089 }
10090
10091 final long token = Binder.clearCallingIdentity();
10092 try {
10093 getGbaManager(subId).bootstrapAuthenticationRequest(
10094 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10095 forceBootStrapping, callback));
10096 } finally {
10097 Binder.restoreCallingIdentity(token);
10098 }
10099 }
10100
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010101 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010102 * Attempts to set the radio power state for all phones for thermal reason.
10103 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010104 * requested radio power state will actually be set. See {@link
10105 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10106 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 * @param enable {@code true} if trying to turn radio on.
10108 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10109 * false}.
10110 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010111 private boolean setRadioPowerForThermal(boolean enable) {
10112 boolean isPhoneAvailable = false;
10113 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10114 Phone phone = PhoneFactory.getPhone(i);
10115 if (phone != null) {
10116 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10117 isPhoneAvailable = true;
10118 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010119 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010120
10121 // return true if successfully informed the phone object about the thermal radio power
10122 // request.
10123 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010124 }
10125
10126 private int handleDataThrottlingRequest(int subId,
10127 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010128 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10129 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10130 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10131 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10132 throw new IllegalArgumentException("modem does not support data throttling");
10133 }
10134
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010135 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10136 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010137 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010138 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10139 }
10140
10141 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10142
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010143 if (isDataThrottlingSupported) {
10144 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010146 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10147 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10148 } else if (thermalMitigationResult
10149 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010150 log("Modem likely does not support data throttling on secondary carrier. Data " +
10151 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10152 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010153 }
10154 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010155 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010156
10157 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 }
10159
Jack Nudelman644b91a2021-03-12 14:09:48 -080010160 private static List<String> getThermalMitigationAllowlist(Context context) {
10161 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10162 for (String pckg : context.getResources()
10163 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10164 sThermalMitigationAllowlistedPackages.add(pckg);
10165 }
10166 }
10167
10168 return sThermalMitigationAllowlistedPackages;
10169 }
10170
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010171 private boolean isAnyPhoneInEmergencyState() {
10172 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10173 if (tm.isInEmergencyCall()) {
10174 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10175 return true;
10176 }
10177 for (Phone phone : PhoneFactory.getPhones()) {
10178 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10179 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10180 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10181 + phone.isInEcm());
10182 return true;
10183 }
10184 }
10185
10186 return false;
10187 }
10188
Jack Nudelman644b91a2021-03-12 14:09:48 -080010189 /**
10190 * Used by shell commands to add an authorized package name for thermal mitigation.
10191 * @param packageName name of package to be allowlisted
10192 * @param context
10193 */
10194 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10195 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10196 sThermalMitigationAllowlistedPackages.add(packageName);
10197 }
10198
10199 /**
10200 * Used by shell commands to remove an authorized package name for thermal mitigation.
10201 * @param packageName name of package to remove from allowlist
10202 * @param context
10203 */
10204 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10205 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10206 sThermalMitigationAllowlistedPackages.remove(packageName);
10207 }
10208
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010209 /**
10210 * Thermal mitigation request to control functionalities at modem.
10211 *
10212 * @param subId the id of the subscription.
10213 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010214 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010215 *
10216 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10217 */
10218 @Override
10219 @ThermalMitigationResult
10220 public int sendThermalMitigationRequest(
10221 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010222 ThermalMitigationRequest thermalMitigationRequest,
10223 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010224 enforceModifyPermission();
10225
Jack Nudelman644b91a2021-03-12 14:09:48 -080010226 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10227 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10228 .contains(callingPackage)) {
10229 throw new SecurityException("Calling package must be configured in the device config. "
10230 + "calling package: " + callingPackage);
10231 }
10232
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10234 final long identity = Binder.clearCallingIdentity();
10235
10236 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10237 try {
10238 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10239 switch (thermalMitigationAction) {
10240 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10241 thermalMitigationResult =
10242 handleDataThrottlingRequest(subId,
10243 thermalMitigationRequest.getDataThrottlingRequest());
10244 break;
10245 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10246 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10247 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10248 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10249 }
10250
10251 // Ensure that radio is on. If not able to power on due to phone being
10252 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010253 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 thermalMitigationResult =
10255 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10256 break;
10257 }
10258
10259 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10260 false);
10261 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10262 break;
10263 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10264 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10265 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10266 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10267 }
10268
10269 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10270 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 Phone phone = getPhone(subId);
10272 if (phone == null) {
10273 thermalMitigationResult =
10274 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10275 break;
10276 }
10277
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010278 TelephonyConnectionService service =
10279 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010280 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010281 Log.e(LOG_TAG, "An emergency call is pending");
10282 thermalMitigationResult =
10283 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10284 break;
10285 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10288 break;
10289 }
10290 } else {
10291 thermalMitigationResult =
10292 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10293 break;
10294 }
10295
10296 // Turn radio off. If not able to power off due to phone being unavailable,
10297 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010298 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010299 thermalMitigationResult =
10300 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10301 break;
10302 }
10303 thermalMitigationResult =
10304 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10305 break;
10306 default:
10307 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10308 + "not exist. Requested action: " + thermalMitigationAction);
10309 }
10310 } catch (IllegalArgumentException e) {
10311 throw e;
10312 } catch (Exception e) {
10313 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10314 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318
10319 if (DBG) {
10320 log("thermalMitigationRequest returning with thermalMitigationResult: "
10321 + thermalMitigationResult);
10322 }
10323
10324 return thermalMitigationResult;
10325 }
Hui Wang641e81c2020-10-12 12:14:23 -070010326
10327 /**
10328 * Set the GbaService Package Name that Telephony will bind to.
10329 *
10330 * @param subId The sim that the GbaService is associated with.
10331 * @param packageName The name of the package to be replaced with.
10332 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10333 */
10334 @Override
10335 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10336 enforceModifyPermission();
10337
10338 final long identity = Binder.clearCallingIdentity();
10339 try {
10340 return getGbaManager(subId).overrideServicePackage(packageName);
10341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
10345
10346 /**
10347 * Return the package name of the currently bound GbaService.
10348 *
10349 * @param subId The sim that the GbaService is associated with.
10350 * @return the package name of the GbaService configuration, null if GBA is not supported.
10351 */
10352 @Override
10353 public String getBoundGbaService(int subId) {
10354 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10355
10356 final long identity = Binder.clearCallingIdentity();
10357 try {
10358 return getGbaManager(subId).getServicePackage();
10359 } finally {
10360 Binder.restoreCallingIdentity(identity);
10361 }
10362 }
10363
10364 /**
10365 * Set the release time for telephony to unbind GbaService.
10366 *
10367 * @param subId The sim that the GbaService is associated with.
10368 * @param interval The release time to unbind GbaService by millisecond.
10369 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10370 */
10371 @Override
10372 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10373 enforceModifyPermission();
10374
10375 final long identity = Binder.clearCallingIdentity();
10376 try {
10377 return getGbaManager(subId).overrideReleaseTime(interval);
10378 } finally {
10379 Binder.restoreCallingIdentity(identity);
10380 }
10381 }
10382
10383 /**
10384 * Return the release time for telephony to unbind GbaService.
10385 *
10386 * @param subId The sim that the GbaService is associated with.
10387 * @return The release time to unbind GbaService by millisecond.
10388 */
10389 @Override
10390 public int getGbaReleaseTime(int subId) {
10391 enforceReadPrivilegedPermission("getGbaReleaseTime");
10392
10393 final long identity = Binder.clearCallingIdentity();
10394 try {
10395 return getGbaManager(subId).getReleaseTime();
10396 } finally {
10397 Binder.restoreCallingIdentity(identity);
10398 }
10399 }
10400
10401 private GbaManager getGbaManager(int subId) {
10402 GbaManager instance = GbaManager.getInstance(subId);
10403 if (instance == null) {
10404 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10405 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10406 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10407 }
10408 return instance;
10409 }
Hui Wang761a6682020-10-31 05:12:53 +000010410
10411 /**
10412 * indicate whether the device and the carrier can support
10413 * RCS VoLTE single registration.
10414 */
10415 @Override
10416 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010417 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10418 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10419 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10420 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010421
10422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10423 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10424 }
10425
10426 final long identity = Binder.clearCallingIdentity();
10427 try {
10428 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10429 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010430 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10431 if (isCapable != null) {
10432 return isCapable;
10433 }
Hui Wang761a6682020-10-31 05:12:53 +000010434 }
Hui Wang67af90e2021-06-04 16:57:15 -070010435 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10436 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 }
10441
10442 /**
10443 * Register RCS provisioning callback.
10444 */
10445 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010446 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010447 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010448 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010449 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010450 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10451 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010452
10453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10454 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10455 }
10456 if (!isImsAvailableOnDevice()) {
10457 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10458 "IMS not available on device.");
10459 }
10460
10461 final long identity = Binder.clearCallingIdentity();
10462 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010463 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010464 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010465 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10466 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010467 }
Hui Wang761a6682020-10-31 05:12:53 +000010468 } finally {
10469 Binder.restoreCallingIdentity(identity);
10470 }
10471 }
10472
10473 /**
10474 * Unregister RCS provisioning callback.
10475 */
10476 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010477 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010478 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010479 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010480 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010481 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10482 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010483
10484 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10485 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10486 }
10487 if (!isImsAvailableOnDevice()) {
10488 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10489 "IMS not available on device.");
10490 }
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010494 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010495 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 }
10500
10501 /**
10502 * trigger RCS reconfiguration.
10503 */
10504 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010505 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10506 "triggerRcsReconfiguration",
10507 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010508
10509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10510 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10511 }
10512 if (!isImsAvailableOnDevice()) {
10513 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10514 "IMS not available on device.");
10515 }
10516
10517 final long identity = Binder.clearCallingIdentity();
10518 try {
10519 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
10525 /**
10526 * Provide the client configuration parameters of the RCS application.
10527 */
10528 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010529 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10530 "setRcsClientConfiguration",
10531 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010532
10533 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10534 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10535 }
10536 if (!isImsAvailableOnDevice()) {
10537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10538 "IMS not available on device.");
10539 }
10540
10541 final long identity = Binder.clearCallingIdentity();
10542
10543 try {
10544 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10545 if (configBinder == null) {
10546 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010547 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10548 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010549 } else {
10550 configBinder.setRcsClientConfiguration(rcc);
10551 }
joonhunshin3e154242021-09-17 06:33:39 +000010552
10553 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10554 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010555 } catch (RemoteException e) {
10556 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010557 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10558 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010559 } finally {
10560 Binder.restoreCallingIdentity(identity);
10561 }
10562 }
10563
10564 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010565 * Enables or disables the test mode for RCS VoLTE single registration.
10566 */
10567 @Override
10568 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10569 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10570 "setRcsSingleRegistrationTestModeEnabled");
10571
10572 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10573 }
10574
10575 /**
10576 * Gets the test mode for RCS VoLTE single registration.
10577 */
10578 @Override
10579 public boolean getRcsSingleRegistrationTestModeEnabled() {
10580 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10581 "getRcsSingleRegistrationTestModeEnabled");
10582
10583 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10584 }
10585
10586 /**
Hui Wang761a6682020-10-31 05:12:53 +000010587 * Overrides the config of RCS VoLTE single registration enabled for the device.
10588 */
10589 @Override
10590 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10592 "setDeviceSingleRegistrationEnabledOverride");
10593 enforceModifyPermission();
10594
10595 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10596 : Boolean.parseBoolean(enabledStr);
10597 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010598 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010599 }
10600
10601 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010602 * Sends a device to device communication message. Only usable via shell.
10603 * @param message message to send.
10604 * @param value message value.
10605 */
10606 @Override
10607 public void sendDeviceToDeviceMessage(int message, int value) {
10608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010609 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010610 enforceModifyPermission();
10611
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 TelephonyConnectionService service =
10615 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10616 if (service == null) {
10617 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10618 return;
10619 }
10620 service.sendTestDeviceToDeviceMessage(message, value);
10621 } finally {
10622 Binder.restoreCallingIdentity(identity);
10623 }
10624 }
10625
Tyler Gunnbabbda02021-02-10 11:05:02 -080010626 /**
10627 * Sets the specified device to device transport active.
10628 * @param transport The transport to set active.
10629 */
10630 @Override
10631 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10633 "setActiveDeviceToDeviceTransport");
10634 enforceModifyPermission();
10635
10636 final long identity = Binder.clearCallingIdentity();
10637 try {
10638 TelephonyConnectionService service =
10639 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10640 if (service == null) {
10641 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10642 return;
10643 }
10644 service.setActiveDeviceToDeviceTransport(transport);
10645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
Tyler Gunn92479152021-01-20 16:30:10 -080010649
Tyler Gunnd4339262021-05-03 14:46:49 -070010650 @Override
10651 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10653 "setDeviceToDeviceForceEnabled");
10654
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 Arrays.stream(PhoneFactory.getPhones()).forEach(
10658 p -> {
10659 Phone thePhone = p.getImsPhone();
10660 if (thePhone != null && thePhone instanceof ImsPhone) {
10661 ImsPhone imsPhone = (ImsPhone) thePhone;
10662 CallTracker tracker = imsPhone.getCallTracker();
10663 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10664 ImsPhoneCallTracker imsPhoneCallTracker =
10665 (ImsPhoneCallTracker) tracker;
10666 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10667 }
10668 }
10669 }
10670 );
10671 } finally {
10672 Binder.restoreCallingIdentity(identity);
10673 }
10674 }
10675
Tyler Gunn92479152021-01-20 16:30:10 -080010676 /**
Hui Wang761a6682020-10-31 05:12:53 +000010677 * Gets the config of RCS VoLTE single registration enabled for the device.
10678 */
10679 @Override
10680 public boolean getDeviceSingleRegistrationEnabled() {
10681 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10682 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10683 }
10684
10685 /**
10686 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10687 */
10688 @Override
10689 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10691 "setCarrierSingleRegistrationEnabledOverride");
10692 enforceModifyPermission();
10693
10694 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10695 : Boolean.parseBoolean(enabledStr);
10696 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10697 subId, enabled);
10698 }
10699
10700 /**
10701 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10702 */
10703 @Override
10704 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10705 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10706 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10707 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010708
10709 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010710 * Overrides the ims feature validation result
10711 */
10712 @Override
10713 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10714 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10715 "setImsFeatureValidationOverride");
10716
10717 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10718 : Boolean.parseBoolean(enabledStr);
10719 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10720 subId, enabled);
10721 }
10722
10723 /**
10724 * Gets the ims feature validation override value
10725 */
10726 @Override
10727 public boolean getImsFeatureValidationOverride(int subId) {
10728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10729 "getImsFeatureValidationOverride");
10730 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10731 }
10732
10733 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010734 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10735 * their mobile plan.
10736 */
10737 @Override
10738 public String getMobileProvisioningUrl() {
10739 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10740 final long identity = Binder.clearCallingIdentity();
10741 try {
10742 return getDefaultPhone().getMobileProvisioningUrl();
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010747
James.cf Linbcdf8b32021-01-14 16:44:13 +080010748 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010749 * Get the EAB contact from the EAB database.
10750 */
10751 @Override
10752 public String getContactFromEab(String contact) {
10753 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10754 enforceModifyPermission();
10755 final long identity = Binder.clearCallingIdentity();
10756 try {
10757 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10758 } finally {
10759 Binder.restoreCallingIdentity(identity);
10760 }
10761 }
10762
10763 /**
Calvin Pana1434322021-07-01 19:27:01 +080010764 * Get the EAB capability from the EAB database.
10765 */
10766 @Override
10767 public String getCapabilityFromEab(String contact) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10769 enforceModifyPermission();
10770 final long identity = Binder.clearCallingIdentity();
10771 try {
10772 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
10777
10778 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010779 * Remove the EAB contacts from the EAB database.
10780 */
10781 @Override
10782 public int removeContactFromEab(int subId, String contacts) {
10783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10784 enforceModifyPermission();
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10788 } finally {
10789 Binder.restoreCallingIdentity(identity);
10790 }
10791 }
10792
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010793 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010794 public boolean getDeviceUceEnabled() {
10795 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10796 final long identity = Binder.clearCallingIdentity();
10797 try {
10798 return mApp.getDeviceUceEnabled();
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
10804 @Override
10805 public void setDeviceUceEnabled(boolean isEnabled) {
10806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10807 final long identity = Binder.clearCallingIdentity();
10808 try {
10809 mApp.setDeviceUceEnabled(isEnabled);
10810 } finally {
10811 Binder.restoreCallingIdentity(identity);
10812 }
10813 }
10814
Brad Ebinger14d467f2021-02-12 06:18:28 +000010815 /**
10816 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10817 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10818 */
10819 // Used for SHELL command only right now.
10820 @Override
10821 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10822 List<String> featureTags) {
10823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10824 "addUceRegistrationOverrideShell");
10825 final long identity = Binder.clearCallingIdentity();
10826 try {
10827 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10828 new ArraySet<>(featureTags));
10829 } catch (ImsException e) {
10830 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 }
10835
10836 /**
10837 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10838 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10839 */
10840 // Used for SHELL command only right now.
10841 @Override
10842 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10843 List<String> featureTags) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10845 "removeUceRegistrationOverrideShell");
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10849 new ArraySet<>(featureTags));
10850 } catch (ImsException e) {
10851 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10852 } finally {
10853 Binder.restoreCallingIdentity(identity);
10854 }
10855 }
10856
10857 /**
10858 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10859 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10860 */
10861 // Used for SHELL command only right now.
10862 @Override
10863 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10865 "clearUceRegistrationOverrideShell");
10866 final long identity = Binder.clearCallingIdentity();
10867 try {
10868 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10869 } catch (ImsException e) {
10870 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
10876 /**
10877 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10878 */
10879 // Used for SHELL command only right now.
10880 @Override
10881 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10883 "getLatestRcsContactUceCapabilityShell");
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10887 } catch (ImsException e) {
10888 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10889 } finally {
10890 Binder.restoreCallingIdentity(identity);
10891 }
10892 }
10893
10894 /**
10895 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10896 * device does not have an active PUBLISH.
10897 */
10898 // Used for SHELL command only right now.
10899 @Override
10900 public String getLastUcePidfXmlShell(int subId) {
10901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
10904 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10905 } catch (ImsException e) {
10906 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
James.cf Line8713a42021-04-29 16:04:26 +080010912 /**
10913 * Remove UCE requests cannot be sent to the network status.
10914 */
10915 // Used for SHELL command only right now.
10916 @Override
10917 public boolean removeUceRequestDisallowedStatus(int subId) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
10921 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10922 } catch (ImsException e) {
10923 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
10928
James.cf Lin18bb9002021-05-25 01:37:38 +080010929 /**
10930 * Remove UCE requests cannot be sent to the network status.
10931 */
10932 // Used for SHELL command only.
10933 @Override
10934 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10936 final long identity = Binder.clearCallingIdentity();
10937 try {
10938 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10939 } catch (ImsException e) {
10940 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10941 } finally {
10942 Binder.restoreCallingIdentity(identity);
10943 }
10944 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010945
James.cf Lin4b784aa2021-01-31 03:25:15 +080010946 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010947 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10948 String callingPackage) {
10949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10950 mApp, subId, "setSignalStrengthUpdateRequest");
10951
10952 final int callingUid = Binder.getCallingUid();
10953 // Verify that tha callingPackage belongs to the calling UID
10954 mApp.getSystemService(AppOpsManager.class)
10955 .checkPackage(callingUid, callingPackage);
10956
Rambo Wang3607f502021-02-01 21:51:40 -080010957 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010958
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10962 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10963
10964 if (result instanceof IllegalStateException) {
10965 throw (IllegalStateException) result;
10966 }
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 @Override
10973 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10974 String callingPackage) {
10975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10976 mApp, subId, "clearSignalStrengthUpdateRequest");
10977
10978 final int callingUid = Binder.getCallingUid();
10979 // Verify that tha callingPackage belongs to the calling UID
10980 mApp.getSystemService(AppOpsManager.class)
10981 .checkPackage(callingUid, callingPackage);
10982
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
10985 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10986 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10987
10988 if (result instanceof IllegalStateException) {
10989 throw (IllegalStateException) result;
10990 }
10991 } finally {
10992 Binder.restoreCallingIdentity(identity);
10993 }
10994 }
10995
Rambo Wang3607f502021-02-01 21:51:40 -080010996 private static void validateSignalStrengthUpdateRequest(Context context,
10997 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010998 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10999 // phone/system process do not have further restriction on request
11000 return;
11001 }
11002
11003 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011004 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011005 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011006 context.enforceCallingOrSelfPermission(
11007 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11008 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011009 }
11010
11011 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11012 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11013 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11014 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11015 || info.isEnabled()) {
11016 throw new IllegalArgumentException(
11017 "Only system can set hide fields in SignalThresholdInfo");
11018 }
11019
11020 // Thresholds length for each RAN need in range. This has been validated in
11021 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11022 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11023 final int[] thresholds = info.getThresholds();
11024 Objects.requireNonNull(thresholds);
11025 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11026 || thresholds.length
11027 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11028 throw new IllegalArgumentException(
11029 "thresholds length is out of range: " + thresholds.length);
11030 }
11031 }
11032 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011033
11034 /**
11035 * Gets the current phone capability.
11036 *
11037 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11038 * @return the PhoneCapability which describes the data connection capability of modem.
11039 * It's used to evaluate possible phone config change, for example from single
11040 * SIM device to multi-SIM device.
11041 */
11042 @Override
11043 public PhoneCapability getPhoneCapability() {
11044 enforceReadPrivilegedPermission("getPhoneCapability");
11045 final long identity = Binder.clearCallingIdentity();
11046 try {
11047 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11048 } finally {
11049 Binder.restoreCallingIdentity(identity);
11050 }
11051 }
Michele Berionne5e411512020-11-13 02:36:59 +000011052
11053 /**
11054 * Prepare TelephonyManager for an unattended reboot. The reboot is
11055 * required to be done shortly after the API is invoked.
11056 */
11057 @Override
11058 @TelephonyManager.PrepareUnattendedRebootResult
11059 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011061 enforceRebootPermission();
11062
11063 final long identity = Binder.clearCallingIdentity();
11064 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011065 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011070
11071 /**
11072 * Request to get the current slicing configuration including URSP rules and
11073 * NSSAIs (configured, allowed and rejected).
11074 *
11075 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11076 */
11077 @Override
11078 public void getSlicingConfig(ResultReceiver callback) {
11079 enforceReadPrivilegedPermission("getSlicingConfig");
11080
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
11083 Phone phone = getDefaultPhone();
11084 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11085 } finally {
11086 Binder.restoreCallingIdentity(identity);
11087 }
11088 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011089
11090 /**
11091 * Register an IMS connection state callback
11092 */
11093 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011094 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11095 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011096 if (feature == ImsFeature.FEATURE_MMTEL) {
11097 // ImsMmTelManager
11098 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11099 TelephonyPermissions
11100 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11101 mApp, subId, "registerImsStateCallback");
11102 } else if (feature == ImsFeature.FEATURE_RCS) {
11103 // ImsRcsManager or SipDelegateManager
11104 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11105 Binder.getCallingUid(), "registerImsStateCallback",
11106 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11107 Manifest.permission.READ_PRECISE_PHONE_STATE,
11108 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11109 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11110 }
11111
11112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11114 "IMS not available on device.");
11115 }
11116
11117 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11118 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11119 }
11120
11121 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11122 if (controller == null) {
11123 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11124 "IMS not available on device.");
11125 }
11126
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011127 if (callingPackage == null) {
11128 callingPackage = getCurrentPackageName();
11129 }
11130
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011131 final long token = Binder.clearCallingIdentity();
11132 try {
11133 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011134 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011135 } catch (ImsException e) {
11136 throw new ServiceSpecificException(e.getCode());
11137 } finally {
11138 Binder.restoreCallingIdentity(token);
11139 }
11140 }
11141
11142 /**
11143 * Unregister an IMS connection state callback
11144 */
11145 @Override
11146 public void unregisterImsStateCallback(IImsStateCallback cb) {
11147 final long token = Binder.clearCallingIdentity();
11148 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11149 if (controller == null) {
11150 return;
11151 }
11152 try {
11153 controller.unregisterImsStateCallback(cb);
11154 } finally {
11155 Binder.restoreCallingIdentity(token);
11156 }
11157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011158}