blob: 296e96b040cbdd0feb575f713d3caade52c4ec03 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080067import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080094import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080095import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080096import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800100import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800101import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000102import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700103import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700104import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800105import android.telephony.data.ApnSetting;
106import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700107import android.telephony.gba.GbaAuthRequest;
108import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700109import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000111import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700112import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800114import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700115import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700117import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000118import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700119import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800120import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800121import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800123import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700126import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800128import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129
Andrew Lee312e8172014-10-23 17:01:36 -0700130import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800131import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800132import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700134import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700135import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800136import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800139import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800142import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800143import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700144import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800146import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800148import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700150import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700151import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700153import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800154import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700155import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700156import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700157import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700158import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700159import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700160import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700161import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800163import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800164import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700166import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800167import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700168import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800169import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700170import com.android.internal.telephony.imsphone.ImsPhone;
171import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800172import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700173import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800175import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700178import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800181import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000182import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800183import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700184import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700185import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800186import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700187import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700188import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800189import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700191import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800192import com.android.services.telephony.TelecomAccountRegistry;
193import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800194import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800195
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700196import java.io.FileDescriptor;
197import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800199import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800200import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800201import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800202import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100203import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700205import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800206import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800207import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800208import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209
210/**
211 * Implementation of the ITelephony interface.
212 */
Santos Cordon117fee72014-05-16 17:56:12 -0700213public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214 private static final String LOG_TAG = "PhoneInterfaceManager";
215 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
216 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
219 // Message codes used with mMainThreadHandler
220 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700221 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
222 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223 private static final int CMD_OPEN_CHANNEL = 9;
224 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
225 private static final int CMD_CLOSE_CHANNEL = 11;
226 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800227 private static final int CMD_NV_READ_ITEM = 13;
228 private static final int EVENT_NV_READ_ITEM_DONE = 14;
229 private static final int CMD_NV_WRITE_ITEM = 15;
230 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
231 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
232 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700233 private static final int CMD_RESET_MODEM_CONFIG = 19;
234 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800235 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
236 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
237 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
238 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800239 private static final int CMD_SEND_ENVELOPE = 25;
240 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000241 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
242 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700243 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
244 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
245 private static final int CMD_EXCHANGE_SIM_IO = 31;
246 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800247 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
248 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700249 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
250 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700251 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
252 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700253 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
254 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
255 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
256 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700257 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
258 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
259 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
260 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700261 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800262 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
263 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000264 private static final int CMD_SWITCH_SLOTS = 50;
265 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700266 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
267 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
268 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
269 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
270 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
271 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
272 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
273 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700274 private static final int CMD_GET_ALL_CELL_INFO = 60;
275 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
276 private static final int CMD_GET_CELL_LOCATION = 62;
277 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700278 private static final int CMD_MODEM_REBOOT = 64;
279 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700280 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
281 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800282 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
283 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284 private static final int CMD_GET_MODEM_STATUS = 70;
285 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700286 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
287 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700288 private static final int CMD_ERASE_MODEM_CONFIG = 74;
289 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800290 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
291 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
292 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
293 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800294 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
295 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800296 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800297 private static final int CMD_GET_CALL_FORWARDING = 83;
298 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
299 private static final int CMD_SET_CALL_FORWARDING = 85;
300 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
301 private static final int CMD_GET_CALL_WAITING = 87;
302 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
303 private static final int CMD_SET_CALL_WAITING = 89;
304 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700305 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
306 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
307 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
308 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700309 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
310 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800311 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
312 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800313 private static final int CMD_SET_DATA_THROTTLING = 99;
314 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800315 private static final int CMD_SET_SIM_POWER = 101;
316 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800318 // Parameters of select command.
319 private static final int SELECT_COMMAND = 0xA4;
320 private static final int SELECT_P1 = 0x04;
321 private static final int SELECT_P2 = 0;
322 private static final int SELECT_P3 = 0x10;
323
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 /** The singleton instance. */
325 private static PhoneInterfaceManager sInstance;
326
Wink Saville3ab207e2014-11-20 13:07:20 -0800327 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800328 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800329 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700330 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800331 private AppOpsManager mAppOps;
332 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800333 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700335 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 /** User Activity */
338 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800339 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
340
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700341 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
342
Derek Tan97ebb422014-09-05 16:55:38 -0700343 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
344 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800345 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800346 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700347
Michelecea4cf22018-12-21 15:00:11 -0800348 // String to store multi SIM allowed
349 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
350
Derek Tan740e1672017-06-27 14:56:27 -0700351 // The AID of ISD-R.
352 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
353
yinxub1bed742017-04-17 11:45:04 -0700354 private NetworkScanRequestTracker mNetworkScanRequestTracker;
355
David Kelly5e06a7f2018-03-12 14:10:59 +0000356 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
357 private static final int MANUFACTURER_CODE_LENGTH = 8;
358
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800359 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
360
Derek Tan89e89d42014-07-08 17:00:10 -0700361 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700362 * Experiment flag to enable erase modem config on reset network, default value is false
363 */
364 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
365 "reset_network_erase_modem_config_enabled";
366
367 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700368 * A request object to use for transmitting data to an ICC.
369 */
370 private static final class IccAPDUArgument {
371 public int channel, cla, command, p1, p2, p3;
372 public String data;
373
374 public IccAPDUArgument(int channel, int cla, int command,
375 int p1, int p2, int p3, String data) {
376 this.channel = channel;
377 this.cla = cla;
378 this.command = command;
379 this.p1 = p1;
380 this.p2 = p2;
381 this.p3 = p3;
382 this.data = data;
383 }
384 }
385
386 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700387 * A request object to use for transmitting data to an ICC.
388 */
389 private static final class ManualNetworkSelectionArgument {
390 public OperatorInfo operatorInfo;
391 public boolean persistSelection;
392
393 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
394 this.operatorInfo = operatorInfo;
395 this.persistSelection = persistSelection;
396 }
397 }
398
399 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
401 * request after sending. The main thread will notify the request when it is complete.
402 */
403 private static final class MainThreadRequest {
404 /** The argument to use for the request */
405 public Object argument;
406 /** The result of the request that is run on the main thread */
407 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800408 // The subscriber id that this request applies to. Defaults to
409 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
410 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411
Nathan Harold92bed182018-10-12 18:16:49 -0700412 // In cases where subId is unavailable, the caller needs to specify the phone.
413 public Phone phone;
414
vagdeviaf9a5b92018-08-15 16:01:53 -0700415 public WorkSource workSource;
416
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 public MainThreadRequest(Object argument) {
418 this.argument = argument;
419 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800420
Nathan Harold92bed182018-10-12 18:16:49 -0700421 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
422 this.argument = argument;
423 if (phone != null) {
424 this.phone = phone;
425 }
426 this.workSource = workSource;
427 }
428
vagdeviaf9a5b92018-08-15 16:01:53 -0700429 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800430 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800431 if (subId != null) {
432 this.subId = subId;
433 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700434 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 }
437
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800438 private static final class IncomingThirdPartyCallArgs {
439 public final ComponentName component;
440 public final String callId;
441 public final String callerDisplayName;
442
443 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
444 String callerDisplayName) {
445 this.component = component;
446 this.callId = callId;
447 this.callerDisplayName = callerDisplayName;
448 }
449 }
450
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 /**
452 * A handler that processes messages on the main thread in the phone process. Since many
453 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
454 * inbound binder threads to the main thread in the phone process. The Binder thread
455 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
456 * on, which will be notified when the operation completes and will contain the result of the
457 * request.
458 *
459 * <p>If a MainThreadRequest object is provided in the msg.obj field,
460 * note that request.result must be set to something non-null for the calling thread to
461 * unblock.
462 */
463 private final class MainThreadHandler extends Handler {
464 @Override
465 public void handleMessage(Message msg) {
466 MainThreadRequest request;
467 Message onCompleted;
468 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800469 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800471 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472
473 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 case CMD_HANDLE_USSD_REQUEST: {
475 request = (MainThreadRequest) msg.obj;
476 final Phone phone = getPhoneFromRequest(request);
477 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
478 String ussdRequest = ussdObject.first;
479 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700480
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 if (!isUssdApiAllowed(request.subId)) {
482 // Carrier does not support use of this API, return failure.
483 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
484 UssdResponse response = new UssdResponse(ussdRequest, null);
485 Bundle returnData = new Bundle();
486 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
487 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700488
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 request.result = true;
490 notifyRequester(request);
491 return;
492 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700493
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 try {
495 request.result = phone != null
496 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
497 } catch (CallStateException cse) {
498 request.result = false;
499 }
500 // Wake up the requesting thread
501 notifyRequester(request);
502 break;
pkanwar32d516d2016-10-14 19:37:38 -0700503 }
504
Yorke Lee716f67e2015-06-17 15:39:16 -0700505 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700507 final Phone phone = getPhoneFromRequest(request);
508 request.result = phone != null ?
509 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
510 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("iccTransmitApduLogicalChannel: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
526 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 iccArgument.channel, iccArgument.cla, iccArgument.command,
529 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700532 break;
533
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 if (ar.result == null) {
542 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800543 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800545 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 } else {
547 loge("iccTransmitApduLogicalChannel: Unknown exception");
548 }
549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 break;
552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
554 request = (MainThreadRequest) msg.obj;
555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduBasicChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
563 request);
564 uiccCard.iccTransmitApduBasicChannel(
565 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
566 iccArgument.p3, iccArgument.data, onCompleted);
567 }
568 break;
569
570 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
571 ar = (AsyncResult) msg.obj;
572 request = (MainThreadRequest) ar.userObj;
573 if (ar.exception == null && ar.result != null) {
574 request.result = ar.result;
575 } else {
576 request.result = new IccIoResult(0x6F, 0, (byte[])null);
577 if (ar.result == null) {
578 loge("iccTransmitApduBasicChannel: Empty response");
579 } else if (ar.exception instanceof CommandException) {
580 loge("iccTransmitApduBasicChannel: CommandException: " +
581 ar.exception);
582 } else {
583 loge("iccTransmitApduBasicChannel: Unknown exception");
584 }
585 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 break;
588
589 case CMD_EXCHANGE_SIM_IO:
590 request = (MainThreadRequest) msg.obj;
591 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 if (uiccCard == null) {
594 loge("iccExchangeSimIO: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
599 request);
600 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
601 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
602 iccArgument.data, onCompleted);
603 }
604 break;
605
606 case EVENT_EXCHANGE_SIM_IO_DONE:
607 ar = (AsyncResult) msg.obj;
608 request = (MainThreadRequest) ar.userObj;
609 if (ar.exception == null && ar.result != null) {
610 request.result = ar.result;
611 } else {
612 request.result = new IccIoResult(0x6f, 0, (byte[])null);
613 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 break;
616
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 case CMD_SEND_ENVELOPE:
618 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800619 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 if (uiccCard == null) {
621 loge("sendEnvelopeWithStatus: No UICC");
622 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 } else {
625 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
626 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
627 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800628 break;
629
630 case EVENT_SEND_ENVELOPE_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800635 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
637 if (ar.result == null) {
638 loge("sendEnvelopeWithStatus: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("sendEnvelopeWithStatus: CommandException: " +
641 ar.exception);
642 } else {
643 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
644 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 break;
648
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 case CMD_OPEN_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800652 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800655 request.result = new IccOpenLogicalChannelResponse(-1,
656 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800660 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
661 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_OPEN_CHANNEL_DONE:
666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 int[] result = (int[]) ar.result;
671 int channelId = result[0];
672 byte[] selectResponse = null;
673 if (result.length > 1) {
674 selectResponse = new byte[result.length - 1];
675 for (int i = 1; i < result.length; ++i) {
676 selectResponse[i - 1] = (byte) result[i];
677 }
678 }
679 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700680 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.result == null) {
683 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 if (ar.exception != null) {
686 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
687 }
688
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700689 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700690 if (ar.exception instanceof CommandException) {
691 CommandException.Error error =
692 ((CommandException) (ar.exception)).getCommandError();
693 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700695 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700696 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 }
698 }
699 openChannelResp = new IccOpenLogicalChannelResponse(
700 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700702 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 break;
705
706 case CMD_CLOSE_CHANNEL:
707 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800708 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700709 if (uiccCard == null) {
710 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900711 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 } else {
714 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
715 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
716 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
719 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800720 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
721 break;
722
723 case CMD_NV_READ_ITEM:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800736 request.result = "";
737 if (ar.result == null) {
738 loge("nvReadItem: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("nvReadItem: CommandException: " +
741 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800743 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 break;
748
Jake Hambye994d462014-02-03 13:10:13 -0800749 case CMD_NV_WRITE_ITEM:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
752 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700754 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800755 break;
756
757 case EVENT_NV_WRITE_ITEM_DONE:
758 handleNullReturnEvent(msg, "nvWriteItem");
759 break;
760
761 case CMD_NV_WRITE_CDMA_PRL:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_WRITE_CDMA_PRL_DONE:
768 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
769 break;
770
chen xu6dac5ab2018-10-26 17:39:23 -0700771 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800772 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700773 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
chen xu6dac5ab2018-10-26 17:39:23 -0700777 case EVENT_RESET_MODEM_CONFIG_DONE:
778 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
Sooraj Sasindran37444802020-08-11 10:40:43 -0700781 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
784 request);
785 Phone phone = getPhoneFromRequest(request);
786 if (phone != null) {
787 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
788 } else {
789 loge("isNRDualConnectivityEnabled: No phone object");
790 request.result = false;
791 notifyRequester(request);
792 }
793 break;
794 }
795
796 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 if (ar.exception == null && ar.result != null) {
800 request.result = ar.result;
801 } else {
802 // request.result must be set to something non-null
803 // for the calling thread to unblock
804 if (request.result != null) {
805 request.result = ar.result;
806 } else {
807 request.result = false;
808 }
809 if (ar.result == null) {
810 loge("isNRDualConnectivityEnabled: Empty response");
811 } else if (ar.exception instanceof CommandException) {
812 loge("isNRDualConnectivityEnabled: CommandException: "
813 + ar.exception);
814 } else {
815 loge("isNRDualConnectivityEnabled: Unknown exception");
816 }
817 }
818 notifyRequester(request);
819 break;
820
821 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
822 request = (MainThreadRequest) msg.obj;
823 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
824 Phone phone = getPhoneFromRequest(request);
825 if (phone != null) {
826 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
827 request.workSource);
828 } else {
829 loge("enableNrDualConnectivity: No phone object");
830 request.result =
831 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
832 notifyRequester(request);
833 }
834 break;
835 }
836
837 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result =
842 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
843 } else {
844 request.result =
845 TelephonyManager
846 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
847 if (ar.exception instanceof CommandException) {
848 CommandException.Error error =
849 ((CommandException) (ar.exception)).getCommandError();
850 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
851 request.result =
852 TelephonyManager
853 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
854 }
855 loge("enableNrDualConnectivity" + ": CommandException: "
856 + ar.exception);
857 } else {
858 loge("enableNrDualConnectivity" + ": Unknown exception");
859 }
860 }
861 notifyRequester(request);
862 break;
863 }
864
Jake Hamby7c27be32014-03-03 13:25:59 -0800865 case CMD_GET_PREFERRED_NETWORK_TYPE:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700868 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800869 break;
870
871 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result; // Integer
876 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530877 // request.result must be set to something non-null
878 // for the calling thread to unblock
879 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 if (ar.result == null) {
881 loge("getPreferredNetworkType: Empty response");
882 } else if (ar.exception instanceof CommandException) {
883 loge("getPreferredNetworkType: CommandException: " +
884 ar.exception);
885 } else {
886 loge("getPreferredNetworkType: Unknown exception");
887 }
888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700889 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 break;
891
892 case CMD_SET_PREFERRED_NETWORK_TYPE:
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
895 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700896 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 break;
898
899 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
900 handleNullReturnEvent(msg, "setPreferredNetworkType");
901 break;
902
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000903 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
904 request = (MainThreadRequest)msg.obj;
905 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000907 break;
908
909 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
910 ar = (AsyncResult)msg.obj;
911 request = (MainThreadRequest)ar.userObj;
912 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000914 break;
915
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800916 case CMD_SET_VOICEMAIL_NUMBER:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
919 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800920 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
921 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800922 break;
923
924 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
925 handleNullReturnEvent(msg, "setVoicemailNumber");
926 break;
927
Stuart Scott54788802015-03-30 13:18:01 -0700928 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
931 request);
932 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
933 break;
934
935 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
936 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
937 break;
938
Shishir Agrawal302c8692015-06-19 13:49:39 -0700939 case CMD_PERFORM_NETWORK_SCAN:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
942 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
943 break;
944
Hall Liu27d24262020-09-18 19:04:59 -0700945 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700948 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
949 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
950 request.argument;
951 int callForwardingReason = args.first;
952 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800953 break;
Hall Liu27d24262020-09-18 19:04:59 -0700954 }
955 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700958 TelephonyManager.CallForwardingInfoCallback callback =
959 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
960 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800961 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700962 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800963 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
964 for (CallForwardInfo callForwardInfo : callForwardInfos) {
965 // Service Class is a bit mask per 3gpp 27.007. Search for
966 // any service for voice call.
967 if ((callForwardInfo.serviceClass
968 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700969 callForwardingInfo = new CallForwardingInfo(true,
970 callForwardInfo.reason,
971 callForwardInfo.number,
972 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800973 break;
974 }
975 }
976 // Didn't find a call forward info for voice call.
977 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700978 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
979 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800980 }
Hall Liu27d24262020-09-18 19:04:59 -0700981 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800982 } else {
983 if (ar.result == null) {
984 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
985 }
986 if (ar.exception != null) {
987 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
988 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700989 int errorCode = TelephonyManager
990 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700995 errorCode = TelephonyManager
996 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800997 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700998 errorCode = TelephonyManager
999 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001000 }
1001 }
Hall Liu27d24262020-09-18 19:04:59 -07001002 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001003 }
Shuo Qian4a594052020-01-23 11:59:30 -08001004 break;
Hall Liu27d24262020-09-18 19:04:59 -07001005 }
Shuo Qian4a594052020-01-23 11:59:30 -08001006
Hall Liu27d24262020-09-18 19:04:59 -07001007 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001010 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001011 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001012 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1013 request.argument).first;
1014 request.phone.setCallForwardingOption(
1015 callForwardingInfoToSet.isEnabled()
1016 ? CommandsInterface.CF_ACTION_ENABLE
1017 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001018 callForwardingInfoToSet.getReason(),
1019 callForwardingInfoToSet.getNumber(),
1020 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1021 break;
Hall Liu27d24262020-09-18 19:04:59 -07001022 }
Shuo Qian4a594052020-01-23 11:59:30 -08001023
Hall Liu27d24262020-09-18 19:04:59 -07001024 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001027 Consumer<Integer> callback =
1028 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1029 request.argument).second;
1030 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001031 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 int errorCode = TelephonyManager.CallForwardingInfoCallback
1033 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001034 if (ar.exception instanceof CommandException) {
1035 CommandException.Error error =
1036 ((CommandException) (ar.exception)).getCommandError();
1037 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager.CallForwardingInfoCallback
1039 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001040 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001041 errorCode = TelephonyManager.CallForwardingInfoCallback
1042 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001043 }
1044 }
1045 callback.accept(errorCode);
1046 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001047 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049 break;
Hall Liu27d24262020-09-18 19:04:59 -07001050 }
Shuo Qian4a594052020-01-23 11:59:30 -08001051
Hall Liu27d24262020-09-18 19:04:59 -07001052 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001053 request = (MainThreadRequest) msg.obj;
1054 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1055 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1056 break;
Hall Liu27d24262020-09-18 19:04:59 -07001057 }
Shuo Qian4a594052020-01-23 11:59:30 -08001058
Hall Liu27d24262020-09-18 19:04:59 -07001059 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001062 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001063 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1064 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001065 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001066 // Service Class is a bit mask per 3gpp 27.007.
1067 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001068 if (callForwardResults.length > 1
1069 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001070 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001071 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001072 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1073 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001074 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001075 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001076 }
1077 } else {
1078 if (ar.result == null) {
1079 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1080 }
1081 if (ar.exception != null) {
1082 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1083 }
1084 if (ar.exception instanceof CommandException) {
1085 CommandException.Error error =
1086 ((CommandException) (ar.exception)).getCommandError();
1087 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1088 callForwardingStatus =
1089 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1090 }
1091 }
1092 }
Hall Liu27d24262020-09-18 19:04:59 -07001093 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001094 break;
Hall Liu27d24262020-09-18 19:04:59 -07001095 }
Shuo Qian4a594052020-01-23 11:59:30 -08001096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001100 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1101 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001102 break;
Hall Liu27d24262020-09-18 19:04:59 -07001103 }
Shuo Qian4a594052020-01-23 11:59:30 -08001104
Hall Liu27d24262020-09-18 19:04:59 -07001105 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001108 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1109 Consumer<Integer> callback =
1110 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1111 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001112 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001113 if (ar.exception instanceof CommandException) {
1114 CommandException.Error error =
1115 ((CommandException) (ar.exception)).getCommandError();
1116 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1118 } else {
1119 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1120 }
1121 } else {
1122 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1123 }
1124 } else {
1125 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1126 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001127 }
Shuo Qian4a594052020-01-23 11:59:30 -08001128 break;
Hall Liu27d24262020-09-18 19:04:59 -07001129 }
Shuo Qian4a594052020-01-23 11:59:30 -08001130
Shishir Agrawal302c8692015-06-19 13:49:39 -07001131 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1132 ar = (AsyncResult) msg.obj;
1133 request = (MainThreadRequest) ar.userObj;
1134 CellNetworkScanResult cellScanResult;
1135 if (ar.exception == null && ar.result != null) {
1136 cellScanResult = new CellNetworkScanResult(
1137 CellNetworkScanResult.STATUS_SUCCESS,
1138 (List<OperatorInfo>) ar.result);
1139 } else {
1140 if (ar.result == null) {
1141 loge("getCellNetworkScanResults: Empty response");
1142 }
1143 if (ar.exception != null) {
1144 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1145 }
1146 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
1149 ((CommandException) (ar.exception)).getCommandError();
1150 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1151 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1152 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1153 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1154 }
1155 }
1156 cellScanResult = new CellNetworkScanResult(errorCode, null);
1157 }
1158 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001159 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 break;
1161
1162 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1163 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001164 ManualNetworkSelectionArgument selArg =
1165 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1167 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001168 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1169 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 break;
1171
1172 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null) {
1176 request.result = true;
1177 } else {
1178 request.result = false;
1179 loge("setNetworkSelectionModeManual " + ar.exception);
1180 }
1181 notifyRequester(request);
1182 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001183 break;
1184
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001185 case CMD_GET_MODEM_ACTIVITY_INFO:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001188 if (defaultPhone != null) {
1189 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001190 } else {
1191 ResultReceiver result = (ResultReceiver) request.argument;
1192 Bundle bundle = new Bundle();
1193 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001194 new ModemActivityInfo(0, 0, 0,
1195 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001196 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001197 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001198 break;
1199
Hall Liud0f208c2020-10-14 16:54:44 -07001200 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001201 ar = (AsyncResult) msg.obj;
1202 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001203 ResultReceiver result = (ResultReceiver) request.argument;
1204
Hall Liud0f208c2020-10-14 16:54:44 -07001205 ModemActivityInfo ret = null;
1206 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001208 // Update the last modem activity info and the result of the request.
1209 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1210 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001211 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001212 int[] txTimeMs = info.getTransmitTimeMillis();
1213 int[] lastModemTxTimeMs = mLastModemActivityInfo
1214 .getTransmitTimeMillis();
1215 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1216 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1217 }
Hall Liu49656c02020-10-09 19:00:11 -07001218 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001219 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1220 + mLastModemActivityInfo.getSleepTimeMillis());
1221 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1222 + mLastModemActivityInfo.getIdleTimeMillis());
1223 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1224 mLastModemActivityInfo.setReceiveTimeMillis(
1225 info.getReceiveTimeMillis()
1226 + mLastModemActivityInfo.getReceiveTimeMillis());
1227 }
Hall Liu49656c02020-10-09 19:00:11 -07001228 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 mLastModemActivityInfo.getSleepTimeMillis(),
1230 mLastModemActivityInfo.getIdleTimeMillis(),
1231 mLastModemActivityInfo.getTransmitTimeMillis(),
1232 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001233 } else {
1234 if (ar.result == null) {
1235 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001236 error = TelephonyManager.ModemActivityInfoException
1237 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 } else if (ar.exception instanceof CommandException) {
1239 loge("queryModemActivityInfo: CommandException: " +
1240 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001241 error = TelephonyManager.ModemActivityInfoException
1242 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 } else {
1244 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001245 error = TelephonyManager.ModemActivityInfoException
1246 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001247 }
1248 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001250 if (ret != null) {
1251 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1252 } else {
1253 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1254 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001255 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001257 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001258 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001259
Meng Wang1a7c35a2016-05-05 20:56:15 -07001260 case CMD_SET_ALLOWED_CARRIERS:
1261 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001262 CarrierRestrictionRules argument =
1263 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001264 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001265 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 break;
1267
1268 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
1271 if (ar.exception == null && ar.result != null) {
1272 request.result = ar.result;
1273 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001274 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1275 if (ar.exception instanceof CommandException) {
1276 loge("setAllowedCarriers: CommandException: " + ar.exception);
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1280 request.result =
1281 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 } else {
1284 loge("setAllowedCarriers: Unknown exception");
1285 }
1286 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001287 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001288 break;
1289
1290 case CMD_GET_ALLOWED_CARRIERS:
1291 request = (MainThreadRequest) msg.obj;
1292 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001293 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001294 break;
1295
1296 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
1299 if (ar.exception == null && ar.result != null) {
1300 request.result = ar.result;
1301 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001302 request.result = new IllegalStateException(
1303 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 if (ar.result == null) {
1305 loge("getAllowedCarriers: Empty response");
1306 } else if (ar.exception instanceof CommandException) {
1307 loge("getAllowedCarriers: CommandException: " +
1308 ar.exception);
1309 } else {
1310 loge("getAllowedCarriers: Unknown exception");
1311 }
1312 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001313 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001314 break;
1315
Nathan Haroldb3014052017-01-25 15:57:32 -08001316 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
1319 if (ar.exception == null && ar.result != null) {
1320 request.result = ar.result;
1321 } else {
1322 request.result = new IllegalArgumentException(
1323 "Failed to retrieve Forbidden Plmns");
1324 if (ar.result == null) {
1325 loge("getForbiddenPlmns: Empty response");
1326 } else {
1327 loge("getForbiddenPlmns: Unknown exception");
1328 }
1329 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001330 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001331 break;
1332
1333 case CMD_GET_FORBIDDEN_PLMNS:
1334 request = (MainThreadRequest) msg.obj;
1335 uiccCard = getUiccCardFromRequest(request);
1336 if (uiccCard == null) {
1337 loge("getForbiddenPlmns() UiccCard is null");
1338 request.result = new IllegalArgumentException(
1339 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001340 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001341 break;
1342 }
1343 Integer appType = (Integer) request.argument;
1344 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1345 if (uiccApp == null) {
1346 loge("getForbiddenPlmns() no app with specified type -- "
1347 + appType);
1348 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001350 break;
1351 } else {
1352 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1353 + " specified type -- " + appType);
1354 }
1355 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1356 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1357 onCompleted);
1358 break;
1359
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001360 case CMD_SWITCH_SLOTS:
1361 request = (MainThreadRequest) msg.obj;
1362 int[] physicalSlots = (int[]) request.argument;
1363 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1364 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1365 break;
1366
1367 case EVENT_SWITCH_SLOTS_DONE:
1368 ar = (AsyncResult) msg.obj;
1369 request = (MainThreadRequest) ar.userObj;
1370 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
1372 break;
1373 case CMD_GET_NETWORK_SELECTION_MODE:
1374 request = (MainThreadRequest) msg.obj;
1375 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1376 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1377 break;
1378
1379 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 if (ar.exception != null) {
1383 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1384 } else {
1385 int mode = ((int[]) ar.result)[0];
1386 if (mode == 0) {
1387 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1388 } else {
1389 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1390 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001391 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
1393 break;
1394 case CMD_GET_CDMA_ROAMING_MODE:
1395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1397 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1398 break;
1399 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception != null) {
1403 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1404 } else {
1405 request.result = ((int[]) ar.result)[0];
1406 }
1407 notifyRequester(request);
1408 break;
1409 case CMD_SET_CDMA_ROAMING_MODE:
1410 request = (MainThreadRequest) msg.obj;
1411 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1412 int mode = (int) request.argument;
1413 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1414 break;
1415 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1416 ar = (AsyncResult) msg.obj;
1417 request = (MainThreadRequest) ar.userObj;
1418 request.result = ar.exception == null;
1419 notifyRequester(request);
1420 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001421 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1424 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1425 break;
1426 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception != null) {
1430 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1431 } else {
1432 request.result = ((int[]) ar.result)[0];
1433 }
1434 notifyRequester(request);
1435 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1439 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001440 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1441 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 break;
1443 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 request.result = ar.exception == null;
1447 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001448 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001449 case CMD_GET_ALL_CELL_INFO:
1450 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001452 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 case EVENT_GET_ALL_CELL_INFO_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001457 // If a timeout occurs, the response will be null
1458 request.result = (ar.exception == null && ar.result != null)
1459 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 synchronized (request) {
1461 request.notifyAll();
1462 }
1463 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001464 case CMD_REQUEST_CELL_INFO_UPDATE:
1465 request = (MainThreadRequest) msg.obj;
1466 request.phone.requestCellInfoUpdate(request.workSource,
1467 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1468 break;
1469 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
1472 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1473 try {
1474 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001475 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001476 cb.onError(
1477 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1478 ar.exception.getClass().getName(),
1479 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001482 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 } else {
1484 // use the result as returned
1485 cb.onCellInfo((List<CellInfo>) ar.result);
1486 }
1487 } catch (RemoteException re) {
1488 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1489 }
1490 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001491 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 request = (MainThreadRequest) msg.obj;
1493 WorkSource ws = (WorkSource) request.argument;
1494 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001495 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001497 }
1498 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 if (ar.exception == null) {
1502 request.result = ar.result;
1503 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001504 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001506 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001507 }
1508
1509 synchronized (request) {
1510 request.notifyAll();
1511 }
1512 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001513 }
chen xu6dac5ab2018-10-26 17:39:23 -07001514 case CMD_MODEM_REBOOT:
1515 request = (MainThreadRequest) msg.obj;
1516 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001517 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001518 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001519 case EVENT_CMD_MODEM_REBOOT_DONE:
1520 handleNullReturnEvent(msg, "rebootModem");
1521 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001522 case CMD_REQUEST_ENABLE_MODEM:
1523 request = (MainThreadRequest) msg.obj;
1524 boolean enable = (boolean) request.argument;
1525 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001526 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001527 PhoneConfigurationManager.getInstance()
1528 .enablePhone(request.phone, enable, onCompleted);
1529 break;
1530 case EVENT_ENABLE_MODEM_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001534 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001535 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001536 if ((boolean) request.result) {
1537 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1538 updateModemStateMetrics();
1539 } else {
1540 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1541 + ar.exception);
1542 }
1543 notifyRequester(request);
1544 break;
1545 case CMD_GET_MODEM_STATUS:
1546 request = (MainThreadRequest) msg.obj;
1547 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1548 PhoneConfigurationManager.getInstance()
1549 .getPhoneStatusFromModem(request.phone, onCompleted);
1550 break;
1551 case EVENT_GET_MODEM_STATUS_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 int id = request.phone.getPhoneId();
1555 if (ar.exception == null && ar.result != null) {
1556 request.result = ar.result;
1557 //update the cache as modem status has changed
1558 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1559 (boolean) request.result);
1560 } else {
1561 // Return true if modem status cannot be retrieved. For most cases,
1562 // modem status is on. And for older version modems, GET_MODEM_STATUS
1563 // and disable modem are not supported. Modem is always on.
1564 // TODO: this should be fixed in R to support a third
1565 // status UNKNOWN b/131631629
1566 request.result = true;
1567 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1568 + ar.exception);
1569 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001570 notifyRequester(request);
1571 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001572 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1575 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1576 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1577 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1578 break;
1579 }
1580 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1581 ar = (AsyncResult) msg.obj;
1582 request = (MainThreadRequest) ar.userObj;
1583 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1584 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1585 args.second.accept(ar.exception == null);
1586 notifyRequester(request);
1587 break;
1588 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001589 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1592 Phone phone = getPhoneFromRequest(request);
1593 if (phone != null) {
1594 phone.getSystemSelectionChannels(onCompleted);
1595 } else {
1596 loge("getSystemSelectionChannels: No phone object");
1597 request.result = new ArrayList<RadioAccessSpecifier>();
1598 notifyRequester(request);
1599 }
1600 break;
1601 }
1602 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 if (ar.exception == null && ar.result != null) {
1606 request.result = ar.result;
1607 } else {
1608 request.result = new IllegalArgumentException(
1609 "Failed to retrieve system selection channels");
1610 if (ar.result == null) {
1611 loge("getSystemSelectionChannels: Empty response");
1612 } else {
1613 loge("getSystemSelectionChannels: Unknown exception");
1614 }
1615 }
1616 notifyRequester(request);
1617 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001618 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1619 ar = (AsyncResult) msg.obj;
1620 request = (MainThreadRequest) ar.userObj;
1621 if (ar.exception == null && ar.result != null) {
1622 request.result = ar.result;
1623 } else {
1624 request.result = -1;
1625 loge("Failed to set Forbidden Plmns");
1626 if (ar.result == null) {
1627 loge("setForbidenPlmns: Empty response");
1628 } else if (ar.exception != null) {
1629 loge("setForbiddenPlmns: Exception: " + ar.exception);
1630 request.result = -1;
1631 } else {
1632 loge("setForbiddenPlmns: Unknown exception");
1633 }
1634 }
1635 notifyRequester(request);
1636 break;
1637 case CMD_SET_FORBIDDEN_PLMNS:
1638 request = (MainThreadRequest) msg.obj;
1639 uiccCard = getUiccCardFromRequest(request);
1640 if (uiccCard == null) {
1641 loge("setForbiddenPlmns: UiccCard is null");
1642 request.result = -1;
1643 notifyRequester(request);
1644 break;
1645 }
1646 Pair<Integer, List<String>> setFplmnsArgs =
1647 (Pair<Integer, List<String>>) request.argument;
1648 appType = setFplmnsArgs.first;
1649 List<String> fplmns = setFplmnsArgs.second;
1650 uiccApp = uiccCard.getApplicationByType(appType);
1651 if (uiccApp == null) {
1652 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1653 request.result = -1;
1654 loge("Failed to get UICC App");
1655 notifyRequester(request);
1656 } else {
1657 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1658 ((SIMRecords) uiccApp.getIccRecords())
1659 .setForbiddenPlmns(onCompleted, fplmns);
1660 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001661 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001662 case CMD_ERASE_MODEM_CONFIG:
1663 request = (MainThreadRequest) msg.obj;
1664 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1665 defaultPhone.eraseModemConfig(onCompleted);
1666 break;
1667 case EVENT_ERASE_MODEM_CONFIG_DONE:
1668 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001669 break;
zoey chene02881a2019-12-30 16:11:23 +08001670
1671 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1674 Pair<String, String> changed = (Pair<String, String>) request.argument;
1675 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1676 changed.first, changed.second, onCompleted);
1677 break;
1678 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 if (ar.exception == null) {
1682 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1683 } else {
1684 request.result = msg.arg1;
1685 }
1686 notifyRequester(request);
1687 break;
1688
1689 case CMD_SET_ICC_LOCK_ENABLED:
1690 request = (MainThreadRequest) msg.obj;
1691 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1692 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1693 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1694 enabled.first, enabled.second, onCompleted);
1695 break;
1696 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
1699 if (ar.exception == null) {
1700 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1701 } else {
1702 request.result = msg.arg1;
1703 }
1704 notifyRequester(request);
1705 break;
1706
Peter Wangdafb9ac2020-01-15 14:13:38 -08001707 case MSG_NOTIFY_USER_ACTIVITY:
1708 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001709 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001710 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1711 getDefaultPhone().getContext().sendBroadcastAsUser(
1712 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1713 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001714
1715 case CMD_SET_DATA_THROTTLING: {
1716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1718 DataThrottlingRequest dataThrottlingRequest =
1719 (DataThrottlingRequest) request.argument;
1720 Phone phone = getPhoneFromRequest(request);
1721 if (phone != null) {
1722 phone.setDataThrottling(onCompleted,
1723 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1724 dataThrottlingRequest.getCompletionDurationMillis());
1725 } else {
1726 loge("setDataThrottling: No phone object");
1727 request.result =
1728 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1729 notifyRequester(request);
1730 }
1731
1732 break;
1733 }
1734 case EVENT_SET_DATA_THROTTLING_DONE:
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737
1738 if (ar.exception == null) {
1739 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1740 } else if (ar.exception instanceof CommandException) {
1741 loge("setDataThrottling: CommandException: " + ar.exception);
1742 CommandException.Error error =
1743 ((CommandException) (ar.exception)).getCommandError();
1744
1745 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1746 request.result = TelephonyManager
1747 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1748 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1749 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1750 } else {
1751 request.result =
1752 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1753 }
1754 } else {
1755 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1756 }
1757 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1758 notifyRequester(request);
1759 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001760
1761 case CMD_SET_SIM_POWER: {
1762 request = (MainThreadRequest) msg.obj;
1763 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1764 request = (MainThreadRequest) msg.obj;
1765 int stateToSet =
1766 ((Pair<Integer, IIntegerConsumer>)
1767 request.argument).first;
1768 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1769 break;
1770 }
1771 case EVENT_SET_SIM_POWER_DONE: {
1772 ar = (AsyncResult) msg.obj;
1773 request = (MainThreadRequest) ar.userObj;
1774 IIntegerConsumer callback =
1775 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1776 if (ar.exception != null) {
1777 loge("setSimPower exception: " + ar.exception);
1778 int errorCode = TelephonyManager.CallForwardingInfoCallback
1779 .RESULT_ERROR_UNKNOWN;
1780 if (ar.exception instanceof CommandException) {
1781 CommandException.Error error =
1782 ((CommandException) (ar.exception)).getCommandError();
1783 if (error == CommandException.Error.SIM_ERR) {
1784 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1785 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1786 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1787 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1788 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1789 } else {
1790 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1791 }
1792 }
1793 try {
1794 callback.accept(errorCode);
1795 } catch (RemoteException e) {
1796 // Ignore if the remote process is no longer available to call back.
1797 Log.w(LOG_TAG, "setSimPower: callback not available.");
1798 }
1799 } else {
1800 try {
1801 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1802 } catch (RemoteException e) {
1803 // Ignore if the remote process is no longer available to call back.
1804 Log.w(LOG_TAG, "setSimPower: callback not available.");
1805 }
1806 }
1807 break;
1808 }
1809
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 default:
1811 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1812 break;
1813 }
1814 }
Jake Hambye994d462014-02-03 13:10:13 -08001815
Pengquan Menga1bb6272018-09-06 09:59:22 -07001816 private void notifyRequester(MainThreadRequest request) {
1817 synchronized (request) {
1818 request.notifyAll();
1819 }
1820 }
1821
Jake Hambye994d462014-02-03 13:10:13 -08001822 private void handleNullReturnEvent(Message msg, String command) {
1823 AsyncResult ar = (AsyncResult) msg.obj;
1824 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1825 if (ar.exception == null) {
1826 request.result = true;
1827 } else {
1828 request.result = false;
1829 if (ar.exception instanceof CommandException) {
1830 loge(command + ": CommandException: " + ar.exception);
1831 } else {
1832 loge(command + ": Unknown exception");
1833 }
1834 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001835 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
1839 /**
1840 * Posts the specified command to be executed on the main thread,
1841 * waits for the request to complete, and returns the result.
1842 * @see #sendRequestAsync
1843 */
1844 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001845 return sendRequest(
1846 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001847 }
1848
1849 /**
1850 * Posts the specified command to be executed on the main thread,
1851 * waits for the request to complete, and returns the result.
1852 * @see #sendRequestAsync
1853 */
1854 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1855 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001856 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001857 }
1858
1859 /**
1860 * Posts the specified command to be executed on the main thread,
1861 * waits for the request to complete, and returns the result.
1862 * @see #sendRequestAsync
1863 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001864 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001865 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001866 }
1867
1868 /**
1869 * Posts the specified command to be executed on the main thread,
1870 * waits for the request to complete, and returns the result.
1871 * @see #sendRequestAsync
1872 */
Nathan Harold92bed182018-10-12 18:16:49 -07001873 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1874 return sendRequest(command, argument, subId, null, workSource);
1875 }
1876
1877 /**
1878 * Posts the specified command to be executed on the main thread,
1879 * waits for the request to complete, and returns the result.
1880 * @see #sendRequestAsync
1881 */
1882 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1883 return sendRequest(
1884 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1885 }
1886
1887 /**
1888 * Posts the specified command to be executed on the main thread,
1889 * waits for the request to complete, and returns the result.
1890 * @see #sendRequestAsync
1891 */
1892 private Object sendRequest(
1893 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1895 throw new RuntimeException("This method will deadlock if called from the main thread.");
1896 }
1897
Nathan Harold92bed182018-10-12 18:16:49 -07001898 MainThreadRequest request = null;
1899 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1900 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1901 } else if (phone != null) {
1902 request = new MainThreadRequest(argument, phone, workSource);
1903 } else {
1904 request = new MainThreadRequest(argument, subId, workSource);
1905 }
1906
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 Message msg = mMainThreadHandler.obtainMessage(command, request);
1908 msg.sendToTarget();
1909
1910 // Wait for the request to complete
1911 synchronized (request) {
1912 while (request.result == null) {
1913 try {
1914 request.wait();
1915 } catch (InterruptedException e) {
1916 // Do nothing, go back and wait until the request is complete
1917 }
1918 }
1919 }
1920 return request.result;
1921 }
1922
1923 /**
1924 * Asynchronous ("fire and forget") version of sendRequest():
1925 * Posts the specified command to be executed on the main thread, and
1926 * returns immediately.
1927 * @see #sendRequest
1928 */
1929 private void sendRequestAsync(int command) {
1930 mMainThreadHandler.sendEmptyMessage(command);
1931 }
1932
1933 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001934 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001935 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001936 */
1937 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001938 sendRequestAsync(command, argument, null, null);
1939 }
1940
1941 /**
1942 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1943 * @see {@link #sendRequest(int,Object)}
1944 */
1945 private void sendRequestAsync(
1946 int command, Object argument, Phone phone, WorkSource workSource) {
1947 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001948 Message msg = mMainThreadHandler.obtainMessage(command, request);
1949 msg.sendToTarget();
1950 }
1951
1952 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 * Initialize the singleton PhoneInterfaceManager instance.
1954 * This is only done once, at startup, from PhoneApp.onCreate().
1955 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001956 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 synchronized (PhoneInterfaceManager.class) {
1958 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001959 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 } else {
1961 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1962 }
1963 return sInstance;
1964 }
1965 }
1966
1967 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001968 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001971 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001972 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1974 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001975 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001976 mTelephonySharedPreferences =
1977 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001978 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001979 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001980 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001981
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 publish();
1983 }
1984
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001985 private Phone getDefaultPhone() {
1986 Phone thePhone = getPhone(getDefaultSubscription());
1987 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1988 }
1989
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 private void publish() {
1991 if (DBG) log("publish: " + this);
1992
Peter Wangc035ce42020-01-08 21:00:22 -08001993 TelephonyFrameworkInitializer
1994 .getTelephonyServiceManager()
1995 .getTelephonyServiceRegisterer()
1996 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
Stuart Scott584921c2015-01-15 17:10:34 -08001999 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002000 if (request.phone != null) {
2001 return request.phone;
2002 } else {
2003 return getPhoneFromSubId(request.subId);
2004 }
2005 }
2006
2007 private Phone getPhoneFromSubId(int subId) {
2008 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2009 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002010 }
2011
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002012 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2013 Phone phone = getPhoneFromRequest(request);
2014 return phone == null ? null :
2015 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2016 }
2017
Wink Saville36469e72014-06-11 15:17:00 -07002018 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002020 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022
Naina Nallurid63128d2019-09-17 14:10:30 -07002023 private void sendEraseModemConfig(Phone phone) {
2024 if (phone != null) {
2025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2026 mApp, phone.getSubId(), "eraseModemConfig");
2027 final long identity = Binder.clearCallingIdentity();
2028 try {
2029 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2030 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2031 } finally {
2032 Binder.restoreCallingIdentity(identity);
2033 }
2034 }
2035 }
2036
Peter Wang44b186e2020-01-13 23:33:09 -08002037 private boolean isImsAvailableOnDevice() {
2038 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2039 if (pm == null) {
2040 // For some reason package manger is not available.. This will fail internally anyway,
2041 // so do not throw error and allow.
2042 return true;
2043 }
2044 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2045 }
2046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002048 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002049 }
2050
Wink Savilleb564aae2014-10-23 10:18:09 -07002051 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 if (DBG) log("dial: " + number);
2053 // No permission check needed here: This is just a wrapper around the
2054 // ACTION_DIAL intent, which is available to any app since it puts up
2055 // the UI before it does anything.
2056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 String url = createTelUrl(number);
2060 if (url == null) {
2061 return;
2062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064 // PENDING: should we just silently fail if phone is offhook or ringing?
2065 PhoneConstants.State state = mCM.getState(subId);
2066 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2067 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2068 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2069 mApp.startActivity(intent);
2070 }
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
2074 }
2075
2076 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002077 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002078 }
2079
Wink Savilleb564aae2014-10-23 10:18:09 -07002080 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 if (DBG) log("call: " + number);
2082
2083 // This is just a wrapper around the ACTION_CALL intent, but we still
2084 // need to do a permission check since we're calling startActivity()
2085 // from the context of the phone app.
2086 enforceCallPermission();
2087
Jordan Liu1617b712019-07-10 15:06:26 -07002088 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 != AppOpsManager.MODE_ALLOWED) {
2090 return;
2091 }
2092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002093 final long identity = Binder.clearCallingIdentity();
2094 try {
2095 String url = createTelUrl(number);
2096 if (url == null) {
2097 return;
2098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100 boolean isValid = false;
2101 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2102 if (slist != null) {
2103 for (SubscriptionInfo subInfoRecord : slist) {
2104 if (subInfoRecord.getSubscriptionId() == subId) {
2105 isValid = true;
2106 break;
2107 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002108 }
Wink Saville08874612014-08-31 19:19:58 -07002109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110 if (!isValid) {
2111 return;
2112 }
Wink Saville08874612014-08-31 19:19:58 -07002113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2115 intent.putExtra(SUBSCRIPTION_KEY, subId);
2116 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2117 mApp.startActivity(intent);
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Wink Savilleb564aae2014-10-23 10:18:09 -07002123 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002124 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002125 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2126 }
2127
Wink Savilleb564aae2014-10-23 10:18:09 -07002128 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002129 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002130 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2131 }
2132
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002135
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2139 checkSimPin.start();
2140 return checkSimPin.unlockSim(null, pin);
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
Wink Savilleb564aae2014-10-23 10:18:09 -07002146 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002148
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2152 checkSimPuk.start();
2153 return checkSimPuk.unlockSim(puk, pin);
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
2156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 }
2158
2159 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002160 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 * a synchronous one.
2162 */
2163 private static class UnlockSim extends Thread {
2164
2165 private final IccCard mSimCard;
2166
2167 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002168 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2169 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
2171 // For replies from SimCard interface
2172 private Handler mHandler;
2173
2174 // For async handler to identify request type
2175 private static final int SUPPLY_PIN_COMPLETE = 100;
2176
2177 public UnlockSim(IccCard simCard) {
2178 mSimCard = simCard;
2179 }
2180
2181 @Override
2182 public void run() {
2183 Looper.prepare();
2184 synchronized (UnlockSim.this) {
2185 mHandler = new Handler() {
2186 @Override
2187 public void handleMessage(Message msg) {
2188 AsyncResult ar = (AsyncResult) msg.obj;
2189 switch (msg.what) {
2190 case SUPPLY_PIN_COMPLETE:
2191 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2192 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002193 mRetryCount = msg.arg1;
2194 if (ar.exception != null) {
2195 if (ar.exception instanceof CommandException &&
2196 ((CommandException)(ar.exception)).getCommandError()
2197 == CommandException.Error.PASSWORD_INCORRECT) {
2198 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002199 } //When UiccCardApp dispose,handle message and return exception
2200 else if (ar.exception instanceof CommandException &&
2201 ((CommandException) (ar.exception)).getCommandError()
2202 == CommandException.Error.ABORTED) {
2203 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002204 } else {
2205 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2206 }
2207 } else {
2208 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 mDone = true;
2211 UnlockSim.this.notifyAll();
2212 }
2213 break;
2214 }
2215 }
2216 };
2217 UnlockSim.this.notifyAll();
2218 }
2219 Looper.loop();
2220 }
2221
2222 /*
2223 * Use PIN or PUK to unlock SIM card
2224 *
2225 * If PUK is null, unlock SIM card with PIN
2226 *
2227 * If PUK is not null, unlock SIM card with PUK and set PIN code
2228 */
Wink Saville9de0f752013-10-22 19:04:03 -07002229 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230
2231 while (mHandler == null) {
2232 try {
2233 wait();
2234 } catch (InterruptedException e) {
2235 Thread.currentThread().interrupt();
2236 }
2237 }
2238 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2239
2240 if (puk == null) {
2241 mSimCard.supplyPin(pin, callback);
2242 } else {
2243 mSimCard.supplyPuk(puk, pin, callback);
2244 }
2245
2246 while (!mDone) {
2247 try {
2248 Log.d(LOG_TAG, "wait for done");
2249 wait();
2250 } catch (InterruptedException e) {
2251 // Restore the interrupted status
2252 Thread.currentThread().interrupt();
2253 }
2254 }
2255 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002256 int[] resultArray = new int[2];
2257 resultArray[0] = mResult;
2258 resultArray[1] = mRetryCount;
2259 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261 }
2262
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002263 /**
2264 * This method has been removed due to privacy and stability concerns.
2265 */
2266 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002268 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2269 return;
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
Nathan Harold1f889d82020-06-04 17:05:26 -07002272 @Override
2273 public void updateServiceLocationWithPackageName(String callingPackage) {
2274 mApp.getSystemService(AppOpsManager.class)
2275 .checkPackage(Binder.getCallingUid(), callingPackage);
2276
2277 final int targetSdk = getTargetSdk(callingPackage);
2278 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2279 // Callers targeting S have no business invoking this method.
2280 return;
2281 }
2282
2283 LocationAccessPolicy.LocationPermissionResult locationResult =
2284 LocationAccessPolicy.checkLocationPermission(mApp,
2285 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2286 .setCallingPackage(callingPackage)
2287 .setCallingFeatureId(null)
2288 .setCallingPid(Binder.getCallingPid())
2289 .setCallingUid(Binder.getCallingUid())
2290 .setMethod("updateServiceLocation")
2291 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2292 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2293 .build());
2294 // Apps that lack location permission have no business calling this method;
2295 // however, because no permission was declared in the public API, denials must
2296 // all be "soft".
2297 switch (locationResult) {
2298 case DENIED_HARD: /* fall through */
2299 case DENIED_SOFT:
2300 return;
2301 }
2302
2303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 final long identity = Binder.clearCallingIdentity();
2305 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002306 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002308 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 }
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002315 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 @Override
2317 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002318 return isRadioOnWithFeature(callingPackage, null);
2319 }
2320
2321
2322 @Override
2323 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2324 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2325 callingFeatureId);
2326 }
2327
2328 @Deprecated
2329 @Override
2330 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2331 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002335 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2336 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002338 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 return false;
2340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return isRadioOnForSubscriber(subId);
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002348 }
2349
2350 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 final Phone phone = getPhone(subId);
2354 if (phone != null) {
2355 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2356 } else {
2357 return false;
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 }
2363
2364 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002365 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
Wink Saville36469e72014-06-11 15:17:00 -07002367
Wink Savilleb564aae2014-10-23 10:18:09 -07002368 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 if (phone != null) {
2375 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002379 }
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
2382 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002383 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002384 }
2385
Wink Savilleb564aae2014-10-23 10:18:09 -07002386 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002387 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 if (phone == null) {
2393 return false;
2394 }
2395 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2396 toggleRadioOnOffForSubscriber(subId);
2397 }
2398 return true;
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
Wink Saville36469e72014-06-11 15:17:00 -07002403
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002404 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002405 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002406 /*
2407 * If any of the Radios are available, it will need to be
2408 * shutdown. So return true if any Radio is available.
2409 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2413 Phone phone = PhoneFactory.getPhone(i);
2414 if (phone != null && phone.isRadioAvailable()) return true;
2415 }
2416 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2417 return false;
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002420 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002421 }
2422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002424 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 enforceModifyPermission();
2426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2430 logv("Shutting down Phone " + i);
2431 shutdownRadioUsingPhoneId(i);
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002435 }
2436 }
2437
2438 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002439 Phone phone = PhoneFactory.getPhone(phoneId);
2440 if (phone != null && phone.isRadioAvailable()) {
2441 phone.shutdownRadio();
2442 }
2443 }
2444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2451 if (defaultPhone != null) {
2452 defaultPhone.setRadioPower(turnOn);
2453 return true;
2454 } else {
2455 loge("There's no default phone.");
2456 return false;
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002460 }
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Wink Savilleb564aae2014-10-23 10:18:09 -07002463 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465
2466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 final Phone phone = getPhone(subId);
2469 if (phone != null) {
2470 phone.setRadioPower(turnOn);
2471 return true;
2472 } else {
2473 return false;
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
Wink Saville36469e72014-06-11 15:17:00 -07002480 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002481 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 public boolean enableDataConnectivity() {
2483 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484
2485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 int subId = mSubscriptionController.getDefaultDataSubId();
2488 final Phone phone = getPhone(subId);
2489 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002490 phone.getDataEnabledSettings().setDataEnabled(
2491 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 return true;
2493 } else {
2494 return false;
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
Wink Saville36469e72014-06-11 15:17:00 -07002501 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 public boolean disableDataConnectivity() {
2504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 int subId = mSubscriptionController.getDefaultDataSubId();
2509 final Phone phone = getPhone(subId);
2510 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002511 phone.getDataEnabledSettings().setDataEnabled(
2512 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 return true;
2514 } else {
2515 return false;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002523 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 final Phone phone = getPhone(subId);
2527 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002528 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 } else {
2530 return false;
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 }
2536
2537 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002538 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
2540
pkanwarae03a6b2016-11-06 20:37:09 -08002541 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 enforceCallPermission();
2543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2547 return;
2548 }
2549 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2550 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
pkanwar32d516d2016-10-14 19:37:38 -07002554 };
2555
Wink Savilleb564aae2014-10-23 10:18:09 -07002556 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558
2559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2562 return false;
2563 }
2564 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002571 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002572 }
2573
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002574 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 Phone phone = PhoneFactory.getPhone(slotIndex);
2578 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2579 PhoneConstantConversions.convertCallState(phone.getState());
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
2582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002586 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002587 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2588 }
2589
2590 @Override
2591 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002594 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 if (phone != null) {
2596 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2597 } else {
2598 return PhoneConstantConversions.convertDataState(
2599 PhoneConstants.DataState.DISCONNECTED);
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605
Sanket Padawe356d7632015-06-22 14:03:32 -07002606 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002607 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002608 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2609 }
2610
2611 @Override
2612 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002615 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 if (phone != null) {
2617 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2618 } else {
2619 return TelephonyManager.DATA_ACTIVITY_NONE;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
2626 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002627 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002629 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002630
2631 LocationAccessPolicy.LocationPermissionResult locationResult =
2632 LocationAccessPolicy.checkLocationPermission(mApp,
2633 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2634 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002635 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002636 .setCallingPid(Binder.getCallingPid())
2637 .setCallingUid(Binder.getCallingUid())
2638 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002639 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002640 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2641 .build());
2642 switch (locationResult) {
2643 case DENIED_HARD:
2644 throw new SecurityException("Not allowed to access cell location");
2645 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002646 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2647 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002654 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002655 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Svetoslav64fad262015-04-14 14:35:21 -07002659 }
2660
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002662 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002663 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2664 // registered cell info, so return a NULL country instead.
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002667 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2668 // Get default phone in this case.
2669 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2670 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002671 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002673 if (phone == null) return "";
2674 ServiceStateTracker sst = phone.getServiceStateTracker();
2675 if (sst == null) return "";
2676 LocaleTracker lt = sst.getLocaleTracker();
2677 if (lt == null) return "";
2678 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2679 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2680 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002684 }
2685
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002686 /**
2687 * This method was removed due to potential issues caused by performing partial
2688 * updates of service state, and lack of a credible use case.
2689 *
2690 * This has the ability to break the telephony implementation by disabling notification of
2691 * changes in device connectivity. DO NOT USE THIS!
2692 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 public void enableLocationUpdates() {
2695 mApp.enforceCallingOrSelfPermission(
2696 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002699 /**
2700 * This method was removed due to potential issues caused by performing partial
2701 * updates of service state, and lack of a credible use case.
2702 *
2703 * This has the ability to break the telephony implementation by disabling notification of
2704 * changes in device connectivity. DO NOT USE THIS!
2705 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 @Override
2707 public void disableLocationUpdates() {
2708 mApp.enforceCallingOrSelfPermission(
2709 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 }
2711
Nathan Harold31d7ff32018-10-15 20:20:30 -07002712 /**
2713 * Returns the target SDK version number for a given package name.
2714 *
Nathan Haroldec184742019-07-10 17:04:16 -07002715 * This call MUST be invoked before clearing the calling UID.
2716 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002717 * @return target SDK if the package is found or INT_MAX.
2718 */
2719 private int getTargetSdk(String packageName) {
2720 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002721 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002722 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002723 if (ai != null) return ai.targetSdkVersion;
2724 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002725 loge("Failed to get package info for pkg="
2726 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002727 }
2728 return Integer.MAX_VALUE;
2729 }
2730
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 @Override
2732 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002733 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2734 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002735 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002736 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2737 throw new SecurityException(
2738 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2739 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002740
Jordan Liu1617b712019-07-10 15:06:26 -07002741 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2743 return null;
2744 }
Svetoslav64fad262015-04-14 14:35:21 -07002745
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002746 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002748 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002749 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
Nathan Haroldf180aac2018-06-01 18:43:55 -07002751 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2752 for (CellInfo ci : info) {
2753 if (ci instanceof CellInfoGsm) {
2754 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2755 } else if (ci instanceof CellInfoWcdma) {
2756 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002759 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 }
2761
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002762 private List<CellInfo> getCachedCellInfo() {
2763 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2764 for (Phone phone : PhoneFactory.getPhones()) {
2765 List<CellInfo> info = phone.getAllCellInfo();
2766 if (info != null) cellInfos.addAll(info);
2767 }
2768 return cellInfos;
2769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770
2771 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002772 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002773 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002774 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002775
2776 LocationAccessPolicy.LocationPermissionResult locationResult =
2777 LocationAccessPolicy.checkLocationPermission(mApp,
2778 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2779 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002780 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002781 .setCallingPid(Binder.getCallingPid())
2782 .setCallingUid(Binder.getCallingUid())
2783 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002784 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002785 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2786 .build());
2787 switch (locationResult) {
2788 case DENIED_HARD:
2789 throw new SecurityException("Not allowed to access cell info");
2790 case DENIED_SOFT:
2791 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002794 final int targetSdk = getTargetSdk(callingPackage);
2795 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2796 return getCachedCellInfo();
2797 }
2798
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002799 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2804 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002805 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002806 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 if (info != null) cellInfos.addAll(info);
2808 }
2809 return cellInfos;
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813 }
2814
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002815 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002816 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2817 String callingFeatureId) {
2818 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2819 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002820 }
2821
2822 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002823 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2824 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002825 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002826 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002827 }
2828
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002829 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2830 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002831 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002832 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002833
2834 LocationAccessPolicy.LocationPermissionResult locationResult =
2835 LocationAccessPolicy.checkLocationPermission(mApp,
2836 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2837 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002838 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002839 .setCallingPid(Binder.getCallingPid())
2840 .setCallingUid(Binder.getCallingUid())
2841 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002842 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2843 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002844 .build());
2845 switch (locationResult) {
2846 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002847 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2848 // Safetynet logging for b/154934934
2849 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002851 throw new SecurityException("Not allowed to access cell info");
2852 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002853 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2854 // Safetynet logging for b/154934934
2855 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2856 }
Nathan Harold5320c422019-05-09 10:26:08 -07002857 try {
2858 cb.onCellInfo(new ArrayList<CellInfo>());
2859 } catch (RemoteException re) {
2860 // Drop without consequences
2861 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002862 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002863 }
2864
Nathan Harolda939a962019-05-09 10:13:47 -07002865
2866 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002867 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2868
2869 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2870 }
2871
2872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002874 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002875 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Shishir Agrawala9f32182016-04-12 12:00:16 -07002885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002886 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002887 Phone phone = PhoneFactory.getPhone(slotIndex);
2888 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002889 return null;
2890 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002891 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002892 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002893 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002894 return null;
2895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 return phone.getImei();
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002903 }
2904
2905 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002906 public String getTypeAllocationCodeForSlot(int slotIndex) {
2907 Phone phone = PhoneFactory.getPhone(slotIndex);
2908 String tac = null;
2909 if (phone != null) {
2910 String imei = phone.getImei();
2911 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2912 }
2913 return tac;
2914 }
2915
2916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002918 Phone phone = PhoneFactory.getPhone(slotIndex);
2919 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002920 return null;
2921 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922
Jeff Davidson913390f2018-02-23 17:11:49 -08002923 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002924 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002925 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002926 return null;
2927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 return phone.getMeid();
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
Jack Yu2af8d712017-03-15 17:14:14 -07002935 }
2936
2937 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002938 public String getManufacturerCodeForSlot(int slotIndex) {
2939 Phone phone = PhoneFactory.getPhone(slotIndex);
2940 String manufacturerCode = null;
2941 if (phone != null) {
2942 String meid = phone.getMeid();
2943 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2944 }
2945 return manufacturerCode;
2946 }
2947
2948 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002949 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2950 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002951 Phone phone = PhoneFactory.getPhone(slotIndex);
2952 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002953 return null;
2954 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002955 int subId = phone.getSubId();
2956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002957 mApp, subId, callingPackage, callingFeatureId,
2958 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002959 return null;
2960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 return phone.getDeviceSvn();
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002968 }
2969
fionaxu43304da2017-11-27 22:51:16 -08002970 @Override
2971 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = getPhone(subId);
2975 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
fionaxu43304da2017-11-27 22:51:16 -08002979 }
2980
2981 @Override
2982 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 final Phone phone = getPhone(subId);
2986 return phone == null ? null : phone.getCarrierName();
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
fionaxu43304da2017-11-27 22:51:16 -08002990 }
2991
calvinpanffe225e2018-11-01 19:43:06 +08002992 @Override
chen xu0026ca62019-03-06 15:28:50 -08002993 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002998 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
chen xu0026ca62019-03-06 15:28:50 -08003005 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003009 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
3013 }
3014
chen xu651eec72018-11-11 19:03:44 -08003015 @Override
chen xu864e11c2018-12-06 22:10:03 -08003016 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3017 if (!isSubscriptionMccMnc) {
3018 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3019 }
chen xu651eec72018-11-11 19:03:44 -08003020 final Phone phone = PhoneFactory.getPhone(slotIndex);
3021 if (phone == null) {
3022 return TelephonyManager.UNKNOWN_CARRIER_ID;
3023 }
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 //
3033 // Internal helper methods.
3034 //
3035
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003036 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3038 *
3039 * @throws SecurityException if the caller does not have the required permission
3040 */
3041 private void enforceModifyPermission() {
3042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3043 }
3044
Shuo Qiancd19c462020-01-16 20:51:11 -08003045 /**
3046 * Make sure the caller is system.
3047 *
3048 * @throws SecurityException if the caller is not system.
3049 */
3050 private void enforceSystemCaller() {
3051 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3052 throw new SecurityException("Caller must be system");
3053 }
3054 }
3055
Shuo Qian3b6ee772019-11-13 17:43:31 -08003056 private void enforceActiveEmergencySessionPermission() {
3057 mApp.enforceCallingOrSelfPermission(
3058 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3059 }
3060
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 /**
3062 * Make sure the caller has the CALL_PHONE permission.
3063 *
3064 * @throws SecurityException if the caller does not have the required permission
3065 */
3066 private void enforceCallPermission() {
3067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3068 }
3069
paulhu5a773602019-08-23 19:17:33 +08003070 private void enforceSettingsPermission() {
3071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 private String createTelUrl(String number) {
3075 if (TextUtils.isEmpty(number)) {
3076 return null;
3077 }
3078
Jake Hambye994d462014-02-03 13:10:13 -08003079 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 }
3081
Ihab Awadf9e92732013-12-05 18:02:52 -08003082 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3084 }
3085
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003086 private static void logv(String msg) {
3087 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3088 }
3089
Ihab Awadf9e92732013-12-05 18:02:52 -08003090 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3092 }
3093
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003094 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003096 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003097 }
3098
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003100 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 final Phone phone = PhoneFactory.getPhone(slotIndex);
3104 if (phone == null) {
3105 return PhoneConstants.PHONE_TYPE_NONE;
3106 } else {
3107 return phone.getPhoneType();
3108 }
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 }
3113
3114 /**
3115 * Returns the CDMA ERI icon index to display
3116 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003118 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3119 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3120 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003121 }
3122
Sanket Padawe356d7632015-06-22 14:03:32 -07003123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003124 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3125 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003127 mApp, subId, callingPackage, callingFeatureId,
3128 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 return -1;
3130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
3136 return phone.getCdmaEriIconIndex();
3137 } else {
3138 return -1;
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
3145 /**
3146 * Returns the CDMA ERI icon mode,
3147 * 0 - ON
3148 * 1 - FLASHING
3149 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003151 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3152 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3153 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003154 }
3155
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003157 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3158 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003160 mApp, subId, callingPackage, callingFeatureId,
3161 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003162 return -1;
3163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 if (phone != null) {
3169 return phone.getCdmaEriIconMode();
3170 } else {
3171 return -1;
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 }
3177
3178 /**
3179 * Returns the CDMA ERI text,
3180 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003182 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3183 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3184 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003185 }
3186
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003188 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3189 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003191 mApp, subId, callingPackage, callingFeatureId,
3192 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003193 return null;
3194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 final Phone phone = getPhone(subId);
3199 if (phone != null) {
3200 return phone.getCdmaEriText();
3201 } else {
3202 return null;
3203 }
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208
3209 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003210 * Returns the CDMA MDN.
3211 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003213 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3215 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003220 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 return phone.getLine1Number();
3222 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 return null;
3225 }
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003228 }
3229 }
3230
3231 /**
3232 * Returns the CDMA MIN.
3233 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003235 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3237 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238
3239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 final Phone phone = getPhone(subId);
3242 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3243 return phone.getCdmaMin();
3244 } else {
3245 return null;
3246 }
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003249 }
3250 }
3251
Hall Liud892bec2018-11-30 14:51:45 -08003252 @Override
3253 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3254 INumberVerificationCallback callback, String callingPackage) {
3255 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3256 != PERMISSION_GRANTED) {
3257 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3258 }
3259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3260
3261 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3262 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3263 throw new SecurityException("Calling package must be configured in the device config");
3264 }
3265
3266 if (range == null) {
3267 throw new NullPointerException("Range must be non-null");
3268 }
3269
3270 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003271 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003272
3273 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3274 }
3275
Junda Liuca05d5d2014-08-14 22:36:34 -07003276 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 * Returns true if CDMA provisioning needs to run.
3278 */
3279 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 final long identity = Binder.clearCallingIdentity();
3281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 }
3287
3288 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003289 * Sets the voice mail number of a given subId.
3290 */
3291 @Override
3292 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003293 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3294 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3299 new Pair<String, String>(alphaTag, number), new Integer(subId));
3300 return success;
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003304 }
3305
Ta-wei Yen87c49842016-05-13 21:19:52 -07003306 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003307 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003309 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3310 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003311 if (!TextUtils.equals(callingPackage, systemDialer)) {
3312 throw new SecurityException("caller must be system dialer");
3313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314
3315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3318 if (phoneAccountHandle == null) {
3319 return null;
3320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003324 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003325 }
3326
3327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003328 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3329 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003332 mApp, subId, callingPackage, callingFeatureId,
3333 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003334 return null;
3335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003337 final long identity = Binder.clearCallingIdentity();
3338 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003343 }
3344
3345 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003346 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3347 VisualVoicemailSmsFilterSettings settings) {
3348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003353 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003357 }
3358
3359 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003360 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003370 }
3371
3372 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003373 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3374 String callingPackage, int subId) {
3375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003384 }
3385
3386 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003387 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003397 }
3398
3399 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003400 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3401 String callingAttributionTag, int subId, String number, int port, String text,
3402 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003403 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003404 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003405 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003406 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003407 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3408 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003409 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003410
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003411 /**
fionaxu0152e512016-11-14 13:36:14 -08003412 * Sets the voice activation state of a given subId.
3413 */
3414 @Override
3415 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3417 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 final Phone phone = getPhone(subId);
3422 if (phone != null) {
3423 phone.setVoiceActivationState(activationState);
3424 } else {
3425 loge("setVoiceActivationState fails with invalid subId: " + subId);
3426 }
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003429 }
3430 }
3431
3432 /**
3433 * Sets the data activation state of a given subId.
3434 */
3435 @Override
3436 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3438 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 final Phone phone = getPhone(subId);
3443 if (phone != null) {
3444 phone.setDataActivationState(activationState);
3445 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003446 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 }
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003450 }
3451 }
3452
3453 /**
3454 * Returns the voice activation state of a given subId.
3455 */
3456 @Override
3457 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
fionaxu0152e512016-11-14 13:36:14 -08003460 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 if (phone != null) {
3464 return phone.getVoiceActivationState();
3465 } else {
3466 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3467 }
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003470 }
3471 }
3472
3473 /**
3474 * Returns the data activation state of a given subId.
3475 */
3476 @Override
3477 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
fionaxu0152e512016-11-14 13:36:14 -08003480 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 if (phone != null) {
3484 return phone.getDataActivationState();
3485 } else {
3486 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3487 }
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003490 }
3491 }
3492
3493 /**
Wink Saville36469e72014-06-11 15:17:00 -07003494 * Returns the unread count of voicemails for a subId
3495 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003496 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003497 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3498 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003500 mApp, subId, callingPackage, callingFeatureId,
3501 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003502 return 0;
3503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = getPhone(subId);
3507 if (phone != null) {
3508 return phone.getVoiceMessageCount();
3509 } else {
3510 return 0;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 }
3516
3517 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003518 * returns true, if the device is in a state where both voice and data
3519 * are supported simultaneously. This can change based on location or network condition.
3520 */
3521 @Override
3522 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 final Phone phone = getPhone(subId);
3526 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003530 }
3531
3532 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003533 * Send the dialer code if called from the current default dialer or the caller has
3534 * carrier privilege.
3535 * @param inputCode The dialer code to send
3536 */
3537 @Override
3538 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003541 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3542 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003543 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003544 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
fionaxu235cc5e2017-03-06 22:25:57 -08003554 }
3555
Pengquan Menga1bb6272018-09-06 09:59:22 -07003556 @Override
3557 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003558 TelephonyPermissions
3559 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3560 mApp, subId, "getNetworkSelectionMode");
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 if (!isActiveSubscription(subId)) {
3564 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3565 }
3566 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003570 }
3571
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003573 public boolean isInEmergencySmsMode() {
3574 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 for (Phone phone : PhoneFactory.getPhones()) {
3578 if (phone.isInEmergencySmsMode()) {
3579 return true;
3580 }
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
3585 return false;
3586 }
3587
shilu366312e2019-12-17 09:28:10 -08003588 /**
3589 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3590 * @param subId The subscription to use to check the configuration.
3591 * @param c The callback that will be used to send the result.
3592 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003593 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003594 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3595 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003596 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3597 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003598
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003599 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3601 "IMS not available on device.");
3602 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 final long token = Binder.clearCallingIdentity();
3604 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (ImsException e) {
3609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 } finally {
3611 Binder.restoreCallingIdentity(token);
3612 }
3613 }
3614
shilu366312e2019-12-17 09:28:10 -08003615 /**
3616 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3617 * @param subId The subscription to use to check the configuration.
3618 * @param c The callback that will be used to send the result.
3619 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003621 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003622 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3623 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3625 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3626 }
Meng Wangafbc5852019-09-19 17:37:13 -07003627 final long token = Binder.clearCallingIdentity();
3628 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003629 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003630 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3631 .removeRegistrationCallbackForSubscription(c, subId);
3632 } catch (ImsException e) {
3633 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3634 + "is inactive, ignoring unregister.");
3635 // If the subscription is no longer active, just return, since the callback
3636 // will already have been removed internally.
3637 } finally {
3638 Binder.restoreCallingIdentity(token);
3639 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 }
3641
Brad Ebingera34a6c22019-10-22 17:36:18 -07003642 /**
3643 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3644 */
3645 @Override
3646 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3647 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3648 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3650 "IMS not available on device.");
3651 }
3652 final long token = Binder.clearCallingIdentity();
3653 try {
3654 Phone phone = getPhone(subId);
3655 if (phone == null) {
3656 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3657 + subId + "'");
3658 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3659 }
3660 phone.getImsRegistrationState(regState -> {
3661 try {
3662 consumer.accept((regState == null)
3663 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3664 } catch (RemoteException e) {
3665 // Ignore if the remote process is no longer available to call back.
3666 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3667 }
3668 });
3669 } finally {
3670 Binder.restoreCallingIdentity(token);
3671 }
3672 }
3673
3674 /**
3675 * Get the transport type for the IMS service registration state.
3676 */
3677 @Override
3678 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003679 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3680 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003681 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3683 "IMS not available on device.");
3684 }
3685 final long token = Binder.clearCallingIdentity();
3686 try {
3687 Phone phone = getPhone(subId);
3688 if (phone == null) {
3689 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3690 + subId + "'");
3691 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3692 }
3693 phone.getImsRegistrationTech(regTech -> {
3694 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3695 int regTechConverted = (regTech == null)
3696 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3697 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3698 regTechConverted);
3699 try {
3700 consumer.accept(regTechConverted);
3701 } catch (RemoteException e) {
3702 // Ignore if the remote process is no longer available to call back.
3703 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3704 }
3705 });
3706 } finally {
3707 Binder.restoreCallingIdentity(token);
3708 }
3709 }
3710
shilu366312e2019-12-17 09:28:10 -08003711 /**
3712 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3713 * @param subId The subscription to use to check the configuration.
3714 * @param c The callback that will be used to send the result.
3715 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003717 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3718 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003719 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3720 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003721 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3722 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3723 "IMS not available on device.");
3724 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3726 final long token = Binder.clearCallingIdentity();
3727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (ImsException e) {
3731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 } finally {
3733 Binder.restoreCallingIdentity(token);
3734 }
3735 }
3736
shilu366312e2019-12-17 09:28:10 -08003737 /**
3738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3739 * @param subId The subscription to use to check the configuration.
3740 * @param c The callback that will be used to send the result.
3741 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003743 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003744 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3745 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3748 }
Meng Wangafbc5852019-09-19 17:37:13 -07003749
3750 final long token = Binder.clearCallingIdentity();
3751 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003752 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003754 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003755 } catch (ImsException e) {
3756 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3757 + "is inactive, ignoring unregister.");
3758 // If the subscription is no longer active, just return, since the callback
3759 // will already have been removed internally.
3760 } finally {
3761 Binder.restoreCallingIdentity(token);
3762 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 }
3764
3765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003766 public boolean isCapable(int subId, int capability, int regTech) {
3767 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3769 final long token = Binder.clearCallingIdentity();
3770 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003772 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003773 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3775 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003777 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3778 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
3782 }
3783
3784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003785 public boolean isAvailable(int subId, int capability, int regTech) {
3786 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 final long token = Binder.clearCallingIdentity();
3788 try {
3789 Phone phone = getPhone(subId);
3790 if (phone == null) return false;
3791 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003792 } catch (com.android.ims.ImsException e) {
3793 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3794 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 } finally {
3796 Binder.restoreCallingIdentity(token);
3797 }
3798 }
3799
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003800 /**
3801 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3802 * subscription.
3803 * @param subId The subscription to use to check the configuration.
3804 * @param callback The callback that will be used to send the result.
3805 * @param capability The MmTelFeature capability that will be used to send the result.
3806 * @param transportType The transport type of the MmTelFeature capability.
3807 */
3808 @Override
3809 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3810 int transportType) {
3811 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3812 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3813 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3814 "IMS not available on device.");
3815 }
3816 final long token = Binder.clearCallingIdentity();
3817 try {
3818 int slotId = getSlotIndex(subId);
3819 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3820 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3821 + subId + "'");
3822 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3823 }
3824 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3825 transportType, aBoolean -> {
3826 try {
3827 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3828 } catch (RemoteException e) {
3829 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3830 + "running. Ignore");
3831 }
3832 });
3833 } finally {
3834 Binder.restoreCallingIdentity(token);
3835 }
3836 }
3837
shilu366312e2019-12-17 09:28:10 -08003838 /**
3839 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3840 * @param subId The subscription to use to check the configuration.
3841 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 @Override
3843 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003844 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3845 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003846
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3848 final long token = Binder.clearCallingIdentity();
3849 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003850 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003852 } catch (ImsException e) {
3853 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 } finally {
3855 Binder.restoreCallingIdentity(token);
3856 }
3857 }
3858
3859 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003860 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003862 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003866 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003868 } catch (ImsException e) {
3869 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
3873 }
3874
shilu366312e2019-12-17 09:28:10 -08003875 /**
3876 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3877 * @param subId The subscription to use to check the configuration.
3878 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003880 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003881 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3882 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003886 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3887 } catch (ImsException e) {
3888 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
3892 }
3893
3894 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003895 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003897 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003902 } catch (ImsException e) {
3903 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
3907 }
3908
shilu366312e2019-12-17 09:28:10 -08003909 /**
3910 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3911 * @param subId The subscription to use to check the configuration.
3912 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 @Override
3914 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003915 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3916 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003922 } catch (ImsException e) {
3923 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
3927 }
3928
3929 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003930 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003932 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003936 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003937 } catch (ImsException e) {
3938 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
3942 }
3943
shilu366312e2019-12-17 09:28:10 -08003944 /**
3945 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3946 * @param subId The subscription to use to check the configuration.
3947 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 @Override
3949 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003950 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3951 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
3964 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003965 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003967 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003973 } catch (ImsException e) {
3974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
3980 @Override
3981 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3983 "setVoWiFiNonPersistent");
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003988 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003989 } catch (ImsException e) {
3990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
3994 }
3995
shilu366312e2019-12-17 09:28:10 -08003996 /**
3997 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3998 * @param subId The subscription to use to check the configuration.
3999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 @Override
4001 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004002 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4003 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
4016 @Override
4017 public void setVoWiFiModeSetting(int subId, int mode) {
4018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4019 "setVoWiFiModeSetting");
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004023 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004025 } catch (ImsException e) {
4026 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
4030 }
4031
4032 @Override
4033 public int getVoWiFiRoamingModeSetting(int subId) {
4034 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
4048 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4050 "setVoWiFiRoamingModeSetting");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
4063 @Override
4064 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4066 "setRttCapabilityEnabled");
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004070 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4071 } catch (ImsException e) {
4072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
4076 }
4077
shilu366312e2019-12-17 09:28:10 -08004078 /**
4079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4080 * @param subId The subscription to use to check the configuration.
4081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 @Override
4083 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004084 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4085 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
4096 }
4097
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004098 @Override
4099 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4100 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004103 if (!isImsAvailableOnDevice()) {
4104 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4105 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004106 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004109 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004110 } catch (ImsException e) {
4111 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
4117 @Override
4118 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4119 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4120 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004121 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4122 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4123 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004127 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004129 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4130 + "is inactive, ignoring unregister.");
4131 // If the subscription is no longer active, just return, since the callback will already
4132 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
allenwtsu99c623b2020-01-03 18:24:23 +08004138
4139 private void checkModifyPhoneStatePermission(int subId, String message) {
4140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4141 message);
4142 }
4143
4144 private boolean isImsProvisioningRequired(int subId, int capability,
4145 boolean isMmtelCapability) {
4146 Phone phone = getPhone(subId);
4147 if (phone == null) {
4148 loge("phone instance null for subid " + subId);
4149 return false;
4150 }
4151 if (isMmtelCapability) {
4152 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4153 return false;
4154 }
4155 } else {
4156 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4157 return false;
4158 }
4159 }
4160 return true;
4161 }
4162
4163 @Override
4164 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4165 boolean isProvisioned) {
4166 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4167
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4171 if (!isImsProvisioningRequired(subId, capability, false)) {
4172 return;
4173 }
4174
4175 // this capability requires provisioning, route to the correct API.
4176 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4177 switch (capability) {
4178 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4179 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4180 ims.setEabProvisioned(isProvisioned);
4181 break;
4182 default: {
4183 throw new IllegalArgumentException("Tried to set provisioning for "
4184 + "rcs capability '" + capability + "', which does not require "
4185 + "provisioning.");
4186 }
4187 }
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191
4192 }
4193
4194
4195 @Override
4196 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4197 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4201 if (!isImsProvisioningRequired(subId, capability, false)) {
4202 return true;
4203 }
4204
4205 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4206 switch (capability) {
4207 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4208 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4209 return ims.isEabProvisionedOnDevice();
4210
4211 default: {
4212 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4213 + "capability '" + capability + "', which does not require "
4214 + "provisioning.");
4215 }
4216 }
4217
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
4221 }
4222
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004223 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4225 boolean isProvisioned) {
4226 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4227 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4228 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4229 }
allenwtsu99c623b2020-01-03 18:24:23 +08004230 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004234 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004235 return;
4236 }
4237
4238 // this capability requires provisioning, route to the correct API.
4239 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4240 switch (capability) {
4241 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4242 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4243 ims.setVolteProvisioned(isProvisioned);
4244 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4245 ims.setWfcProvisioned(isProvisioned);
4246 }
4247 break;
4248 }
4249 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4250 // There is currently no difference in VT provisioning type.
4251 ims.setVtProvisioned(isProvisioned);
4252 break;
4253 }
4254 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4255 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4256 // change the capability of the feature instead if needed.
4257 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4258 == isProvisioned) {
4259 // No change in provisioning.
4260 return;
4261 }
4262 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4263 try {
4264 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004266 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4267 + ", Exception" + e.getMessage());
4268 }
4269 break;
4270 }
4271 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004272 throw new IllegalArgumentException("Tried to set provisioning for "
4273 + "MmTel capability '" + capability + "', which does not require "
4274 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004275 }
4276 }
4277
4278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
4283 @Override
4284 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4285 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4286 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4287 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4288 }
4289 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004293 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004294 return true;
4295 }
4296
4297 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4298 switch (capability) {
4299 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4300 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4301 return ims.isVolteProvisionedOnDevice();
4302 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4303 return ims.isWfcProvisionedOnDevice();
4304 }
4305 // This should never happen, since we are checking tech above to make sure it
4306 // is either LTE or IWLAN.
4307 throw new IllegalArgumentException("Invalid radio technology for voice "
4308 + "capability.");
4309 }
4310 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4311 // There is currently no difference in VT provisioning type.
4312 return ims.isVtProvisionedOnDevice();
4313 }
4314 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4315 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4316 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4317 }
4318 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004319 throw new IllegalArgumentException(
4320 "Tried to get provisioning for MmTel capability '" + capability
4321 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004322 }
4323 }
4324
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 @Override
4331 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4332 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4333 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4334 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4335 }
4336 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4337 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4338 return (provisionedBits & capability) > 0;
4339 }
4340
4341 @Override
4342 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4343 boolean isProvisioned) {
4344 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4345 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4346 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4347 }
4348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4349 "setProvisioningStatusForCapability");
4350 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4351 // If the current provisioning status for capability already matches isProvisioned,
4352 // do nothing.
4353 if (((provisionedBits & capability) > 0) == isProvisioned) {
4354 return;
4355 }
4356 if (isProvisioned) {
4357 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4358 } else {
4359 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4360 }
4361 }
4362
4363 /**
4364 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4365 * technology. The bitfield should mirror the bitfield defined by
4366 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4367 */
4368 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4369 String key = getMmTelProvisioningKey(subId, tech);
4370 // Default is no capabilities are provisioned.
4371 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4372 }
4373
4374 /**
4375 * Sets the MmTel capability provisioning bitfield (defined by
4376 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4377 * technology specified.
4378 *
4379 * Note: This is a synchronous command and should not be called on UI thread.
4380 */
4381 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4382 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4383 String key = getMmTelProvisioningKey(subId, tech);
4384 editor.putInt(key, newField);
4385 editor.commit();
4386 }
4387
4388 private static String getMmTelProvisioningKey(int subId, int tech) {
4389 // resulting key is provision_ims_mmtel_{subId}_{tech}
4390 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4391 }
4392
4393 /**
4394 * Query CarrierConfig to see if the specified capability requires provisioning for the
4395 * carrier associated with the subscription id.
4396 */
4397 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4398 int capability) {
4399 CarrierConfigManager configManager = new CarrierConfigManager(context);
4400 PersistableBundle c = configManager.getConfigForSubId(subId);
4401 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004402 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004403 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4404 false);
4405 boolean requireVoiceVtProvisioning = c.getBoolean(
4406 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4407
4408 // First check to make sure that the capability requires provisioning.
4409 switch (capability) {
4410 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4411 // intentional fallthrough
4412 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4413 if (requireVoiceVtProvisioning) {
4414 // Voice and Video requires provisioning
4415 return true;
4416 }
4417 break;
4418 }
4419 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4420 if (requireUtProvisioning) {
4421 // UT requires provisioning
4422 return true;
4423 }
4424 break;
4425 }
4426 }
4427 return false;
4428 }
4429
allenwtsu99c623b2020-01-03 18:24:23 +08004430 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4431 int capability) {
4432 CarrierConfigManager configManager = new CarrierConfigManager(context);
4433 PersistableBundle c = configManager.getConfigForSubId(subId);
4434
4435 boolean requireRcsProvisioning = c.getBoolean(
4436 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4437
4438 // First check to make sure that the capability requires provisioning.
4439 switch (capability) {
4440 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4441 // intentional fallthrough
4442 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4443 if (requireRcsProvisioning) {
4444 // OPTION or PRESENCE requires provisioning
4445 return true;
4446 }
4447 break;
4448 }
4449 }
4450 return false;
4451 }
4452
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004453 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004454 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4456 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4457 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004458 enforceReadPrivilegedPermission("getImsProvisioningInt");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004462 int slotId = getSlotIndex(subId);
4463 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4464 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4465 + subId + "' for key:" + key);
4466 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4467 }
4468 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004469 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004470 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4471 + subId + "' for key:" + key);
4472 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477
4478 @Override
4479 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004480 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4481 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4482 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004483 enforceReadPrivilegedPermission("getImsProvisioningString");
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004487 int slotId = getSlotIndex(subId);
4488 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4489 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4490 + subId + "' for key:" + key);
4491 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4492 }
4493 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004495 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4496 + subId + "' for key:" + key);
4497 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
4503 @Override
4504 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004505 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4506 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4507 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4509 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004510 final long identity = Binder.clearCallingIdentity();
4511 try {
4512 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 int slotId = getSlotIndex(subId);
4514 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4515 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4516 + subId + "' for key:" + key);
4517 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4518 }
4519 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4522 + "' for key:" + key);
4523 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4532 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4533 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4535 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004539 int slotId = getSlotIndex(subId);
4540 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4541 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4542 + subId + "' for key:" + key);
4543 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4544 }
4545 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004546 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4548 + "' for key:" + key);
4549 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 int slotId = SubscriptionManager.getSlotIndex(subId);
4557 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4559 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 }
4561 return slotId;
4562 }
4563
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004564 private int getSlotIndex(int subId) {
4565 int slotId = SubscriptionManager.getSlotIndex(subId);
4566 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4567 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4568 }
4569 return slotId;
4570 }
4571
Wink Saville36469e72014-06-11 15:17:00 -07004572 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004573 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004574 */
4575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004576 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4577 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004578 final int targetSdk = getTargetSdk(callingPackage);
4579 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004580 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004581 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004582 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004583 mApp, subId, callingPackage, callingFeatureId,
4584 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4586 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 final Phone phone = getPhone(subId);
4591 if (phone != null) {
4592 return phone.getServiceState().getDataNetworkType();
4593 } else {
4594 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4595 }
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004599 }
4600
4601 /**
4602 * Returns the data network type
4603 */
4604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004605 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4606 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4607 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004608 }
4609
4610 /**
4611 * Returns the data network type for a subId
4612 */
4613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004614 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4615 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004617 mApp, subId, callingPackage, callingFeatureId,
4618 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004619 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4620 }
4621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 final Phone phone = getPhone(subId);
4625 if (phone != null) {
4626 return phone.getServiceState().getDataNetworkType();
4627 } else {
4628 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4629 }
4630 } finally {
4631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004633 }
4634
4635 /**
Wink Saville36469e72014-06-11 15:17:00 -07004636 * Returns the Voice network type for a subId
4637 */
4638 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004639 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4640 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004642 mApp, subId, callingPackage, callingFeatureId,
4643 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004644 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4645 }
4646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 final Phone phone = getPhone(subId);
4650 if (phone != null) {
4651 return phone.getServiceState().getVoiceNetworkType();
4652 } else {
4653 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4654 }
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004658 }
4659
4660 /**
4661 * @return true if a ICC card is present
4662 */
4663 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004664 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004665 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4666 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004667 }
4668
4669 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004670 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004671 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004672 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004673 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 final long identity = Binder.clearCallingIdentity();
4675 try {
4676 final Phone phone = PhoneFactory.getPhone(slotIndex);
4677 if (phone != null) {
4678 return phone.getIccCard().hasIccCard();
4679 } else {
4680 return false;
4681 }
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004685 }
4686
4687 /**
4688 * Return if the current radio is LTE on CDMA. This
4689 * is a tri-state return value as for a period of time
4690 * the mode may be unknown.
4691 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004692 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004693 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004694 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004695 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004697 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4698 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4699 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004700 }
4701
Sanket Padawe356d7632015-06-22 14:03:32 -07004702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004703 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4704 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004705 try {
4706 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4707 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004708 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4709 }
4710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 final Phone phone = getPhone(subId);
4714 if (phone == null) {
4715 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4716 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004717 return TelephonyProperties.lte_on_cdma_device()
4718 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 }
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004722 }
Wink Saville36469e72014-06-11 15:17:00 -07004723 }
4724
Wink Saville36469e72014-06-11 15:17:00 -07004725 /**
4726 * {@hide}
4727 * Returns Default subId, 0 in the case of single standby.
4728 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004729 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004730 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004731 }
4732
Shishir Agrawala9f32182016-04-12 12:00:16 -07004733 private int getSlotForDefaultSubscription() {
4734 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4735 }
4736
Wink Savilleb564aae2014-10-23 10:18:09 -07004737 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004738 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004739 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004740
Pengquan Menge92a50d2018-09-21 15:54:48 -07004741 private boolean isActiveSubscription(int subId) {
4742 return mSubscriptionController.isActiveSubId(subId);
4743 }
4744
Ihab Awadf2177b72013-11-25 13:33:23 -08004745 /**
4746 * @see android.telephony.TelephonyManager.WifiCallingChoices
4747 */
4748 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004751 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4753 getWhenToMakeWifiCallsDefaultPreference());
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004757 }
4758
4759 /**
4760 * @see android.telephony.TelephonyManager.WifiCallingChoices
4761 */
4762 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004766 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004771 }
4772
Sailesh Nepald1e68152013-12-12 19:08:02 -08004773 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004774 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004775 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004776 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004777
Jordan Liu4c733742019-02-28 12:03:40 -08004778 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4779 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4780 if (phoneId == -1) {
4781 throw new IllegalArgumentException("Given slot index: " + slotIndex
4782 + " does not correspond to an active phone");
4783 }
4784 return PhoneFactory.getPhone(phoneId);
4785 }
4786
Shishir Agrawal566b7612013-10-28 14:41:00 -07004787 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004788 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4789 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4791 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004793 if (DBG) {
4794 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4795 }
4796 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4797 p2);
4798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004799
Jordan Liu4c733742019-02-28 12:03:40 -08004800
4801 @Override
4802 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4803 int slotIndex, String callingPackage, String aid, int p2) {
4804 enforceModifyPermission();
4805 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4806 if (DBG) {
4807 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4808 }
4809 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4810 callingPackage, aid, p2);
4811 }
4812
4813 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4814 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 if (TextUtils.equals(ISDR_AID, aid)) {
4818 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004819 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4820 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 if (bestComponent == null
4822 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4823 loge("The calling package is not allowed to access ISD-R.");
4824 throw new SecurityException(
4825 "The calling package is not allowed to access ISD-R.");
4826 }
Derek Tan740e1672017-06-27 14:56:27 -07004827 }
Derek Tan740e1672017-06-27 14:56:27 -07004828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004830 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4831 null /* workSource */);
4832 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 return response;
4834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004837 }
4838
4839 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004840 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004843 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4844 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004846
Jordan Liu4c733742019-02-28 12:03:40 -08004847 @Override
4848 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4849 enforceModifyPermission();
4850 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4851 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4852 channel);
4853 }
4854
4855 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 final long identity = Binder.clearCallingIdentity();
4857 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 if (channel < 0) {
4859 return false;
4860 }
Jordan Liu4c733742019-02-28 12:03:40 -08004861 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4862 null /* workSource */);
4863 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 return success;
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004867 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004868 }
4869
4870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004871 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004872 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004875 if (DBG) {
4876 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4877 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4878 + p3 + " data=" + data);
4879 }
4880 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4881 command, p1, p2, p3, data);
4882 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004883
Jordan Liu4c733742019-02-28 12:03:40 -08004884 @Override
4885 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4886 int command, int p1, int p2, int p3, String data) {
4887 enforceModifyPermission();
4888 if (DBG) {
4889 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4890 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4891 + p3 + " data=" + data);
4892 }
4893 return iccTransmitApduLogicalChannelWithPermission(
4894 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4895 data);
4896 }
4897
4898 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4899 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004902 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 return "";
4904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004907 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4908 null /* workSource */);
4909 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 // Append the returned status code to the end of the response payload.
4912 String s = Integer.toHexString(
4913 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4914 if (response.payload != null) {
4915 s = IccUtils.bytesToHexString(response.payload) + s;
4916 }
4917 return s;
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004920 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004921 }
Jake Hambye994d462014-02-03 13:10:13 -08004922
Evan Charltonc66da362014-05-16 14:06:40 -07004923 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004924 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4925 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4927 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004929 if (DBG) {
4930 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4931 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4932 }
4933 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4934 cla, command, p1, p2, p3, data);
4935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004936
Jordan Liu4c733742019-02-28 12:03:40 -08004937 @Override
4938 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4939 int command, int p1, int p2, int p3, String data) {
4940 enforceModifyPermission();
4941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4942 if (DBG) {
4943 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4944 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4945 + " data=" + data);
4946 }
4947
4948 return iccTransmitApduBasicChannelWithPermission(
4949 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4950 p2, p3, data);
4951 }
4952
4953 // open APDU basic channel assuming the caller has sufficient permissions
4954 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4955 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4959 && TextUtils.equals(ISDR_AID, data)) {
4960 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004961 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4962 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 if (bestComponent == null
4964 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4965 loge("The calling package is not allowed to select ISD-R.");
4966 throw new SecurityException(
4967 "The calling package is not allowed to select ISD-R.");
4968 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004969 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004972 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4973 null /* workSource */);
4974 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 // Append the returned status code to the end of the response payload.
4977 String s = Integer.toHexString(
4978 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4979 if (response.payload != null) {
4980 s = IccUtils.bytesToHexString(response.payload) + s;
4981 }
4982 return s;
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004985 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004986 }
4987
4988 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004989 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004990 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4992 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 if (DBG) {
4997 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4998 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4999 }
5000
5001 IccIoResult response =
5002 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5003 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5004 subId);
5005
5006 if (DBG) {
5007 log("Exchange SIM_IO [R]" + response);
5008 }
5009
5010 byte[] result = null;
5011 int length = 2;
5012 if (response.payload != null) {
5013 length = 2 + response.payload.length;
5014 result = new byte[length];
5015 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5016 } else {
5017 result = new byte[length];
5018 }
5019
5020 result[length - 1] = (byte) response.sw2;
5021 result[length - 2] = (byte) response.sw1;
5022 return result;
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005025 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005026 }
5027
Nathan Haroldb3014052017-01-25 15:57:32 -08005028 /**
5029 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5030 * on a particular subscription
5031 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005032 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5033 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005035 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005036 return null;
5037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
5041 if (appType != TelephonyManager.APPTYPE_USIM
5042 && appType != TelephonyManager.APPTYPE_SIM) {
5043 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5044 return null;
5045 }
5046 Object response = sendRequest(
5047 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5048 if (response instanceof String[]) {
5049 return (String[]) response;
5050 }
yincheng zhao2737e882019-09-06 17:06:54 -07005051 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005053 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005056 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005057 }
5058
yincheng zhao2737e882019-09-06 17:06:54 -07005059 /**
5060 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5061 * subscription.
5062 *
5063 * @param subId the id of the subscription.
5064 * @param appType the uicc app type, must be USIM or SIM.
5065 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5066 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005067 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005068 * @return number of fplmns that is successfully written to the SIM.
5069 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005070 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5071 String callingFeatureId) {
5072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5073 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005074 if (DBG) logv("no permissions for setForbiddenplmns");
5075 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5076 }
5077 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5078 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5079 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5080 }
5081 if (fplmns == null) {
5082 throw new IllegalArgumentException("Fplmn List provided is null");
5083 }
5084 for (String fplmn : fplmns) {
5085 if (!CellIdentity.isValidPlmn(fplmn)) {
5086 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5087 }
5088 }
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 Object response = sendRequest(
5092 CMD_SET_FORBIDDEN_PLMNS,
5093 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5094 subId);
5095 return (int) response;
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
5099 }
5100
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005101 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005102 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5104 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5109 if (response.payload == null) {
5110 return "";
5111 }
Evan Charltonc66da362014-05-16 14:06:40 -07005112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 // Append the returned status code to the end of the response payload.
5114 String s = Integer.toHexString(
5115 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5116 s = IccUtils.bytesToHexString(response.payload) + s;
5117 return s;
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
Evan Charltonc66da362014-05-16 14:06:40 -07005121 }
5122
Jake Hambye994d462014-02-03 13:10:13 -08005123 /**
5124 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5125 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5126 *
5127 * @param itemID the ID of the item to read
5128 * @return the NV item as a String, or null on error.
5129 */
5130 @Override
5131 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005132 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5134 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135
5136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005139 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5141 return value;
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144 }
Jake Hambye994d462014-02-03 13:10:13 -08005145 }
5146
5147 /**
5148 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5149 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5150 *
5151 * @param itemID the ID of the item to read
5152 * @param itemValue the value to write, as a String
5153 * @return true on success; false on any failure
5154 */
5155 @Override
5156 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5159 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5164 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005165 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5167 return success;
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
Jake Hambye994d462014-02-03 13:10:13 -08005171 }
5172
5173 /**
5174 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5175 * Used for device configuration by some CDMA operators.
5176 *
5177 * @param preferredRoamingList byte array containing the new PRL
5178 * @return true on success; false on any failure
5179 */
5180 @Override
5181 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5183 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5188 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5189 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5190 return success;
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Jake Hambye994d462014-02-03 13:10:13 -08005194 }
5195
5196 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005197 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005198 * Used for device configuration by some CDMA operators.
5199 *
chen xu6dac5ab2018-10-26 17:39:23 -07005200 * @param slotIndex - device slot.
5201 *
Jake Hambye994d462014-02-03 13:10:13 -08005202 * @return true on success; false on any failure
5203 */
5204 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005205 public boolean resetModemConfig(int slotIndex) {
5206 Phone phone = PhoneFactory.getPhone(slotIndex);
5207 if (phone != null) {
5208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
chen xu6dac5ab2018-10-26 17:39:23 -07005211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5214 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5215 return success;
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 }
chen xu6dac5ab2018-10-26 17:39:23 -07005220 return false;
5221 }
5222
5223 /**
5224 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5225 *
5226 * @param slotIndex - device slot.
5227 *
5228 * @return true on success; false on any failure
5229 */
5230 @Override
5231 public boolean rebootModem(int slotIndex) {
5232 Phone phone = PhoneFactory.getPhone(slotIndex);
5233 if (phone != null) {
5234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5235 mApp, phone.getSubId(), "rebootModem");
5236
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5240 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5241 return success;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
5245 }
5246 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005247 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005248
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005249 public String[] getPcscfAddress(String apnType, String callingPackage,
5250 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005251 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5253 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005254 return new String[0];
5255 }
5256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
5258 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005259 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Wink Saville36469e72014-06-11 15:17:00 -07005263 }
5264
Brad Ebinger51f743a2017-01-23 13:50:20 -08005265 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005266 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5267 * {@link #disableIms(int)}.
5268 * @param slotIndex device slot.
5269 */
5270 public void resetIms(int slotIndex) {
5271 enforceModifyPermission();
5272
5273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (mImsResolver == null) {
5276 // may happen if the does not support IMS.
5277 return;
5278 }
5279 mImsResolver.disableIms(slotIndex);
5280 mImsResolver.enableIms(slotIndex);
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
5286 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005287 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5288 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005289 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005290 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005295 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005296 // may happen if the device does not support IMS.
5297 return;
5298 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005299 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005303 }
5304
5305 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005306 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5307 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005308 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005309 public void disableIms(int slotId) {
5310 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005314 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005315 // may happen if the device does not support IMS.
5316 return;
5317 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005318 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005322 }
5323
5324 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005325 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5326 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005327 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005328 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005329 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005330 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005334 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5336 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005337 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005338 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005342 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005343 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005344 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5345 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005346 @Override
5347 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005348 enforceModifyPermission();
5349
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005353 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
5357 }
5358
5359 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005360 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005361 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005362 */
5363 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5364 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365
5366 final long identity = Binder.clearCallingIdentity();
5367 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005368 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005369 // may happen if the device does not support IMS.
5370 return null;
5371 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005372 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005376 }
5377
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005378 /**
5379 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005380 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005381 */
5382 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384
5385 final long identity = Binder.clearCallingIdentity();
5386 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005387 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005388 // may happen if the device does not support IMS.
5389 return null;
5390 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005391 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 } finally {
5393 Binder.restoreCallingIdentity(identity);
5394 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005395 }
5396
Brad Ebinger884c07b2018-02-15 16:17:40 -08005397 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005398 * Sets the ImsService Package Name that Telephony will bind to.
5399 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005400 * @param slotIndex the slot ID that the ImsService should bind for.
5401 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005402 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005403 * @param featureTypes An integer array of feature types associated with a packageName.
5404 * @param packageName The name of the package that the current configuration will be replaced
5405 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005406 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005407 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005408 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5409 int[] featureTypes, String packageName) {
5410 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5411 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5413 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005414 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 final long identity = Binder.clearCallingIdentity();
5417 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005418 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005419 // may happen if the device does not support IMS.
5420 return false;
5421 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005422 Map<Integer, String> featureConfig = new HashMap<>();
5423 for (int featureType : featureTypes) {
5424 featureConfig.put(featureType, packageName);
5425 }
5426 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5427 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 } finally {
5429 Binder.restoreCallingIdentity(identity);
5430 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005431 }
5432
5433 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005434 * Clears any carrier ImsService overrides for the slot index specified that were previously
5435 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5436 *
5437 * This should only be used for testing.
5438 *
5439 * @param slotIndex the slot ID that the ImsService should bind for.
5440 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5441 */
5442 @Override
5443 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5444 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5445 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5446 "clearCarrierImsServiceOverride");
5447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5448 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5449 "clearCarrierImsServiceOverride");
5450
5451 final long identity = Binder.clearCallingIdentity();
5452 try {
5453 if (mImsResolver == null) {
5454 // may happen if the device does not support IMS.
5455 return false;
5456 }
5457 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
5461 }
5462
5463 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005464 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005465 *
5466 * @param slotId The slot that the ImsService is associated with.
5467 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5468 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005469 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005470 * @return the package name of the ImsService configuration.
5471 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005472 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5473 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005474 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005475 TelephonyPermissions
5476 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5477 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5478 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005483 // may happen if the device does not support IMS.
5484 return "";
5485 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005486 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005487 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5488 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005492 }
5493
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005494 /**
5495 * Get the MmTelFeature state associated with the requested subscription id.
5496 * @param subId The subscription that the MmTelFeature is associated with.
5497 * @param callback A callback with an integer containing the
5498 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5499 */
5500 @Override
5501 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5502 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5503 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5505 "IMS not available on device.");
5506 }
5507 final long token = Binder.clearCallingIdentity();
5508 try {
5509 int slotId = getSlotIndex(subId);
5510 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5511 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5512 + subId + "'");
5513 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5514 }
5515 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5516 try {
5517 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5518 } catch (RemoteException e) {
5519 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5520 + "Ignore");
5521 }
5522 });
5523 } finally {
5524 Binder.restoreCallingIdentity(token);
5525 }
5526 }
5527
Wink Saville36469e72014-06-11 15:17:00 -07005528 public void setImsRegistrationState(boolean registered) {
5529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005533 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Wink Saville36469e72014-06-11 15:17:00 -07005537 }
5538
5539 /**
Stuart Scott54788802015-03-30 13:18:01 -07005540 * Set the network selection mode to automatic.
5541 *
5542 */
5543 @Override
5544 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5546 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547
5548 final long identity = Binder.clearCallingIdentity();
5549 try {
shilufc958392020-01-20 11:36:01 -08005550 if (!isActiveSubscription(subId)) {
5551 return;
5552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5554 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
Stuart Scott54788802015-03-30 13:18:01 -07005558 }
5559
Jack Yud10cdd42020-09-28 20:28:01 -07005560 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005561 * Ask the radio to connect to the input network and change selection mode to manual.
5562 *
5563 * @param subId the id of the subscription.
5564 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5565 * the operator to attach to.
5566 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5567 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5568 * normal network selection next time.
5569 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005570 */
5571 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005572 public boolean setNetworkSelectionModeManual(
5573 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5575 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005576
5577 if (!isActiveSubscription(subId)) {
5578 return false;
5579 }
5580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005583 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005585 if (DBG) {
5586 log("setNetworkSelectionModeManual: subId: " + subId
5587 + " operator: " + operatorInfo);
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005593 }
shilu84f6e8b2019-12-19 13:58:01 -08005594 /**
5595 * Get the manual network selection
5596 *
5597 * @param subId the id of the subscription.
5598 *
5599 * @return the previously saved user selected PLMN
5600 */
5601 @Override
5602 public String getManualNetworkSelectionPlmn(int subId) {
5603 TelephonyPermissions
5604 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5605 mApp, subId, "getManualNetworkSelectionPlmn");
5606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005610 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005611 }
5612
5613 final Phone phone = getPhone(subId);
5614 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005615 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005616 }
5617 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5618 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5619 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
5623 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005624
5625 /**
5626 * Scans for available networks.
5627 */
5628 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005629 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005633 LocationAccessPolicy.LocationPermissionResult locationResult =
5634 LocationAccessPolicy.checkLocationPermission(mApp,
5635 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5636 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005637 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005638 .setCallingPid(Binder.getCallingPid())
5639 .setCallingUid(Binder.getCallingUid())
5640 .setMethod("getCellNetworkScanResults")
5641 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005642 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5643 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005644 .build());
5645 switch (locationResult) {
5646 case DENIED_HARD:
5647 throw new SecurityException("Not allowed to access scan results -- location");
5648 case DENIED_SOFT:
5649 return null;
5650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651
Pengquan Menga1bb6272018-09-06 09:59:22 -07005652 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 try {
5654 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005655 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005660 }
5661
5662 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005663 * Get the call forwarding info, given the call forwarding reason.
5664 */
5665 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005666 public void getCallForwarding(int subId, int callForwardingReason,
5667 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005668 enforceReadPrivilegedPermission("getCallForwarding");
5669 long identity = Binder.clearCallingIdentity();
5670 try {
5671 if (DBG) {
5672 log("getCallForwarding: subId " + subId
5673 + " callForwardingReason" + callForwardingReason);
5674 }
Hall Liu27d24262020-09-18 19:04:59 -07005675
5676 Phone phone = getPhone(subId);
5677 if (phone == null) {
5678 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005679 callback.onError(
5680 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005681 } catch (RemoteException e) {
5682 // ignore
5683 }
5684 return;
5685 }
5686
5687 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5688 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5689 @Override
5690 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5691 try {
5692 callback.onCallForwardingInfoAvailable(info);
5693 } catch (RemoteException e) {
5694 // ignore
5695 }
5696 }
5697
5698 @Override
5699 public void onError(int error) {
5700 try {
5701 callback.onError(error);
5702 } catch (RemoteException e) {
5703 // ignore
5704 }
5705 }
5706 });
5707 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
5711 }
5712
5713 /**
5714 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5715 * reason, the number to forward, and the timeout before the forwarding is attempted.
5716 */
5717 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005718 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5719 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005720 enforceModifyPermission();
5721 long identity = Binder.clearCallingIdentity();
5722 try {
5723 if (DBG) {
5724 log("setCallForwarding: subId " + subId
5725 + " callForwardingInfo" + callForwardingInfo);
5726 }
Hall Liu27d24262020-09-18 19:04:59 -07005727
5728 Phone phone = getPhone(subId);
5729 if (phone == null) {
5730 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005731 callback.accept(
5732 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005733 } catch (RemoteException e) {
5734 // ignore
5735 }
5736 return;
5737 }
5738
5739 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5740 FunctionalUtils.ignoreRemoteException(callback::accept));
5741
5742 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
5746 }
5747
5748 /**
Hall Liu27d24262020-09-18 19:04:59 -07005749 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005750 */
5751 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005752 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005753 enforceReadPrivilegedPermission("getCallForwarding");
5754 long identity = Binder.clearCallingIdentity();
5755 try {
Hall Liu27d24262020-09-18 19:04:59 -07005756
5757 Phone phone = getPhone(subId);
5758 if (phone == null) {
5759 try {
5760 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5761 } catch (RemoteException e) {
5762 // ignore
5763 }
5764 return;
5765 }
5766
5767 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5768
Shuo Qian4a594052020-01-23 11:59:30 -08005769 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005770 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
5774 }
5775
5776 /**
Hall Liu27d24262020-09-18 19:04:59 -07005777 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005778 */
5779 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005780 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005781 enforceModifyPermission();
5782 long identity = Binder.clearCallingIdentity();
5783 try {
Hall Liu27d24262020-09-18 19:04:59 -07005784 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5785
5786 Phone phone = getPhone(subId);
5787 if (phone == null) {
5788 try {
5789 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5790 } catch (RemoteException e) {
5791 // ignore
5792 }
5793 return;
5794 }
5795
5796 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5797 FunctionalUtils.ignoreRemoteException(callback::accept));
5798
5799 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
5803 }
5804
5805 /**
yinxub1bed742017-04-17 11:45:04 -07005806 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005807 *
yinxub1bed742017-04-17 11:45:04 -07005808 * @param subId id of the subscription
5809 * @param request contains the radio access networks with bands/channels to scan
5810 * @param messenger callback messenger for scan results or errors
5811 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005812 * @return the id of the requested scan which can be used to stop the scan.
5813 */
5814 @Override
5815 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005816 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5818 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005819 LocationAccessPolicy.LocationPermissionResult locationResult =
5820 LocationAccessPolicy.checkLocationPermission(mApp,
5821 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5822 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005823 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005824 .setCallingPid(Binder.getCallingPid())
5825 .setCallingUid(Binder.getCallingUid())
5826 .setMethod("requestNetworkScan")
5827 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005828 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5829 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005830 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005831 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005832 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5833 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005834 if (e != null) {
5835 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5836 throw e;
5837 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005838 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005839 return TelephonyScanManager.INVALID_SCAN_ID;
5840 }
5841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 }
Hall Liu912dfd32019-04-25 14:02:26 -07005843 int callingUid = Binder.getCallingUid();
5844 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 return mNetworkScanRequestTracker.startNetworkScan(
5848 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005849 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
yinxu504e1392017-04-12 16:03:22 -07005853 }
5854
Hall Liub2ac8ef2019-02-28 15:56:23 -08005855 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005856 NetworkScanRequest request, int subId, String callingPackage) {
5857 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005858 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5859 boolean hasNetworkScanPermission =
5860 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5861 == PERMISSION_GRANTED;
5862
5863 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5864 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5865 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005866 }
5867
5868 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5869 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005870 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5871 return new SecurityException("Specific channels must not be"
5872 + " scanned without location access.");
5873 }
5874 }
5875 }
5876
Hall Liub2ac8ef2019-02-28 15:56:23 -08005877 return null;
5878 }
5879
yinxu504e1392017-04-12 16:03:22 -07005880 /**
5881 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005882 *
5883 * @param subId id of the subscription
5884 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005885 */
5886 @Override
5887 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5889 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890
Hall Liu912dfd32019-04-25 14:02:26 -07005891 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005894 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
yinxu504e1392017-04-12 16:03:22 -07005898 }
5899
5900 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005901 * Get the calculated preferred network type.
5902 * Used for debugging incorrect network type.
5903 *
5904 * @return the preferred network type, defined in RILConstants.java.
5905 */
5906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005907 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005908 final Phone defaultPhone = getDefaultPhone();
5909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005910 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005911 return RILConstants.PREFERRED_NETWORK_MODE;
5912 }
5913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005917 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
Junda Liu84d15a22014-07-02 11:21:04 -07005921 }
5922
5923 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005924 * Get the preferred network type.
5925 * Used for device configuration by some CDMA operators.
5926 *
5927 * @return the preferred network type, defined in RILConstants.java.
5928 */
5929 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005930 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005931 TelephonyPermissions
5932 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5933 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 if (DBG) log("getPreferredNetworkType");
5938 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5939 int networkType = (result != null ? result[0] : -1);
5940 if (DBG) log("getPreferredNetworkType: " + networkType);
5941 return networkType;
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005945 }
5946
5947 /**
5948 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005949 *
5950 * @param networkType the preferred network type, defined in RILConstants.java.
5951 * @return true on success; false on any failure.
5952 */
5953 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005954 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5956 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957
5958 final long identity = Binder.clearCallingIdentity();
5959 try {
calvinpan8ed33732020-03-12 14:17:55 +08005960 Boolean success = (Boolean) sendRequest(
5961 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005962
5963 if (success) {
5964 Settings.Global.putInt(mApp.getContentResolver(),
5965 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5966 }
calvinpan8ed33732020-03-12 14:17:55 +08005967 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5968 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 } finally {
5970 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005971 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005972 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005973
5974 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005975 * Get the allowed network types that store in the telephony provider.
5976 *
5977 * @param subId the id of the subscription.
5978 * @return allowedNetworkTypes the allowed network types.
5979 */
5980 @Override
5981 public long getAllowedNetworkTypes(int subId) {
5982 TelephonyPermissions
5983 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5984 mApp, subId, "getAllowedNetworkTypes");
5985
5986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 return SubscriptionManager.getLongSubscriptionProperty(
5989 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
5993 }
5994
5995 /**
5996 * Set the allowed network types.
5997 *
5998 * @param subId the id of the subscription.
5999 * @param allowedNetworkTypes the allowed network types.
6000 * @return true on success; false on any failure.
6001 */
6002 @Override
6003 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6005 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08006006
calvinpan8ed33732020-03-12 14:17:55 +08006007 SubscriptionManager.setSubscriptionProperty(subId,
6008 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6009 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08006010
calvinpan8ed33732020-03-12 14:17:55 +08006011 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6012 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6013 RILConstants.PREFERRED_NETWORK_MODE);
6014 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006015 }
6016
6017 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006018 * Get the allowed network types for certain reason.
6019 *
6020 * @param subId the id of the subscription.
6021 * @param reason the reason the allowed network type change is taking place
6022 * @return the allowed network types.
6023 */
6024 @Override
6025 public long getAllowedNetworkTypesForReason(int subId,
6026 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6027 TelephonyPermissions
6028 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6029 mApp, subId, "getAllowedNetworkTypesForReason");
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
6036 }
6037
6038 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006039 * Enable/Disable E-UTRA-NR Dual Connectivity
6040 * @param subId subscription id of the sim card
6041 * @param nrDualConnectivityState expected NR dual connectivity state
6042 * This can be passed following states
6043 * <ol>
6044 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6045 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6046 * <li>Disable NR dual connectivity and force secondary cell to be released
6047 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6048 * </ol>
6049 * @return operation result.
6050 */
6051 @Override
6052 public int setNrDualConnectivityState(int subId,
6053 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6055 mApp, subId, "enableNRDualConnectivity");
6056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6057 final long identity = Binder.clearCallingIdentity();
6058 try {
6059 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6060 nrDualConnectivityState, subId,
6061 workSource);
6062 if (DBG) log("enableNRDualConnectivity result: " + result);
6063 return result;
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
6067 }
6068
6069 /**
6070 * Is E-UTRA-NR Dual Connectivity enabled
6071 * @return true if dual connectivity is enabled else false
6072 */
6073 @Override
6074 public boolean isNrDualConnectivityEnabled(int subId) {
6075 TelephonyPermissions
6076 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6077 mApp, subId, "isNRDualConnectivityEnabled");
6078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6082 null, subId, workSource);
6083 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6084 return isEnabled;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
6088 }
6089
6090 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006091 * get carrier bandwidth per primary and secondary carrier
6092 * @param subId subscription id of the sim card
6093 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6094 */
6095 @Override
6096 public CarrierBandwidth getCarrierBandwidth(int subId) {
6097 TelephonyPermissions
6098 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6099 mApp, subId, "isNRDualConnectivityEnabled");
6100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 CarrierBandwidth carrierBandwidth =
6104 getPhoneFromSubId(subId).getCarrierBandwidth();
6105 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6106 return carrierBandwidth;
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
6111
6112 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006113 * Get the effective allowed network types on the device.
6114 * This API will return an intersection of allowed network types for all reasons,
6115 * including the configuration done through setAllowedNetworkTypes
6116 *
6117 * @param subId the id of the subscription.
6118 * @return the allowed network types
6119 */
6120 @Override
6121 public long getEffectiveAllowedNetworkTypes(int subId) {
6122 TelephonyPermissions
6123 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6124 mApp, subId, "getEffectiveAllowedNetworkTypes");
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
6131 }
6132
6133 /**
6134 * Set the allowed network types of the device and
6135 * provide the reason triggering the allowed network change.
6136 *
6137 * @param subId the id of the subscription.
6138 * @param reason the reason the allowed network type change is taking place
6139 * @param allowedNetworkTypes the allowed network types.
6140 * @return true on success; false on any failure.
6141 */
6142 @Override
6143 public boolean setAllowedNetworkTypesForReason(int subId,
6144 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6146 mApp, subId, "setAllowedNetworkTypesForReason");
6147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6150 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6151 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6152 RILConstants.PREFERRED_NETWORK_MODE);
6153 return setPreferredNetworkType(subId, preferredNetworkMode);
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
6157 }
6158
6159 /**
Miaoa84611c2019-03-15 09:21:10 +08006160 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006161 *
Miaoa84611c2019-03-15 09:21:10 +08006162 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006163 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006164 * @hide
6165 */
6166 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006167 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006168 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006170 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 try {
Miaoa84611c2019-03-15 09:21:10 +08006172 if (phone != null) {
6173 return phone.hasMatchedTetherApnSetting();
6174 } else {
6175 return false;
6176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006179 }
Junda Liu475951f2014-11-07 16:45:03 -08006180 }
6181
6182 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006183 * Enable or disable always reporting signal strength changes from radio.
6184 *
6185 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6186 */
6187 @Override
6188 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6189 enforceModifyPermission();
6190 enforceSystemCaller();
6191
6192 final long identity = Binder.clearCallingIdentity();
6193 final Phone phone = getPhone(subId);
6194 try {
6195 if (phone != null) {
6196 if (DBG) {
6197 log("setAlwaysReportSignalStrength: subId=" + subId
6198 + " isEnable=" + isEnable);
6199 }
6200 phone.setAlwaysReportSignalStrength(isEnable);
6201 } else {
6202 loge("setAlwaysReportSignalStrength: no phone found for subId="
6203 + subId);
6204 }
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
6208 }
6209
6210 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006211 * Get the user enabled state of Mobile Data.
6212 *
6213 * TODO: remove and use isUserDataEnabled.
6214 * This can't be removed now because some vendor codes
6215 * calls through ITelephony directly while they should
6216 * use TelephonyManager.
6217 *
6218 * @return true on enabled
6219 */
6220 @Override
6221 public boolean getDataEnabled(int subId) {
6222 return isUserDataEnabled(subId);
6223 }
6224
6225 /**
6226 * Get whether mobile data is enabled per user setting.
6227 *
6228 * There are other factors deciding whether mobile data is actually enabled, but they are
6229 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006230 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006231 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006232 *
6233 * @return {@code true} if data is enabled else {@code false}
6234 */
6235 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006236 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006237 try {
6238 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6239 null);
6240 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6242 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244
6245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 int phoneId = mSubscriptionController.getPhoneId(subId);
6248 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6249 Phone phone = PhoneFactory.getPhone(phoneId);
6250 if (phone != null) {
6251 boolean retVal = phone.isUserDataEnabled();
6252 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6253 return retVal;
6254 } else {
6255 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6256 return false;
6257 }
6258 } finally {
6259 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006260 }
6261 }
6262
6263 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006264 * Checks if the device is capable of mobile data by considering whether whether the
6265 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6266 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006267 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006268 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006269 */
6270 @Override
6271 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006272 try {
6273 try {
6274 mApp.enforceCallingOrSelfPermission(
6275 android.Manifest.permission.ACCESS_NETWORK_STATE,
6276 null);
6277 } catch (Exception e) {
6278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6279 "isDataEnabled");
6280 }
6281 } catch (Exception e) {
6282 enforceReadPrivilegedPermission("isDataEnabled");
6283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 int phoneId = mSubscriptionController.getPhoneId(subId);
6288 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6289 Phone phone = PhoneFactory.getPhone(phoneId);
6290 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006291 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6293 return retVal;
6294 } else {
6295 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6296 return false;
6297 }
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006300 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006301 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006302
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006303 /**
6304 * Check if data is enabled for a specific reason
6305 * @param subId Subscription index
6306 * @param reason the reason the data enable change is taking place
6307 * @return {@code true} if the overall data is enabled; {@code false} if not.
6308 */
6309 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006310 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006311 @TelephonyManager.DataEnabledReason int reason) {
6312 try {
6313 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6314 null);
6315 } catch (Exception e) {
6316 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006317 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006318 }
6319
6320
6321 final long identity = Binder.clearCallingIdentity();
6322 try {
6323 int phoneId = mSubscriptionController.getPhoneId(subId);
6324 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006325 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006326 + " reason=" + reason);
6327 }
6328 Phone phone = PhoneFactory.getPhone(phoneId);
6329 if (phone != null) {
6330 boolean retVal;
6331 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6332 retVal = phone.isUserDataEnabled();
6333 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006334 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006335 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006336 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006337 return retVal;
6338 } else {
6339 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006340 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006341 + subId + " retVal=false");
6342 }
6343 return false;
6344 }
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
6348 }
6349
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006350 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006351 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006352 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6353 // Skip the check if it's one of these special uids
6354 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6355 }
6356
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006357 //load access rules from carrier configs, and check those as well: b/139133814
6358 SubscriptionController subController = SubscriptionController.getInstance();
6359 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6360 || subController == null) return privilegeFromSim;
6361
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006362 PackageManager pkgMgr = phone.getContext().getPackageManager();
6363 String[] packages = pkgMgr.getPackagesForUid(uid);
6364
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006367 int subId = phone.getSubId();
6368 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6369 // A test override is in place for the privileges for this subId, so don't try to
6370 // read the subscription privileges.
6371 return privilegeFromSim;
6372 }
6373 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006374 SubscriptionManager subManager = (SubscriptionManager)
6375 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6376 for (String pkg : packages) {
6377 if (subManager.canManageSubscription(subInfo, pkg)) {
6378 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6379 }
6380 }
6381 return privilegeFromSim;
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
6386
6387 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6388 String pkgName) {
6389 //load access rules from carrier configs, and check those as well: b/139133814
6390 SubscriptionController subController = SubscriptionController.getInstance();
6391 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6392 || subController == null) return privilegeFromSim;
6393
6394 final long identity = Binder.clearCallingIdentity();
6395 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006396 int subId = phone.getSubId();
6397 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6398 // A test override is in place for the privileges for this subId, so don't try to
6399 // read the subscription privileges.
6400 return privilegeFromSim;
6401 }
6402 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006403 SubscriptionManager subManager = (SubscriptionManager)
6404 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6405 return subManager.canManageSubscription(subInfo, pkgName)
6406 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
6410 }
6411
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006412 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006413 public int getCarrierPrivilegeStatus(int subId) {
6414 final Phone phone = getPhone(subId);
6415 if (phone == null) {
6416 loge("getCarrierPrivilegeStatus: Invalid subId");
6417 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6418 }
6419 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006420 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006421 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006422 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6423 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006424
6425 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6426 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006427 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006428 }
Junda Liu29340342014-07-10 15:23:27 -07006429
6430 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006432 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006433 final Phone phone = getPhone(subId);
6434 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006435 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006436 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6437 }
6438 UiccProfile profile =
6439 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6440 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006441 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6443 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006444 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006445 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006446 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 }
6448
6449 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006450 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6451 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006452 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006453 }
6454
6455 int phoneId = SubscriptionManager.getPhoneId(subId);
6456 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006457 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006458 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6460 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006461 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6462 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6463 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006464 }
6465
6466 @Override
6467 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006468 if (TextUtils.isEmpty(pkgName))
6469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006470 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6471 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6472 UiccCard card = UiccController.getInstance().getUiccCard(i);
6473 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006474 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006475 continue;
6476 }
6477
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006478 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6479 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6480 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006481 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6482 break;
6483 }
6484 }
6485
6486 return result;
Junda Liu29340342014-07-10 15:23:27 -07006487 }
Derek Tan89e89d42014-07-08 17:00:10 -07006488
6489 @Override
Junda Liue64de782015-04-16 17:19:16 -07006490 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6491 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6492 loge("phoneId " + phoneId + " is not valid.");
6493 return null;
6494 }
6495 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006496 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006497 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006498 return null ;
6499 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006500 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006501 }
6502
Amith Yamasani6e118872016-02-19 12:53:51 -08006503 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006504 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006505 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006506 List<String> privilegedPackages = new ArrayList<>();
6507 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006508 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6509 // has UICC in that slot.
6510 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006511 if (card.hasCarrierPrivilegeRules()) {
6512 if (packages == null) {
6513 // Only check packages in user 0 for now
6514 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006515 PackageManager.MATCH_DISABLED_COMPONENTS
6516 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006517 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006518 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006519 }
6520 for (int p = packages.size() - 1; p >= 0; p--) {
6521 PackageInfo pkgInfo = packages.get(p);
6522 if (pkgInfo != null && pkgInfo.packageName != null
6523 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006524 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006525 privilegedPackages.add(pkgInfo.packageName);
6526 }
6527 }
6528 }
6529 }
6530 return privilegedPackages;
6531 }
6532
chen xuf7e9fe82019-05-09 19:31:02 -07006533 @Override
6534 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006535 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6536
6537 final long identity = Binder.clearCallingIdentity();
6538
chen xuf7e9fe82019-05-09 19:31:02 -07006539 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006540 try {
6541 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6542 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6543 }
6544 } finally {
6545 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006546 }
6547 return privilegedPackages;
6548 }
6549
Wink Savilleb564aae2014-10-23 10:18:09 -07006550 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006551 final Phone phone = getPhone(subId);
6552 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006553 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006554 return null;
6555 }
6556 String iccId = card.getIccId();
6557 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006558 return null;
6559 }
6560 return iccId;
6561 }
6562
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006563 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006564 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6565 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006566 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006567 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 final String iccId = getIccId(subId);
6572 final Phone phone = getPhone(subId);
6573 if (phone == null) {
6574 return false;
6575 }
6576 final String subscriberId = phone.getSubscriberId();
6577
6578 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006579 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 + subscriberId + " to " + number);
6581 }
6582
6583 if (TextUtils.isEmpty(iccId)) {
6584 return false;
6585 }
6586
6587 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6588
6589 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6590 if (alphaTag == null) {
6591 editor.remove(alphaTagPrefKey);
6592 } else {
6593 editor.putString(alphaTagPrefKey, alphaTag);
6594 }
6595
6596 // Record both the line number and IMSI for this ICCID, since we need to
6597 // track all merged IMSIs based on line number
6598 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6599 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6600 if (number == null) {
6601 editor.remove(numberPrefKey);
6602 editor.remove(subscriberPrefKey);
6603 } else {
6604 editor.putString(numberPrefKey, number);
6605 editor.putString(subscriberPrefKey, subscriberId);
6606 }
6607
6608 editor.commit();
6609 return true;
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006612 }
Derek Tan7226c842014-07-02 17:42:23 -07006613 }
6614
6615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006616 public String getLine1NumberForDisplay(int subId, String callingPackage,
6617 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006618 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006620 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006621 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006622 return null;
6623 }
Derek Tan97ebb422014-09-05 16:55:38 -07006624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 String iccId = getIccId(subId);
6628 if (iccId != null) {
6629 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6630 if (DBG_MERGE) {
6631 log("getLine1NumberForDisplay returning "
6632 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6633 }
6634 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6637 return null;
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006640 }
Derek Tan7226c842014-07-02 17:42:23 -07006641 }
6642
6643 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006644 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6645 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006647 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006648 return null;
6649 }
Derek Tan97ebb422014-09-05 16:55:38 -07006650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 String iccId = getIccId(subId);
6654 if (iccId != null) {
6655 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6656 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6657 }
6658 return null;
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006661 }
Derek Tan7226c842014-07-02 17:42:23 -07006662 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006663
6664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006665 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6666 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006667 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6668 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006670 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006671 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006672 return null;
6673 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006674
Jordan Liub49b04b2019-05-06 14:45:15 -07006675 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6676 // the process, where TelephonyManager was instantiated.
6677 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006678 final long identity = Binder.clearCallingIdentity();
6679 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006680 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final TelephonyManager tele = TelephonyManager.from(context);
6682 final SubscriptionManager sub = SubscriptionManager.from(context);
6683
6684 // Figure out what subscribers are currently active
6685 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686
Jordan Liub49b04b2019-05-06 14:45:15 -07006687 // Only consider subs which match the current subId
6688 // This logic can be simplified. See b/131189269 for progress.
6689 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006690 activeSubscriberIds.add(tele.getSubscriberId(subId));
6691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692
6693 // First pass, find a number override for an active subscriber
6694 String mergeNumber = null;
6695 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6696 for (String key : prefs.keySet()) {
6697 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6698 final String subscriberId = (String) prefs.get(key);
6699 if (activeSubscriberIds.contains(subscriberId)) {
6700 final String iccId = key.substring(
6701 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6702 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6703 mergeNumber = (String) prefs.get(numberKey);
6704 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006705 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 + " for active subscriber " + subscriberId);
6707 }
6708 if (!TextUtils.isEmpty(mergeNumber)) {
6709 break;
6710 }
6711 }
6712 }
6713 }
6714
6715 // Shortcut when no active merged subscribers
6716 if (TextUtils.isEmpty(mergeNumber)) {
6717 return null;
6718 }
6719
6720 // Second pass, find all subscribers under that line override
6721 final ArraySet<String> result = new ArraySet<>();
6722 for (String key : prefs.keySet()) {
6723 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6724 final String number = (String) prefs.get(key);
6725 if (mergeNumber.equals(number)) {
6726 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6727 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6728 final String subscriberId = (String) prefs.get(subscriberKey);
6729 if (!TextUtils.isEmpty(subscriberId)) {
6730 result.add(subscriberId);
6731 }
6732 }
6733 }
6734 }
6735
6736 final String[] resultArray = result.toArray(new String[result.size()]);
6737 Arrays.sort(resultArray);
6738 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006739 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6741 }
6742 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006743 } finally {
6744 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006745 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006746 }
6747
6748 @Override
zoey chen38003472019-12-13 17:16:31 +08006749 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6750 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 final TelephonyManager telephonyManager = mApp.getSystemService(
6755 TelephonyManager.class);
6756 String subscriberId = telephonyManager.getSubscriberId(subId);
6757 if (subscriberId == null) {
6758 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006759 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006760 + subId);
6761 }
6762 return null;
6763 }
6764
6765 final SubscriptionInfo info = SubscriptionController.getInstance()
6766 .getSubscriptionInfo(subId);
6767 final ParcelUuid groupUuid = info.getGroupUuid();
6768 // If it doesn't belong to any group, return just subscriberId of itself.
6769 if (groupUuid == null) {
6770 return new String[]{subscriberId};
6771 }
6772
6773 // Get all subscriberIds from the group.
6774 final List<String> mergedSubscriberIds = new ArrayList<>();
6775 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006776 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006777 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006778 for (SubscriptionInfo subInfo : groupInfos) {
6779 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6780 if (subscriberId != null) {
6781 mergedSubscriberIds.add(subscriberId);
6782 }
6783 }
6784
6785 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
6788
6789 }
6790 }
6791
6792 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006793 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006794 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006795 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 final Phone phone = getPhone(subId);
6800 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006804 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006805
6806 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006807 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006808 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6809 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006810 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6811 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 final Phone phone = getPhone(subId);
6816 if (phone == null) {
6817 return false;
6818 }
6819 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6820 cdmaNonRoamingList);
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006823 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006824 }
6825
6826 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006827 @Deprecated
6828 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6829 enforceModifyPermission();
6830
6831 int returnValue = 0;
6832 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006833 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006834 if(result.exception == null) {
6835 if (result.result != null) {
6836 byte[] responseData = (byte[])(result.result);
6837 if(responseData.length > oemResp.length) {
6838 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6839 responseData.length + "bytes. Buffer Size is " +
6840 oemResp.length + "bytes.");
6841 }
6842 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6843 returnValue = responseData.length;
6844 }
6845 } else {
6846 CommandException ex = (CommandException) result.exception;
6847 returnValue = ex.getCommandError().ordinal();
6848 if(returnValue > 0) returnValue *= -1;
6849 }
6850 } catch (RuntimeException e) {
6851 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6852 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6853 if(returnValue > 0) returnValue *= -1;
6854 }
6855
6856 return returnValue;
6857 }
6858
6859 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006860 public void setRadioCapability(RadioAccessFamily[] rafs) {
6861 try {
6862 ProxyController.getInstance().setRadioCapability(rafs);
6863 } catch (RuntimeException e) {
6864 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6865 }
6866 }
6867
6868 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006869 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006870 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006871 try {
6872 TelephonyPermissions
6873 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6874 mApp, phone.getSubId(), "getRadioAccessFamily");
6875 } catch (SecurityException e) {
6876 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6877 throw e;
6878 }
chen xub97461a2018-10-26 14:17:57 -07006879 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006880 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006881 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 final long identity = Binder.clearCallingIdentity();
6884 try {
chen xub97461a2018-10-26 14:17:57 -07006885 TelephonyPermissions
6886 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6887 mApp, phone.getSubId(), "getRadioAccessFamily");
6888 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
chen xub97461a2018-10-26 14:17:57 -07006892 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006893 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006894
6895 @Override
6896 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006897 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006902 ImsManager.getInstance(defaultPhone.getContext(),
6903 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
6906 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006907 }
6908
6909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006910 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006911 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6913 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006914 return false;
6915 }
Svet Ganovb320e182015-04-16 12:30:10 -07006916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 final long identity = Binder.clearCallingIdentity();
6918 try {
6919 // Check the user preference and the system-level IMS setting. Even if the user has
6920 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6921 // In the long run, we may instead need to check if there exists a connection service
6922 // which can support video calling.
6923 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 return imsManager.isVtEnabledByPlatform()
6926 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6927 && imsManager.isVtEnabledByUser();
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006931 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006932
Andrew Leea1239f22015-03-02 17:44:07 -08006933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006934 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6935 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006937 mApp, subId, callingPackage, callingFeatureId,
6938 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 return false;
6940 }
6941
6942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 CarrierConfigManager configManager =
6945 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006946 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
Andrew Leea1239f22015-03-02 17:44:07 -08006951 }
6952
6953 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006954 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006956 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 return false;
6958 }
6959
6960 final long identity = Binder.clearCallingIdentity();
6961 try {
6962 CarrierConfigManager configManager =
6963 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006964 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
6968 }
Andrew Leea1239f22015-03-02 17:44:07 -08006969 }
6970
Andrew Lee9431b832015-03-09 18:46:45 -07006971 @Override
6972 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006973 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006974 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006975 }
6976
6977 @Override
6978 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 final long identity = Binder.clearCallingIdentity();
6980 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 } finally {
6983 Binder.restoreCallingIdentity(identity);
6984 }
Andrew Lee9431b832015-03-09 18:46:45 -07006985 }
6986
Hall Liuf6668912018-10-31 17:05:23 -07006987 /**
6988 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6989 * support for the feature and device firmware support.
6990 *
6991 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6992 */
6993 @Override
6994 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006996 final Phone phone = getPhone(subscriptionId);
6997 if (phone == null) {
6998 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6999 return false;
7000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007002 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7004 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007005 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 return isCarrierSupported && isDeviceSupported;
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Hall Liu98187582018-01-22 19:15:32 -08007010 }
7011
Hall Liuf6668912018-10-31 17:05:23 -07007012 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007013 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7014 * RTT setting, will return true if the device and carrier both support RTT.
7015 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007016 */
7017 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007020 boolean isRttSupported = isRttSupported(subscriptionId);
7021 boolean isUserRttSettingOn = Settings.Secure.getInt(
7022 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7023 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7024 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7025 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007029 }
7030
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007031 @Deprecated
7032 @Override
7033 public String getDeviceId(String callingPackage) {
7034 return getDeviceIdWithFeature(callingPackage, null);
7035 }
7036
Sanket Padawe7310cc72015-01-14 09:53:20 -08007037 /**
7038 * Returns the unique device ID of phone, for example, the IMEI for
7039 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7040 *
7041 * <p>Requires Permission:
7042 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7043 */
7044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007045 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007046 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007047 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007048 return null;
7049 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007050 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007051 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007052 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007053 return null;
7054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055
7056 final long identity = Binder.clearCallingIdentity();
7057 try {
7058 return phone.getDeviceId();
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007062 }
7063
Ping Sunc67b7c22016-03-02 19:16:45 +08007064 /**
7065 * {@hide}
7066 * Returns the IMS Registration Status on a particular subid
7067 *
7068 * @param subId
7069 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007070 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 return phone.isImsRegistered();
7074 } else {
7075 return false;
7076 }
7077 }
7078
Santos Cordon7a1885b2015-02-03 11:15:19 -08007079 @Override
7080 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 final long identity = Binder.clearCallingIdentity();
7082 try {
7083 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007087 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007088
Tyler Gunnf70ed162019-04-03 15:28:53 -07007089 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007090 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007094 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7095 }
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
7101 }
7102 }
7103
7104 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007105 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007106 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7107 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 Phone phone = getPhone(subscriptionId);
7111 if (phone == null) {
7112 return null;
7113 }
7114 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
7118 }
7119
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007120 /**
7121 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007122 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007123 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 Phone phone = getPhone(subId);
7127 if (phone != null) {
7128 return phone.isWifiCallingEnabled();
7129 } else {
7130 return false;
7131 }
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007134 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007135 }
7136
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007137 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007138 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007139 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007140 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 Phone phone = getPhone(subId);
7144 if (phone != null) {
7145 return phone.isVideoEnabled();
7146 } else {
7147 return false;
7148 }
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007151 }
7152 }
7153
7154 /**
7155 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7156 * defined in {@link ImsRegistrationImplBase}.
7157 */
7158 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 final long identity = Binder.clearCallingIdentity();
7160 try {
7161 Phone phone = getPhone(subId);
7162 if (phone != null) {
7163 return phone.getImsRegistrationTech();
7164 } else {
7165 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7166 }
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007169 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007170 }
7171
Stuart Scott8eef64f2015-04-08 15:13:54 -07007172 @Override
7173 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007174 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007175 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7176 return;
7177 }
7178
Svet Ganovcc087f82015-05-12 20:35:54 -07007179 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007180
Svet Ganovcc087f82015-05-12 20:35:54 -07007181 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007182 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7183 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007184 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007185 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007186 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007187 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007188 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7189 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007190 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007191 // There has been issues when Sms raw table somehow stores orphan
7192 // fragments. They lead to garbled message when new fragments come
7193 // in and combined with those stale ones. In case this happens again,
7194 // user can reset all network settings which will clean up this table.
7195 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007196 // Clean up IMS settings as well here.
7197 int slotId = getSlotIndex(subId);
7198 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7199 ImsManager.getInstance(mApp, slotId).factoryReset();
7200 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007201
7202 // Erase modem config if erase modem on network setting is enabled.
7203 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7204 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7205 if (configValue != null && Boolean.parseBoolean(configValue)) {
7206 sendEraseModemConfig(getDefaultPhone());
7207 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007210 }
7211 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007212
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007213 private void cleanUpSmsRawTable(Context context) {
7214 ContentResolver resolver = context.getContentResolver();
7215 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7216 resolver.delete(uri, null, null);
7217 }
7218
Narayan Kamath1c496c22015-04-16 14:40:19 +01007219 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007220 public String getSimLocaleForSubscriber(int subId) {
7221 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7222 final Phone phone = getPhone(subId);
7223 if (phone == null) {
7224 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007225 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
7228 try {
chen xu5d3637b2019-01-21 23:31:38 -08007229 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007230 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007231 if (info == null) {
7232 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7233 return null;
7234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 // Try and fetch the locale from the carrier properties or from the SIM language
7236 // preferences (EF-PL and EF-LI)...
7237 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007239 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7240 if (localeFromDefaultSim != null) {
7241 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7242 if (DBG) log("Using locale from subId: " + subId + " locale: "
7243 + localeFromDefaultSim);
7244 return localeFromDefaultSim.toLanguageTag();
7245 } else {
7246 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 }
7248 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 // The SIM language preferences only store a language (e.g. fr = French), not an
7251 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7252 // the SIM and carrier preferences does not include a country we add the country
7253 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007254 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007256 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 return mccLocale.toLanguageTag();
7258 }
7259
7260 if (DBG) log("No locale found - returning null");
7261 return null;
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007265 }
7266
7267 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007268 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007269 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007270 }
7271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 /**
7273 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7274 */
7275 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007276 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007277 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007278 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007279
Chenjie Yu1ba97252018-01-11 18:16:20 -08007280 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007281 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007282
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007283 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007284 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7285 * representing the state of the modem.
7286 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007287 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7288 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007289 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007290 */
7291 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007292 public void requestModemActivityInfo(ResultReceiver result) {
7293 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007298 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 } finally {
7300 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007302 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007303
Siddharth Rayb8114062018-06-17 15:02:38 -07007304 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7305 // less than total activity duration.
7306 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7307 if (info == null) {
7308 return false;
7309 }
7310 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007311 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7312 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7313
Siddharth Rayb8114062018-06-17 15:02:38 -07007314 return (info.isValid()
7315 && (info.getSleepTimeMillis() <= activityDurationMs)
7316 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007317 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007318 && (totalTxTimeMs <= activityDurationMs));
7319 }
7320
Jack Yu85bd38a2015-11-09 11:34:32 -08007321 /**
7322 * {@hide}
7323 * Returns the service state information on specified subscription.
7324 */
7325 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007326 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7327 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007329 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007330 return null;
7331 }
7332
Hall Liuf19c44f2018-11-27 14:38:17 -08007333 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7334 LocationAccessPolicy.checkLocationPermission(mApp,
7335 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7336 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007337 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007338 .setCallingPid(Binder.getCallingPid())
7339 .setCallingUid(Binder.getCallingUid())
7340 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007341 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007343 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7344 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007345 .build());
7346
7347 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7348 LocationAccessPolicy.checkLocationPermission(mApp,
7349 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7350 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007351 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007352 .setCallingPid(Binder.getCallingPid())
7353 .setCallingUid(Binder.getCallingUid())
7354 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007355 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007356 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007357 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7358 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007359 .build());
7360 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7361 boolean hasFinePermission =
7362 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7363 boolean hasCoarsePermission =
7364 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7365
Jack Yu479f40e2020-10-27 21:29:25 -07007366 final Phone phone = getPhone(subId);
7367 if (phone == null) {
7368 return null;
7369 }
7370
Jordan Liu0f2bc442020-11-18 16:47:37 -08007371 final long identity = Binder.clearCallingIdentity();
7372
Jack Yu479f40e2020-10-27 21:29:25 -07007373 boolean isCallingPackageDataService = phone.getDataServicePackages()
7374 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007376 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7377 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7378 Rlog.d(LOG_TAG,
7379 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7380 return null;
7381 }
7382
Hall Liuf19c44f2018-11-27 14:38:17 -08007383 ServiceState ss = phone.getServiceState();
7384
7385 // Scrub out the location info in ServiceState depending on what level of access
7386 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007387 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007388 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7389 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007393 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007394
7395 /**
7396 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7397 *
7398 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7399 * voicemail ringtone.
7400 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7401 * PhoneAccount.
7402 */
7403 @Override
7404 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7408 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007409 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007416 }
7417
7418 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007419 * Sets the per-account voicemail ringtone.
7420 *
7421 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7422 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7423 *
7424 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7425 * voicemail ringtone.
7426 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7427 * PhoneAccount.
7428 */
7429 @Override
7430 public void setVoicemailRingtoneUri(String callingPackage,
7431 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007434 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7435 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7437 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7438 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7444 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 }
7447 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007450 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007451 }
7452
7453 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007454 * Returns whether vibration is set for voicemail notification in Phone settings.
7455 *
7456 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7457 * voicemail vibration setting.
7458 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7459 */
7460 @Override
7461 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 final long identity = Binder.clearCallingIdentity();
7463 try {
7464 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7465 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007473 }
7474
Youhan Wange64578a2016-05-02 15:32:42 -07007475 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007476 * Sets the per-account voicemail vibration.
7477 *
7478 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7479 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7480 *
7481 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7482 * voicemail vibration setting.
7483 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7484 * specific PhoneAccount.
7485 */
7486 @Override
7487 public void setVoicemailVibrationEnabled(String callingPackage,
7488 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007491 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7492 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7494 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7495 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007496 }
7497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7501 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 }
7504 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007507 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007508 }
7509
7510 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007511 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7512 *
7513 * @throws SecurityException if the caller does not have the required permission
7514 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007515 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007517 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007518 }
7519
7520 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007521 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7522 * permission.
7523 *
7524 * @throws SecurityException if the caller does not have the required permission
7525 */
7526 private void enforceSendSmsPermission() {
7527 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7528 }
7529
7530 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007531 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007532 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007533 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007534 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007535 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 if (componentName == null) {
7541 throw new SecurityException(
7542 "Caller not current active visual voicemail package[null]");
7543 }
7544 String vvmPackage = componentName.getPackageName();
7545 if (!callingPackage.equals(vvmPackage)) {
7546 throw new SecurityException("Caller not current active visual voicemail package["
7547 + vvmPackage + "]");
7548 }
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007551 }
7552 }
7553
7554 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007555 * Return the application ID for the app type.
7556 *
7557 * @param subId the subscription ID that this request applies to.
7558 * @param appType the uicc app type.
7559 * @return Application ID for specificied app type, or null if no uicc.
7560 */
7561 @Override
7562 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007563 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007564 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565
7566 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007567 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 if (phone == null) {
7569 return null;
7570 }
7571 String aid = null;
7572 try {
7573 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7574 .getApplicationByType(appType).getAid();
7575 } catch (Exception e) {
7576 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7577 }
7578 return aid;
7579 } finally {
7580 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007581 }
Youhan Wange64578a2016-05-02 15:32:42 -07007582 }
7583
Youhan Wang4001d252016-05-11 10:29:41 -07007584 /**
7585 * Return the Electronic Serial Number.
7586 *
7587 * @param subId the subscription ID that this request applies to.
7588 * @return ESN or null if error.
7589 */
7590 @Override
7591 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007592 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007593 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594
7595 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007596 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 if (phone == null) {
7598 return null;
7599 }
7600 String esn = null;
7601 try {
7602 esn = phone.getEsn();
7603 } catch (Exception e) {
7604 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7605 }
7606 return esn;
7607 } finally {
7608 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007609 }
Youhan Wang4001d252016-05-11 10:29:41 -07007610 }
7611
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007612 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007613 * Return the Preferred Roaming List Version.
7614 *
7615 * @param subId the subscription ID that this request applies to.
7616 * @return PRLVersion or null if error.
7617 */
7618 @Override
7619 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007620 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007621 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622
7623 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007624 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 if (phone == null) {
7626 return null;
7627 }
7628 String cdmaPrlVersion = null;
7629 try {
7630 cdmaPrlVersion = phone.getCdmaPrlVersion();
7631 } catch (Exception e) {
7632 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7633 }
7634 return cdmaPrlVersion;
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007637 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007638 }
7639
7640 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007641 * Get snapshot of Telephony histograms
7642 * @return List of Telephony histograms
7643 * @hide
7644 */
7645 @Override
7646 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7648 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 return RIL.getTelephonyRILTimingHistograms();
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007656 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007657
7658 /**
7659 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007660 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7661 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007662 * Require system privileges. In the future we may add this to carrier APIs.
7663 *
Michele Berionne482f8202018-11-27 18:57:59 -08007664 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007665 */
7666 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007667 @TelephonyManager.SetCarrierRestrictionResult
7668 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007669 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007670 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007671
Michele Berionne482f8202018-11-27 18:57:59 -08007672 if (carrierRestrictionRules == null) {
7673 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007674 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 final long identity = Binder.clearCallingIdentity();
7677 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007678 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007679 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007683 }
7684
7685 /**
7686 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007687 * Get the allowed carrier list and the excluded carrier list, including the priority between
7688 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007689 * Require system privileges. In the future we may add this to carrier APIs.
7690 *
Michele Berionne482f8202018-11-27 18:57:59 -08007691 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007692 */
7693 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007694 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007695 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007696 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697
7698 final long identity = Binder.clearCallingIdentity();
7699 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007700 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7701 if (response instanceof CarrierRestrictionRules) {
7702 return (CarrierRestrictionRules) response;
7703 }
7704 // Response is an Exception of some kind,
7705 // which is signalled to the user as a NULL retval
7706 return null;
7707 } catch (Exception e) {
7708 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7709 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007713 }
7714
fionaxu59545b42016-05-25 15:53:37 -07007715 /**
fionaxu59545b42016-05-25 15:53:37 -07007716 * Action set from carrier signalling broadcast receivers to enable/disable radio
7717 * @param subId the subscription ID that this action applies to.
7718 * @param enabled control enable or disable radio.
7719 * {@hide}
7720 */
7721 @Override
7722 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7723 enforceModifyPermission();
7724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725
7726 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007727 if (phone == null) {
7728 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7729 return;
7730 }
7731 try {
7732 phone.carrierActionSetRadioEnabled(enabled);
7733 } catch (Exception e) {
7734 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 } finally {
7736 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007737 }
7738 }
7739
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007740 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007741 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7742 * network status based on which carrier apps could apply actions accordingly,
7743 * enable/disable default url handler for example.
7744 *
7745 * @param subId the subscription ID that this action applies to.
7746 * @param report control start/stop reporting the default network status.
7747 * {@hide}
7748 */
7749 @Override
7750 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7751 enforceModifyPermission();
7752 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753
7754 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007755 if (phone == null) {
7756 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7757 return;
7758 }
7759 try {
7760 phone.carrierActionReportDefaultNetworkStatus(report);
7761 } catch (Exception e) {
7762 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 } finally {
7764 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007765 }
7766 }
7767
7768 /**
fionaxud9622282017-07-17 17:51:30 -07007769 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7770 * @param subId the subscription ID that this action applies to.
7771 * {@hide}
7772 */
7773 @Override
7774 public void carrierActionResetAll(int subId) {
7775 enforceModifyPermission();
7776 final Phone phone = getPhone(subId);
7777 if (phone == null) {
7778 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7779 return;
7780 }
7781 try {
7782 phone.carrierActionResetAll();
7783 } catch (Exception e) {
7784 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7785 }
7786 }
7787
7788 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007789 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7790 * bug report is being generated.
7791 */
7792 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007793 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007794 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7795 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007796 writer.println("Permission Denial: can't dump Phone from pid="
7797 + Binder.getCallingPid()
7798 + ", uid=" + Binder.getCallingUid()
7799 + "without permission "
7800 + android.Manifest.permission.DUMP);
7801 return;
7802 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007803 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007804 }
Jack Yueb89b242016-06-22 13:27:47 -07007805
Brad Ebingerdac2f002018-04-03 15:17:52 -07007806 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007807 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7808 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7809 @NonNull String[] args) {
7810 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7811 this, in.getFileDescriptor(), out.getFileDescriptor(),
7812 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007813 }
7814
Jack Yueb89b242016-06-22 13:27:47 -07007815 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007816 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007817 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007818 * @param reason the reason the data enable change is taking place
7819 * @param enabled True if enabling the data, otherwise disabling.
7820 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007821 */
7822 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007823 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007824 boolean enabled) {
7825 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7826 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7827 try {
7828 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007829 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007830 } catch (SecurityException se) {
7831 enforceModifyPermission();
7832 }
7833 } else {
7834 enforceModifyPermission();
7835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 Phone phone = getPhone(subId);
7840 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007841 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7842 phone.carrierActionSetMeteredApnsEnabled(enabled);
7843 } else {
7844 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 }
7847 } finally {
7848 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007849 }
7850 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007851
7852 /**
7853 * Get Client request stats
7854 * @return List of Client Request Stats
7855 * @hide
7856 */
7857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7859 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007862 return null;
7863 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007864 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 if (phone != null) {
7869 return phone.getClientRequestStats();
7870 }
7871
7872 return null;
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007876 }
7877
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007878 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007879 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007880 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007881 }
Jack Yueb4124c2017-02-16 15:32:43 -08007882
7883 /**
Grace Chen70990072017-03-24 17:21:30 -07007884 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007885 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007886 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007887 * @param state State of SIM (power down, power up, pass through)
7888 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7889 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7890 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007891 *
7892 **/
7893 @Override
Grace Chen70990072017-03-24 17:21:30 -07007894 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007895 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007896 Phone phone = PhoneFactory.getPhone(slotIndex);
7897
vagdeviaf9a5b92018-08-15 16:01:53 -07007898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08007903 phone.setSimPowerState(state, null, workSource);
7904 }
7905 } finally {
7906 Binder.restoreCallingIdentity(identity);
7907 }
7908 }
7909
7910 /**
7911 * Set SIM card power state.
7912 *
7913 * @param slotIndex SIM slot id.
7914 * @param state State of SIM (power down, power up, pass through)
7915 * @param callback callback to trigger after success or failure
7916 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7917 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7918 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7919 *
7920 **/
7921 @Override
7922 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7923 IIntegerConsumer callback) {
7924 enforceModifyPermission();
7925 Phone phone = PhoneFactory.getPhone(slotIndex);
7926
7927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7928
7929 final long identity = Binder.clearCallingIdentity();
7930 try {
7931 if (phone != null) {
7932 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7933 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 }
7935 } finally {
7936 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007937 }
7938 }
Shuo Qiandd210312017-04-12 22:11:33 +00007939
Tyler Gunn65d45c22017-06-05 11:22:26 -07007940 private boolean isUssdApiAllowed(int subId) {
7941 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007942 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007943 if (configManager == null) {
7944 return false;
7945 }
7946 PersistableBundle pb = configManager.getConfigForSubId(subId);
7947 if (pb == null) {
7948 return false;
7949 }
7950 return pb.getBoolean(
7951 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7952 }
7953
Shuo Qiandd210312017-04-12 22:11:33 +00007954 /**
7955 * Check if phone is in emergency callback mode
7956 * @return true if phone is in emergency callback mode
7957 * @param subId sub id
7958 */
goneil9c5f4872017-12-05 14:07:56 -08007959 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007960 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007961 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007962 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963
7964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 if (phone != null) {
7967 return phone.isInEcm();
7968 } else {
7969 return false;
7970 }
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007973 }
7974 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007975
7976 /**
7977 * Get the current signal strength information for the given subscription.
7978 * Because this information is not updated when the device is in a low power state
7979 * it should not be relied-upon to be current.
7980 * @param subId Subscription index
7981 * @return the most recent cached signal strength info from the modem
7982 */
7983 @Override
7984 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 final long identity = Binder.clearCallingIdentity();
7986 try {
7987 Phone p = getPhone(subId);
7988 if (p == null) {
7989 return null;
7990 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 return p.getSignalStrength();
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007996 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007997
Pengquan Meng77b7f132018-08-22 14:49:57 -07007998 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007999 * Get the current modem radio state for the given slot.
8000 * @param slotIndex slot index.
8001 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008002 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008003 * @return the current radio power state from the modem
8004 */
8005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008006 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008007 Phone phone = PhoneFactory.getPhone(slotIndex);
8008 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8010 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008011 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8012 }
8013
8014 final long identity = Binder.clearCallingIdentity();
8015 try {
8016 return phone.getRadioPowerState();
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 }
8021 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8022 }
8023
8024 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008025 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8026 *
8027 * <p>Requires one of the following permissions:
8028 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8029 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8030 * privileges.
8031 *
8032 * @param subId subscription id
8033 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8034 * {@code false}.
8035 */
8036 @Override
8037 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008038 try {
8039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8040 null);
8041 } catch (Exception e) {
8042 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8043 mApp, subId, "isDataRoamingEnabled");
8044 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008045
Pengquan Menga1bb6272018-09-06 09:59:22 -07008046 boolean isEnabled = false;
8047 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008048 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008049 Phone phone = getPhone(subId);
8050 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008051 } finally {
8052 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008053 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008054 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008055 }
8056
8057
8058 /**
8059 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8060 *
8061 * <p> Requires permission:
8062 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8063 * privileges.
8064 *
8065 * @param subId subscription id
8066 * @param isEnabled {@code true} means enable, {@code false} means disable.
8067 */
8068 @Override
8069 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8071 mApp, subId, "setDataRoamingEnabled");
8072
Pengquan Menga1bb6272018-09-06 09:59:22 -07008073 final long identity = Binder.clearCallingIdentity();
8074 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008075 Phone phone = getPhone(subId);
8076 if (phone != null) {
8077 phone.setDataRoamingEnabled(isEnabled);
8078 }
8079 } finally {
8080 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008081 }
8082 }
8083
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008084 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008085 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008086 TelephonyPermissions
8087 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008088 mApp, subId, "isManualNetworkSelectionAllowed");
8089
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008090 boolean isAllowed = true;
8091 final long identity = Binder.clearCallingIdentity();
8092 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008093 Phone phone = getPhone(subId);
8094 if (phone != null) {
8095 isAllowed = phone.isCspPlmnEnabled();
8096 }
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
8100 return isAllowed;
8101 }
8102
8103 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008104 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008105 // Verify that tha callingPackage belongs to the calling UID
8106 mApp.getSystemService(AppOpsManager.class)
8107 .checkPackage(Binder.getCallingUid(), callingPackage);
8108
Jordan Liu1e142fc2019-04-22 15:10:43 -07008109 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008110 try {
8111 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008112 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008113 } catch (SecurityException e) {
8114 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8115 // has carrier privileges on an active UICC
8116 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8117 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008118 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008119 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008120 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008121
8122 final long identity = Binder.clearCallingIdentity();
8123 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008124 UiccController uiccController = UiccController.getInstance();
8125 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008126 if (hasReadPermission) {
8127 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008128 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008129
8130 // Remove private info if the caller doesn't have access
8131 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8132 for (UiccCardInfo cardInfo : cardInfos) {
8133 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8134 // is available
8135 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8136 if (card == null || card.getUiccProfile() == null) {
8137 // assume no access if the card or profile is unavailable
8138 filteredInfos.add(cardInfo.getUnprivileged());
8139 continue;
8140 }
8141 UiccProfile profile = card.getUiccProfile();
8142 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8143 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8144 filteredInfos.add(cardInfo);
8145 } else {
8146 filteredInfos.add(cardInfo.getUnprivileged());
8147 }
8148 }
8149 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008150 } finally {
8151 Binder.restoreCallingIdentity(identity);
8152 }
8153 }
8154
8155 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008156 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008157 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 final long identity = Binder.clearCallingIdentity();
8160 try {
8161 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8162 if (slots == null) {
8163 Rlog.i(LOG_TAG, "slots is null.");
8164 return null;
8165 }
8166
8167 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8168 for (int i = 0; i < slots.length; i++) {
8169 UiccSlot slot = slots[i];
8170 if (slot == null) {
8171 continue;
8172 }
8173
Jordan Liu7be7e652019-05-06 18:55:02 +00008174 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 UiccCard card = slot.getUiccCard();
8176 if (card != null) {
8177 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008178 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008179 cardId = slot.getEid();
8180 if (TextUtils.isEmpty(cardId)) {
8181 cardId = slot.getIccId();
8182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 }
8184
Jordan Liu857451f2019-05-09 16:35:35 -07008185 if (cardId != null) {
8186 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8187 // if cardId is an EID, it's all digits so this is fine
8188 cardId = IccUtils.stripTrailingFs(cardId);
8189 }
8190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 int cardState = 0;
8192 switch (slot.getCardState()) {
8193 case CARDSTATE_ABSENT:
8194 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8195 break;
8196 case CARDSTATE_PRESENT:
8197 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8198 break;
8199 case CARDSTATE_ERROR:
8200 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8201 break;
8202 case CARDSTATE_RESTRICTED:
8203 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8204 break;
8205 default:
8206 break;
8207
8208 }
8209
8210 infos[i] = new UiccSlotInfo(
8211 slot.isActive(),
8212 slot.isEuicc(),
8213 cardId,
8214 cardState,
8215 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008216 slot.isExtendedApduSupported(),
8217 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 }
8219 return infos;
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008222 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008223 }
8224
8225 @Override
8226 public boolean switchSlots(int[] physicalSlots) {
8227 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
8231 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008235 }
Jack Yu4c988042018-02-27 15:30:01 -08008236
8237 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008238 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008239 final long identity = Binder.clearCallingIdentity();
8240 try {
8241 return UiccController.getInstance().getCardIdForDefaultEuicc();
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
8244 }
8245 }
8246
Pengquan Meng85728fb2018-03-12 16:31:21 -07008247 /**
goneil47ffb6e2018-04-06 15:40:58 -07008248 * A test API to reload the UICC profile.
8249 *
8250 * <p>Requires that the calling app has permission
8251 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8252 * @hide
8253 */
8254 @Override
8255 public void refreshUiccProfile(int subId) {
8256 enforceModifyPermission();
8257
8258 final long identity = Binder.clearCallingIdentity();
8259 try {
8260 Phone phone = getPhone(subId);
8261 if (phone == null) {
8262 return;
8263 }
8264 UiccCard uiccCard = phone.getUiccCard();
8265 if (uiccCard == null) {
8266 return;
8267 }
8268 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8269 if (uiccProfile == null) {
8270 return;
8271 }
8272 uiccProfile.refresh();
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
8277
8278 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008279 * Returns false if the mobile data is disabled by default, otherwise return true.
8280 */
8281 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008282 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008283 }
8284
8285 /**
8286 * Returns true if the data roaming is enabled by default, i.e the system property
8287 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8288 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8289 */
8290 private boolean getDefaultDataRoamingEnabled(int subId) {
8291 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008293 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008294 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8295 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8296 return isDataRoamingEnabled;
8297 }
8298
8299 /**
8300 * Returns the default network type for the given {@code subId}, if the default network type is
8301 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8302 */
8303 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008304 List<Integer> list = TelephonyProperties.default_network();
8305 int phoneId = mSubscriptionController.getPhoneId(subId);
8306 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8307 return list.get(phoneId);
8308 }
8309 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008310 }
fionaxua13278b2018-03-21 00:08:13 -07008311
8312 @Override
8313 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008314 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316
8317 final long identity = Binder.clearCallingIdentity();
8318 try {
8319 final Phone phone = getPhone(subId);
8320 if (phone == null) {
8321 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8322 return;
8323 }
chen xueaba88a2019-03-15 13:15:10 -07008324 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8325 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008326 if (carrierPrivilegeRules == null) {
8327 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8328 } else {
8329 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 } finally {
8332 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008333 }
fionaxua13278b2018-03-21 00:08:13 -07008334 }
8335
8336 @Override
8337 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008338 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339
8340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 final Phone phone = getPhone(subId);
8343 if (phone == null) {
8344 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8345 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8346 }
8347 return phone.getCarrierIdListVersion();
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008350 }
fionaxua13278b2018-03-21 00:08:13 -07008351 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008352
8353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008354 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8355 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008357 mApp, subId, callingPackage, callingFeatureId,
8358 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008359 return -1;
8360 }
8361
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8365 } finally {
8366 Binder.restoreCallingIdentity(identity);
8367 }
8368 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008369
8370 @Override
8371 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008372 TelephonyPermissions
8373 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008374 mApp, subId, "getCdmaRoamingMode");
8375
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
8383
8384 @Override
8385 public boolean setCdmaRoamingMode(int subId, int mode) {
8386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8387 mApp, subId, "setCdmaRoamingMode");
8388
8389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396
8397 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008398 public int getCdmaSubscriptionMode(int subId) {
8399 TelephonyPermissions
8400 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8401 mApp, subId, "getCdmaSubscriptionMode");
8402
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
8405 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
8409 }
8410
8411 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008412 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8414 mApp, subId, "setCdmaSubscriptionMode");
8415
8416 final long identity = Binder.clearCallingIdentity();
8417 try {
8418 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
8422 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008423
sqianc5eccab2018-10-19 18:46:41 -07008424 @Override
sqian8c685422019-02-22 15:55:18 -08008425 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008426 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008428 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8429 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008430 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8431 }
8432 final long identity = Binder.clearCallingIdentity();
8433 try {
sqian854d44b2018-12-12 16:48:18 -08008434 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8435 for (Phone phone: PhoneFactory.getPhones()) {
8436 if (phone.getEmergencyNumberTracker() != null
8437 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8438 emergencyNumberListInternal.put(
8439 phone.getSubId(),
8440 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8441 }
sqian11b7a0e2018-12-05 18:48:28 -08008442 }
sqian854d44b2018-12-12 16:48:18 -08008443 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
sqianc5eccab2018-10-19 18:46:41 -07008447 }
8448
8449 @Override
sqian8c685422019-02-22 15:55:18 -08008450 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008451 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008452 if (!exactMatch) {
8453 TelephonyPermissions
8454 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008455 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008456 }
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
sqian854d44b2018-12-12 16:48:18 -08008459 for (Phone phone: PhoneFactory.getPhones()) {
8460 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008461 && phone.getEmergencyNumberTracker()
8462 .isEmergencyNumber(number, exactMatch)) {
8463 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008464 }
sqian11b7a0e2018-12-05 18:48:28 -08008465 }
8466 return false;
8467 } finally {
8468 Binder.restoreCallingIdentity(identity);
8469 }
8470 }
8471
sqianf4ca7ed2019-01-15 18:32:07 -08008472 /**
8473 * Update emergency number list for test mode.
8474 */
8475 @Override
8476 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8477 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8478 "updateEmergencyNumberListTestMode");
8479
8480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 for (Phone phone: PhoneFactory.getPhones()) {
8483 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8484 if (tracker != null) {
8485 tracker.executeEmergencyNumberTestModeCommand(action, num);
8486 }
8487 }
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
8492
8493 /**
8494 * Get the full emergency number list for test mode.
8495 */
8496 @Override
8497 public List<String> getEmergencyNumberListTestMode() {
8498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8499 "getEmergencyNumberListTestMode");
8500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 Set<String> emergencyNumbers = new HashSet<>();
8504 for (Phone phone: PhoneFactory.getPhones()) {
8505 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8506 if (tracker != null) {
8507 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8508 emergencyNumbers.add(num.getNumber());
8509 }
8510 }
8511 }
8512 return new ArrayList<>(emergencyNumbers);
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
chen xud6b45bd2018-10-30 22:27:10 -07008518 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008519 public int getEmergencyNumberDbVersion(int subId) {
8520 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8521
8522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 final Phone phone = getPhone(subId);
8525 if (phone == null) {
8526 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8527 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8528 }
8529 return phone.getEmergencyNumberDbVersion();
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 @Override
8536 public void notifyOtaEmergencyNumberDbInstalled() {
8537 enforceModifyPermission();
8538
8539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 for (Phone phone: PhoneFactory.getPhones()) {
8542 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8543 if (tracker != null) {
8544 tracker.updateOtaEmergencyNumberDatabase();
8545 }
8546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
8550 }
8551
8552 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008553 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008554 enforceActiveEmergencySessionPermission();
8555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 for (Phone phone: PhoneFactory.getPhones()) {
8559 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8560 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008561 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8562 }
8563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
8569 @Override
8570 public void resetOtaEmergencyNumberDbFilePath() {
8571 enforceActiveEmergencySessionPermission();
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 for (Phone phone: PhoneFactory.getPhones()) {
8576 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8577 if (tracker != null) {
8578 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008579 }
8580 }
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
8585
8586 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008587 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8588 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8589 Phone phone = getPhone(subId);
8590 if (phone == null) {
8591 return null;
8592 }
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 UiccProfile profile = UiccController.getInstance()
8596 .getUiccProfileForPhone(phone.getPhoneId());
8597 if (profile != null) {
8598 return profile.getCertsFromCarrierPrivilegeAccessRules();
8599 }
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
8602 }
8603 return null;
8604 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008605
8606 /**
8607 * Enable or disable a modem stack.
8608 */
8609 @Override
8610 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8611 enforceModifyPermission();
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 Phone phone = PhoneFactory.getPhone(slotIndex);
8616 if (phone == null) {
8617 return false;
8618 } else {
8619 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8620 }
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
Michelecea4cf22018-12-21 15:00:11 -08008625
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008626 /**
8627 * Whether a modem stack is enabled or not.
8628 */
8629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008630 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8631 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008632 Phone phone = PhoneFactory.getPhone(slotIndex);
8633 if (phone == null) return false;
8634
8635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008636 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8637 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008638 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8639 }
8640
8641 final long identity = Binder.clearCallingIdentity();
8642 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008643 try {
8644 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8645 } catch (NoSuchElementException ex) {
8646 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8647 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
8652
Michelecea4cf22018-12-21 15:00:11 -08008653 @Override
Michele0ea7d782019-03-19 14:58:42 -07008654 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008655 enforceModifyPermission();
8656
8657 final long identity = Binder.clearCallingIdentity();
8658 try {
8659 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008660 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008661 .commit();
8662 } finally {
8663 Binder.restoreCallingIdentity(identity);
8664 }
8665 }
8666
8667 @Override
Michele0ea7d782019-03-19 14:58:42 -07008668 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008669 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008671 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8672 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008673 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008674 }
Michelecea4cf22018-12-21 15:00:11 -08008675
8676 final long identity = Binder.clearCallingIdentity();
8677 try {
Michele0ea7d782019-03-19 14:58:42 -07008678 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
8682 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008683
Michele0ea7d782019-03-19 14:58:42 -07008684 @TelephonyManager.IsMultiSimSupportedResult
8685 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008686 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8687 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8688 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008689 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8690 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008691 }
8692 // Check if the hardware supports multisim functionality. If usage of multisim is not
8693 // supported by the modem, indicate that it is restricted.
8694 PhoneCapability staticCapability =
8695 mPhoneConfigurationManager.getStaticPhoneCapability();
8696 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008697 loge("isMultiSimSupportedInternal: no static configuration available");
8698 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008699 }
Sarah Chin7caee492020-02-18 20:49:02 +00008700 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008701 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8702 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008703 }
8704 // Check if support of multiple SIMs is restricted by carrier
8705 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008706 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008707 }
8708
Michele0ea7d782019-03-19 14:58:42 -07008709 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008710 }
8711
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008712 /**
8713 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008714 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8715 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8716 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008717 * @param numOfSims number of active sims we want to switch to
8718 */
8719 @Override
8720 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008721 if (numOfSims == 1) {
8722 enforceModifyPermission();
8723 } else {
8724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8725 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8726 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008727 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008728
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008729 try {
Michele30b57b22019-03-01 12:01:14 -08008730 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008731 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008732 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8733 return;
8734 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008735 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008741 @Override
8742 public boolean isApplicationOnUicc(int subId, int appType) {
8743 enforceReadPrivilegedPermission("isApplicationOnUicc");
8744 Phone phone = getPhone(subId);
8745 if (phone == null) {
8746 return false;
8747 }
8748 final long identity = Binder.clearCallingIdentity();
8749 try {
8750 UiccCard uiccCard = phone.getUiccCard();
8751 if (uiccCard == null) {
8752 return false;
8753 }
8754 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8755 if (uiccProfile == null) {
8756 return false;
8757 }
8758 if (TelephonyManager.APPTYPE_SIM <= appType
8759 && appType <= TelephonyManager.APPTYPE_ISIM) {
8760 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8761 }
8762 return false;
8763 } finally {
8764 Binder.restoreCallingIdentity(identity);
8765 }
8766 }
8767
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008768 /**
chen xub4baa772019-04-03 10:23:41 -07008769 * Get whether making changes to modem configurations will trigger reboot.
8770 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008771 */
8772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008773 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8774 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008776 mApp, subId, callingPackage, callingFeatureId,
8777 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008778 return false;
8779 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
Nathan Harold29f5f052019-02-15 13:41:57 -08008788 private void updateModemStateMetrics() {
8789 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8790 // TODO: check the state for each modem if the api is ready.
8791 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8792 }
8793
Pengquan Meng3889a572019-01-23 11:16:29 -08008794 @Override
8795 public int[] getSlotsMapping() {
8796 enforceReadPrivilegedPermission("getSlotsMapping");
8797
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
8800 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8801 // All logical slots should have a mapping to a physical slot.
8802 int[] logicalSlotsMapping = new int[phoneCount];
8803 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8804 for (int i = 0; i < slotInfos.length; i++) {
8805 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8806 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8807 }
8808 }
8809 return logicalSlotsMapping;
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008814
8815 /**
8816 * Get the IRadio HAL Version
8817 */
8818 @Override
8819 public int getRadioHalVersion() {
8820 Phone phone = getDefaultPhone();
8821 if (phone == null) return -1;
8822 HalVersion hv = phone.getHalVersion();
8823 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8824 return hv.major * 100 + hv.minor;
8825 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008826
8827 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008828 * Get the current calling package name.
8829 * @return the current calling package name
8830 */
8831 @Override
8832 public String getCurrentPackageName() {
8833 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8834 }
8835
8836 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008837 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8838 * corresponding network requests on a subId.
8839 *
8840 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008841 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008842 * 2) APN is un-metered for this subscription, or
8843 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008844 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008845 *
8846 * @return whether data is allowed for a apn type.
8847 *
8848 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008849 */
8850 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008851 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008852 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8853 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008854
8855 // Now that all security checks passes, perform the operation as ourselves.
8856 final long identity = Binder.clearCallingIdentity();
8857 try {
8858 Phone phone = getPhone(subId);
8859 if (phone == null) return false;
8860
Jack Yu41407ee2019-05-13 16:54:09 -07008861 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008862 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
8866 }
8867
8868 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008869 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008870 enforceReadPrivilegedPermission("isApnMetered");
8871
8872 // Now that all security checks passes, perform the operation as ourselves.
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 Phone phone = getPhone(subId);
8876 if (phone == null) return true; // By default return true.
8877
Jack Yu41407ee2019-05-13 16:54:09 -07008878 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008883
8884 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008885 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8886 int subscriptionId, IBooleanConsumer resultCallback) {
8887 enforceModifyPermission();
8888 long token = Binder.clearCallingIdentity();
8889 try {
8890 Phone phone = getPhone(subscriptionId);
8891 if (phone == null) {
8892 try {
8893 if (resultCallback != null) {
8894 resultCallback.accept(false);
8895 }
8896 } catch (RemoteException e) {
8897 // ignore
8898 }
8899 return;
8900 }
8901 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8902 Pair.create(specifiers, (x) -> {
8903 try {
8904 if (resultCallback != null) {
8905 resultCallback.accept(x);
8906 }
8907 } catch (RemoteException e) {
8908 // ignore
8909 }
8910 });
8911 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8912 } finally {
8913 Binder.restoreCallingIdentity(token);
8914 }
8915 }
8916
8917 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008918 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8919 TelephonyPermissions
8920 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8921 mApp, subId, "getSystemSelectionChannels");
8922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 List<RadioAccessSpecifier> specifiers =
8926 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8927 null, subId, workSource);
8928 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8929 return specifiers;
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
8934
8935 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008936 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008937 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008938 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8939 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8940 if (iccRecords == null) {
8941 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8942 return false;
8943 }
8944 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8945 }
8946
8947 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008948 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8949 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008950 if (callingPackage == null) {
8951 callingPackage = getCurrentPackageName();
8952 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008953 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8954 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008955 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8956 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008957 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8958 }
8959 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8960 Intent intent = new Intent();
8961 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8962 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8963 // Bring up choose default SMS subscription dialog right now
8964 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8965 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8966 mApp.startActivity(intent);
8967 }
chen xud5ca2d52019-05-28 15:20:57 -07008968
8969 @Override
8970 public String getMmsUAProfUrl(int subId) {
8971 //TODO investigate if this API should require proper permission check in R b/133791609
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008974 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8975 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8976 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8977 return carrierUAProfUrl;
8978 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008979 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8980 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
8987 public String getMmsUserAgent(int subId) {
8988 //TODO investigate if this API should require proper permission check in R b/133791609
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008991 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8992 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8993 if (!TextUtils.isEmpty(carrierUserAgent)) {
8994 return carrierUserAgent;
8995 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008996 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8997 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 }
Jack Yub07d4972019-05-28 16:12:25 -07009002
9003 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009004 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9005 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009006
Jack Yub07d4972019-05-28 16:12:25 -07009007 final long identity = Binder.clearCallingIdentity();
9008 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009009 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009010 if (phone == null) return false;
9011
Hall Liua62f5da2020-09-25 10:42:19 -07009012 switch (policy) {
9013 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9014 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9015 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9016 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9017 default:
9018 throw new IllegalArgumentException(policy + " is not a valid policy");
9019 }
Jack Yub07d4972019-05-28 16:12:25 -07009020 } finally {
9021 Binder.restoreCallingIdentity(identity);
9022 }
9023 }
9024
9025 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009026 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9027 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009028 enforceModifyPermission();
9029
changbettyd5c246e2019-12-24 15:40:37 +08009030 final long identity = Binder.clearCallingIdentity();
9031 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009032 Phone phone = getPhone(subscriptionId);
9033 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009034
Hall Liua62f5da2020-09-25 10:42:19 -07009035 switch (policy) {
9036 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9037 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9038 break;
9039 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9040 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9041 break;
9042 default:
9043 throw new IllegalArgumentException(policy + " is not a valid policy");
9044 }
changbettyd5c246e2019-12-24 15:40:37 +08009045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
9048 }
9049
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009050 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009051 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009052 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9053 * otherwise.
9054 */
9055 @Override
9056 public void setCepEnabled(boolean isCepEnabled) {
9057 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9062 for (Phone phone : PhoneFactory.getPhones()) {
9063 Phone defaultPhone = phone.getImsPhone();
9064 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9065 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9066 ImsPhoneCallTracker imsPhoneCallTracker =
9067 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9068 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9069 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9070 + imsPhone.getMsisdn());
9071 }
9072 }
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
allenwtsu46dcc572020-01-08 18:24:03 +08009077
9078 /**
9079 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9080 *
9081 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9082 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9083 * before being read.
9084 */
9085 @Override
9086 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9087 isCompressed) {
9088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9089 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009090 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9091 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9092 }
9093 if (!isImsAvailableOnDevice()) {
9094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9095 "IMS not available on device.");
9096 }
9097
9098 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009099 try {
Hui Wang761a6682020-10-31 05:12:53 +00009100 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9101 } finally {
9102 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009103 }
9104 }
zoey chene02881a2019-12-30 16:11:23 +08009105
9106 @Override
9107 public boolean isIccLockEnabled(int subId) {
9108 enforceReadPrivilegedPermission("isIccLockEnabled");
9109
9110 // Now that all security checks passes, perform the operation as ourselves.
9111 final long identity = Binder.clearCallingIdentity();
9112 try {
9113 Phone phone = getPhone(subId);
9114 if (phone != null && phone.getIccCard() != null) {
9115 return phone.getIccCard().getIccLockEnabled();
9116 } else {
9117 return false;
9118 }
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
9123
9124 /**
9125 * Set the ICC pin lock enabled or disabled.
9126 *
9127 * @return an integer representing the status of IccLock enabled or disabled in the following
9128 * three cases:
9129 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9130 * successfully.
9131 * - Positive number and zero for remaining password attempts.
9132 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9133 *
9134 */
9135 @Override
9136 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9137 enforceModifyPermission();
9138
9139 Phone phone = getPhone(subId);
9140 if (phone == null) {
9141 return 0;
9142 }
9143 // Now that all security checks passes, perform the operation as ourselves.
9144 final long identity = Binder.clearCallingIdentity();
9145 try {
9146 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9147 new Pair<Boolean, String>(enabled, password), phone, null);
9148 return attemptsRemaining;
9149
9150 } catch (Exception e) {
9151 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
9155 return 0;
9156 }
9157
9158 /**
9159 * Change the ICC password used in ICC pin lock.
9160 *
9161 * @return an integer representing the status of IccLock changed in the following three cases:
9162 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9163 * - Positive number and zero for remaining password attempts.
9164 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9165 *
9166 */
9167 @Override
9168 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9169 enforceModifyPermission();
9170
9171 Phone phone = getPhone(subId);
9172 if (phone == null) {
9173 return 0;
9174 }
9175 // Now that all security checks passes, perform the operation as ourselves.
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9179 new Pair<String, String>(oldPassword, newPassword), phone, null);
9180 return attemptsRemaining;
9181
9182 } catch (Exception e) {
9183 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 return 0;
9188 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009189
9190 /**
9191 * Request for receiving user activity notification
9192 */
9193 @Override
9194 public void requestUserActivityNotification() {
9195 if (!mNotifyUserActivity.get()
9196 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9197 mNotifyUserActivity.set(true);
9198 }
9199 }
9200
9201 /**
9202 * Called when userActivity is signalled in the power manager.
9203 * This is safe to call from any thread, with any window manager locks held or not.
9204 */
9205 @Override
9206 public void userActivity() {
9207 // ***************************************
9208 // * Inherited from PhoneWindowManager *
9209 // ***************************************
9210 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9211 // WITH ITS LOCKS HELD.
9212 //
9213 // This code must be VERY careful about the locks
9214 // it acquires.
9215 // In fact, the current code acquires way too many,
9216 // and probably has lurking deadlocks.
9217
9218 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9219 throw new SecurityException("Only the OS may call notifyUserActivity()");
9220 }
9221
9222 if (mNotifyUserActivity.getAndSet(false)) {
9223 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9224 USER_ACTIVITY_NOTIFICATION_DELAY);
9225 }
9226 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009227
9228 @Override
9229 public boolean canConnectTo5GInDsdsMode() {
9230 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9231 }
Jack Yud10cdd42020-09-28 20:28:01 -07009232
9233 @Override
9234 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9235 String callingFeatureId) {
9236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9237 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9238 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9239 }
9240
9241 Phone phone = getPhone(subId);
9242 if (phone == null) {
9243 throw new RuntimeException("phone is not available");
9244 }
9245 // Now that all security checks passes, perform the operation as ourselves.
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 return phone.getEquivalentHomePlmns();
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
Daniel Bright59e67312020-11-13 11:49:37 -08009253
9254 @Override
9255 public boolean isRadioInterfaceCapabilitySupported(
9256 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9257 RadioInterfaceCapabilities radioInterfaceCapabilities =
9258 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9259 if (radioInterfaceCapabilities == null) {
9260 throw new RuntimeException("radio interface capabilities are not available");
9261 } else {
9262 return radioInterfaceCapabilities.isSupported(capability);
9263 }
9264 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009265
Hui Wang641e81c2020-10-12 12:14:23 -07009266 @Override
9267 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9268 UaSecurityProtocolIdentifier securityProtocol,
9269 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9270 throws RemoteException {
9271 enforceModifyPermission();
9272 if (DBG) {
9273 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9274 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9275 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9276 }
9277
9278 if (!SubscriptionManager.isValidSubscriptionId(subId)
9279 || appType < TelephonyManager.APPTYPE_UNKNOWN
9280 || appType > TelephonyManager.APPTYPE_ISIM
9281 || nafUrl == null || securityProtocol == null || callback == null) {
9282 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9283 if (callback != null) {
9284 try {
9285 callback.onAuthenticationFailure(
9286 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9287 } catch (RemoteException exception) {
9288 log("Fail to notify onAuthenticationFailure due to " + exception);
9289 }
9290 return;
9291 }
9292 }
9293
9294 final long token = Binder.clearCallingIdentity();
9295 try {
9296 getGbaManager(subId).bootstrapAuthenticationRequest(
9297 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9298 forceBootStrapping, callback));
9299 } finally {
9300 Binder.restoreCallingIdentity(token);
9301 }
9302 }
9303
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009304 /**
9305 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9306 * requested radio power state will actually be set. See {@link
9307 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9308 *
9309 * @param subId the subscription ID of the phone requesting to set the radio power state.
9310 * @param enable {@code true} if trying to turn radio on.
9311 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9312 * false}.
9313 */
9314 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9315 Phone phone = getPhone(subId);
9316 if (phone != null) {
9317 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9318 return true;
9319 }
9320 return false;
9321 }
9322
9323 private int handleDataThrottlingRequest(int subId,
9324 DataThrottlingRequest dataThrottlingRequest) {
9325 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9326 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9327 if (!setRadioPowerForThermal(subId, true)) {
9328 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9329 }
9330
9331 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9332
9333 int thermalMitigationResult =
9334 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9335 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9336 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9337 }
9338 return thermalMitigationResult;
9339 }
9340
9341 /**
9342 * Thermal mitigation request to control functionalities at modem.
9343 *
9344 * @param subId the id of the subscription.
9345 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9346 *
9347 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9348 */
9349 @Override
9350 @ThermalMitigationResult
9351 public int sendThermalMitigationRequest(
9352 int subId,
9353 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9354 enforceModifyPermission();
9355
9356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9357 final long identity = Binder.clearCallingIdentity();
9358
9359 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9360 try {
9361 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9362 switch (thermalMitigationAction) {
9363 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9364 thermalMitigationResult =
9365 handleDataThrottlingRequest(subId,
9366 thermalMitigationRequest.getDataThrottlingRequest());
9367 break;
9368 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9369 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9370 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9371 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9372 }
9373
9374 // Ensure that radio is on. If not able to power on due to phone being
9375 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9376 if (!setRadioPowerForThermal(subId, true)) {
9377 thermalMitigationResult =
9378 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9379 break;
9380 }
9381
9382 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9383 false);
9384 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9385 break;
9386 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9387 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9388 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9389 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9390 }
9391
9392 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9393 if (registry != null) {
9394 TelephonyConnectionService service =
9395 registry.getTelephonyConnectionService();
9396 Phone phone = getPhone(subId);
9397 if (phone == null) {
9398 thermalMitigationResult =
9399 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9400 break;
9401 }
9402
9403 if (PhoneConstantConversions.convertCallState(phone.getState())
9404 != TelephonyManager.CALL_STATE_IDLE
9405 || phone.isInEmergencySmsMode() || phone.isInEcm()
9406 || (service != null && service.isEmergencyCallPending())) {
9407 String errorMessage = "Phone state is not valid. call state = "
9408 + PhoneConstantConversions.convertCallState(phone.getState())
9409 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9410 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9411 errorMessage += service == null
9412 ? " TelephonyConnectionService is null"
9413 : " isEmergencyCallPending = "
9414 + service.isEmergencyCallPending();
9415 Log.e(LOG_TAG, errorMessage);
9416 thermalMitigationResult =
9417 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9418 break;
9419 }
9420 } else {
9421 thermalMitigationResult =
9422 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9423 break;
9424 }
9425
9426 // Turn radio off. If not able to power off due to phone being unavailable,
9427 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9428 if (!setRadioPowerForThermal(subId, false)) {
9429 thermalMitigationResult =
9430 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9431 break;
9432 }
9433 thermalMitigationResult =
9434 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9435 break;
9436 default:
9437 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9438 + "not exist. Requested action: " + thermalMitigationAction);
9439 }
9440 } catch (IllegalArgumentException e) {
9441 throw e;
9442 } catch (Exception e) {
9443 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9444 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448
9449 if (DBG) {
9450 log("thermalMitigationRequest returning with thermalMitigationResult: "
9451 + thermalMitigationResult);
9452 }
9453
9454 return thermalMitigationResult;
9455 }
Hui Wang641e81c2020-10-12 12:14:23 -07009456
9457 /**
9458 * Set the GbaService Package Name that Telephony will bind to.
9459 *
9460 * @param subId The sim that the GbaService is associated with.
9461 * @param packageName The name of the package to be replaced with.
9462 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9463 */
9464 @Override
9465 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9466 enforceModifyPermission();
9467
9468 final long identity = Binder.clearCallingIdentity();
9469 try {
9470 return getGbaManager(subId).overrideServicePackage(packageName);
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
9476 /**
9477 * Return the package name of the currently bound GbaService.
9478 *
9479 * @param subId The sim that the GbaService is associated with.
9480 * @return the package name of the GbaService configuration, null if GBA is not supported.
9481 */
9482 @Override
9483 public String getBoundGbaService(int subId) {
9484 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9485
9486 final long identity = Binder.clearCallingIdentity();
9487 try {
9488 return getGbaManager(subId).getServicePackage();
9489 } finally {
9490 Binder.restoreCallingIdentity(identity);
9491 }
9492 }
9493
9494 /**
9495 * Set the release time for telephony to unbind GbaService.
9496 *
9497 * @param subId The sim that the GbaService is associated with.
9498 * @param interval The release time to unbind GbaService by millisecond.
9499 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9500 */
9501 @Override
9502 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9503 enforceModifyPermission();
9504
9505 final long identity = Binder.clearCallingIdentity();
9506 try {
9507 return getGbaManager(subId).overrideReleaseTime(interval);
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 /**
9514 * Return the release time for telephony to unbind GbaService.
9515 *
9516 * @param subId The sim that the GbaService is associated with.
9517 * @return The release time to unbind GbaService by millisecond.
9518 */
9519 @Override
9520 public int getGbaReleaseTime(int subId) {
9521 enforceReadPrivilegedPermission("getGbaReleaseTime");
9522
9523 final long identity = Binder.clearCallingIdentity();
9524 try {
9525 return getGbaManager(subId).getReleaseTime();
9526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
9530
9531 private GbaManager getGbaManager(int subId) {
9532 GbaManager instance = GbaManager.getInstance(subId);
9533 if (instance == null) {
9534 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9535 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9536 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9537 }
9538 return instance;
9539 }
Hui Wang761a6682020-10-31 05:12:53 +00009540
9541 /**
9542 * indicate whether the device and the carrier can support
9543 * RCS VoLTE single registration.
9544 */
9545 @Override
9546 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9547 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9548
9549 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9550 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9551 }
9552
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
9555 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9556 if (rpm != null) {
9557 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9558 }
9559 return false;
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
9565 /**
9566 * Register RCS provisioning callback.
9567 */
9568 @Override
9569 public void registerRcsProvisioningChangedCallback(int subId,
9570 IRcsConfigCallback callback) {
9571 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9572
9573 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9574 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9575 }
9576 if (!isImsAvailableOnDevice()) {
9577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9578 "IMS not available on device.");
9579 }
9580
9581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9584 .addRcsProvisioningCallbackForSubscription(callback, subId);
9585 } catch (ImsException e) {
9586 throw new ServiceSpecificException(e.getCode());
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
9590 }
9591
9592 /**
9593 * Unregister RCS provisioning callback.
9594 */
9595 @Override
9596 public void unregisterRcsProvisioningChangedCallback(int subId,
9597 IRcsConfigCallback callback) {
9598 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9599
9600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9602 }
9603 if (!isImsAvailableOnDevice()) {
9604 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9605 "IMS not available on device.");
9606 }
9607
9608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9611 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9612 } catch (ImsException e) {
9613 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9614 + "is inactive, ignoring unregister.");
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
9619
9620 /**
9621 * trigger RCS reconfiguration.
9622 */
9623 public void triggerRcsReconfiguration(int subId) {
9624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9625 mApp, subId, "triggerRcsReconfiguration");
9626
9627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9628 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9629 }
9630 if (!isImsAvailableOnDevice()) {
9631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9632 "IMS not available on device.");
9633 }
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 /**
9644 * Provide the client configuration parameters of the RCS application.
9645 */
9646 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9648 mApp, subId, "setRcsClientConfiguration");
9649
9650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9651 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9652 }
9653 if (!isImsAvailableOnDevice()) {
9654 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9655 "IMS not available on device.");
9656 }
9657
9658 final long identity = Binder.clearCallingIdentity();
9659
9660 try {
9661 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9662 if (configBinder == null) {
9663 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9664 } else {
9665 configBinder.setRcsClientConfiguration(rcc);
9666 }
9667 } catch (RemoteException e) {
9668 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672 }
9673
9674 /**
9675 * Overrides the config of RCS VoLTE single registration enabled for the device.
9676 */
9677 @Override
9678 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9679 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9680 "setDeviceSingleRegistrationEnabledOverride");
9681 enforceModifyPermission();
9682
9683 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9684 : Boolean.parseBoolean(enabledStr);
9685 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9686 }
9687
9688 /**
9689 * Gets the config of RCS VoLTE single registration enabled for the device.
9690 */
9691 @Override
9692 public boolean getDeviceSingleRegistrationEnabled() {
9693 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9694 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9695 }
9696
9697 /**
9698 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9699 */
9700 @Override
9701 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9703 "setCarrierSingleRegistrationEnabledOverride");
9704 enforceModifyPermission();
9705
9706 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9707 : Boolean.parseBoolean(enabledStr);
9708 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9709 subId, enabled);
9710 }
9711
9712 /**
9713 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9714 */
9715 @Override
9716 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9717 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9718 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009720}