blob: 9b37900bfe5a1a19173f95a49079c969ad08e143 [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;
Hall Liu82694d52020-12-11 18:22:04 -080029import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
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
Hall Liu82694d52020-12-11 18:22:04 -0800196import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700197import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800198import java.io.IOException;
199import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.util.UUID;
212import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800213import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800214import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
216/**
217 * Implementation of the ITelephony interface.
218 */
Santos Cordon117fee72014-05-16 17:56:12 -0700219public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 private static final String LOG_TAG = "PhoneInterfaceManager";
221 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
222 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225 // Message codes used with mMainThreadHandler
226 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700227 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
228 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229 private static final int CMD_OPEN_CHANNEL = 9;
230 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
231 private static final int CMD_CLOSE_CHANNEL = 11;
232 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800233 private static final int CMD_NV_READ_ITEM = 13;
234 private static final int EVENT_NV_READ_ITEM_DONE = 14;
235 private static final int CMD_NV_WRITE_ITEM = 15;
236 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
237 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
238 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700239 private static final int CMD_RESET_MODEM_CONFIG = 19;
240 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800241 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
242 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
243 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
244 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800245 private static final int CMD_SEND_ENVELOPE = 25;
246 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000247 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
248 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700249 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
250 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
251 private static final int CMD_EXCHANGE_SIM_IO = 31;
252 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800253 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
254 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700255 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
256 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700257 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
258 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700259 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
260 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
261 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
262 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700263 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
264 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
265 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
266 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700267 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800268 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
269 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000270 private static final int CMD_SWITCH_SLOTS = 50;
271 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700272 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
273 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
274 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
275 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
276 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
277 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
278 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
279 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700280 private static final int CMD_GET_ALL_CELL_INFO = 60;
281 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
282 private static final int CMD_GET_CELL_LOCATION = 62;
283 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700284 private static final int CMD_MODEM_REBOOT = 64;
285 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700286 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
287 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800288 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
289 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700290 private static final int CMD_GET_MODEM_STATUS = 70;
291 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700292 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
293 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700294 private static final int CMD_ERASE_MODEM_CONFIG = 74;
295 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800296 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
297 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
298 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
299 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800300 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
301 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800302 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800303 private static final int CMD_GET_CALL_FORWARDING = 83;
304 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
305 private static final int CMD_SET_CALL_FORWARDING = 85;
306 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
307 private static final int CMD_GET_CALL_WAITING = 87;
308 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
309 private static final int CMD_SET_CALL_WAITING = 89;
310 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700311 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
312 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
313 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
314 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700315 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
316 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800317 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
318 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800319 private static final int CMD_SET_DATA_THROTTLING = 99;
320 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800321 private static final int CMD_SET_SIM_POWER = 101;
322 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800324 // Parameters of select command.
325 private static final int SELECT_COMMAND = 0xA4;
326 private static final int SELECT_P1 = 0x04;
327 private static final int SELECT_P2 = 0;
328 private static final int SELECT_P3 = 0x10;
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 /** The singleton instance. */
331 private static PhoneInterfaceManager sInstance;
332
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800335 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700336 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private AppOpsManager mAppOps;
338 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800339 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700341 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Peter Wangdafb9ac2020-01-15 14:13:38 -0800343 /** User Activity */
344 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
346
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700347 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
348
Derek Tan97ebb422014-09-05 16:55:38 -0700349 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
350 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800351 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800352 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700353
Michelecea4cf22018-12-21 15:00:11 -0800354 // String to store multi SIM allowed
355 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
356
Derek Tan740e1672017-06-27 14:56:27 -0700357 // The AID of ISD-R.
358 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
359
yinxub1bed742017-04-17 11:45:04 -0700360 private NetworkScanRequestTracker mNetworkScanRequestTracker;
361
David Kelly5e06a7f2018-03-12 14:10:59 +0000362 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
363 private static final int MANUFACTURER_CODE_LENGTH = 8;
364
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800365 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
366
Derek Tan89e89d42014-07-08 17:00:10 -0700367 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700368 * Experiment flag to enable erase modem config on reset network, default value is false
369 */
370 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
371 "reset_network_erase_modem_config_enabled";
372
373 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700374 * A request object to use for transmitting data to an ICC.
375 */
376 private static final class IccAPDUArgument {
377 public int channel, cla, command, p1, p2, p3;
378 public String data;
379
380 public IccAPDUArgument(int channel, int cla, int command,
381 int p1, int p2, int p3, String data) {
382 this.channel = channel;
383 this.cla = cla;
384 this.command = command;
385 this.p1 = p1;
386 this.p2 = p2;
387 this.p3 = p3;
388 this.data = data;
389 }
390 }
391
392 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700393 * A request object to use for transmitting data to an ICC.
394 */
395 private static final class ManualNetworkSelectionArgument {
396 public OperatorInfo operatorInfo;
397 public boolean persistSelection;
398
399 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
400 this.operatorInfo = operatorInfo;
401 this.persistSelection = persistSelection;
402 }
403 }
404
405 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
407 * request after sending. The main thread will notify the request when it is complete.
408 */
409 private static final class MainThreadRequest {
410 /** The argument to use for the request */
411 public Object argument;
412 /** The result of the request that is run on the main thread */
413 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800414 // The subscriber id that this request applies to. Defaults to
415 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
416 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Nathan Harold92bed182018-10-12 18:16:49 -0700418 // In cases where subId is unavailable, the caller needs to specify the phone.
419 public Phone phone;
420
vagdeviaf9a5b92018-08-15 16:01:53 -0700421 public WorkSource workSource;
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 public MainThreadRequest(Object argument) {
424 this.argument = argument;
425 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800426
Nathan Harold92bed182018-10-12 18:16:49 -0700427 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
428 this.argument = argument;
429 if (phone != null) {
430 this.phone = phone;
431 }
432 this.workSource = workSource;
433 }
434
vagdeviaf9a5b92018-08-15 16:01:53 -0700435 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800436 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800437 if (subId != null) {
438 this.subId = subId;
439 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 }
443
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800444 private static final class IncomingThirdPartyCallArgs {
445 public final ComponentName component;
446 public final String callId;
447 public final String callerDisplayName;
448
449 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
450 String callerDisplayName) {
451 this.component = component;
452 this.callId = callId;
453 this.callerDisplayName = callerDisplayName;
454 }
455 }
456
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 /**
458 * A handler that processes messages on the main thread in the phone process. Since many
459 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
460 * inbound binder threads to the main thread in the phone process. The Binder thread
461 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
462 * on, which will be notified when the operation completes and will contain the result of the
463 * request.
464 *
465 * <p>If a MainThreadRequest object is provided in the msg.obj field,
466 * note that request.result must be set to something non-null for the calling thread to
467 * unblock.
468 */
469 private final class MainThreadHandler extends Handler {
470 @Override
471 public void handleMessage(Message msg) {
472 MainThreadRequest request;
473 Message onCompleted;
474 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800477 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478
479 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 case CMD_HANDLE_USSD_REQUEST: {
481 request = (MainThreadRequest) msg.obj;
482 final Phone phone = getPhoneFromRequest(request);
483 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
484 String ussdRequest = ussdObject.first;
485 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 if (!isUssdApiAllowed(request.subId)) {
488 // Carrier does not support use of this API, return failure.
489 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
490 UssdResponse response = new UssdResponse(ussdRequest, null);
491 Bundle returnData = new Bundle();
492 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
493 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 request.result = true;
496 notifyRequester(request);
497 return;
498 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 try {
501 request.result = phone != null
502 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
503 } catch (CallStateException cse) {
504 request.result = false;
505 }
506 // Wake up the requesting thread
507 notifyRequester(request);
508 break;
pkanwar32d516d2016-10-14 19:37:38 -0700509 }
510
Yorke Lee716f67e2015-06-17 15:39:16 -0700511 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 final Phone phone = getPhoneFromRequest(request);
514 request.result = phone != null ?
515 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
516 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("iccTransmitApduLogicalChannel: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
532 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 iccArgument.channel, iccArgument.cla, iccArgument.command,
535 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 break;
539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800549 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800551 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 } else {
553 loge("iccTransmitApduLogicalChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccTransmitApduBasicChannel: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
569 request);
570 uiccCard.iccTransmitApduBasicChannel(
571 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
572 iccArgument.p3, iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("iccTransmitApduBasicChannel: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("iccTransmitApduBasicChannel: CommandException: " +
587 ar.exception);
588 } else {
589 loge("iccTransmitApduBasicChannel: Unknown exception");
590 }
591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 break;
594
595 case CMD_EXCHANGE_SIM_IO:
596 request = (MainThreadRequest) msg.obj;
597 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800598 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (uiccCard == null) {
600 loge("iccExchangeSimIO: No UICC");
601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
605 request);
606 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
607 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
608 iccArgument.data, onCompleted);
609 }
610 break;
611
612 case EVENT_EXCHANGE_SIM_IO_DONE:
613 ar = (AsyncResult) msg.obj;
614 request = (MainThreadRequest) ar.userObj;
615 if (ar.exception == null && ar.result != null) {
616 request.result = ar.result;
617 } else {
618 request.result = new IccIoResult(0x6f, 0, (byte[])null);
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 break;
622
Derek Tan4d5e5c12014-02-04 11:54:58 -0800623 case CMD_SEND_ENVELOPE:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("sendEnvelopeWithStatus: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
632 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
633 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800634 break;
635
636 case EVENT_SEND_ENVELOPE_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700642 request.result = new IccIoResult(0x6F, 0, (byte[])null);
643 if (ar.result == null) {
644 loge("sendEnvelopeWithStatus: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("sendEnvelopeWithStatus: CommandException: " +
647 ar.exception);
648 } else {
649 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 break;
654
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 case CMD_OPEN_CHANNEL:
656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800657 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 if (uiccCard == null) {
660 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800661 request.result = new IccOpenLogicalChannelResponse(-1,
662 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
665 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
667 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case EVENT_OPEN_CHANNEL_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 int[] result = (int[]) ar.result;
677 int channelId = result[0];
678 byte[] selectResponse = null;
679 if (result.length > 1) {
680 selectResponse = new byte[result.length - 1];
681 for (int i = 1; i < result.length; ++i) {
682 selectResponse[i - 1] = (byte) result[i];
683 }
684 }
685 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700686 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.result == null) {
689 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 if (ar.exception != null) {
692 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
693 }
694
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700696 if (ar.exception instanceof CommandException) {
697 CommandException.Error error =
698 ((CommandException) (ar.exception)).getCommandError();
699 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700701 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 }
704 }
705 openChannelResp = new IccOpenLogicalChannelResponse(
706 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700708 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 break;
711
712 case CMD_CLOSE_CHANNEL:
713 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800714 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 if (uiccCard == null) {
716 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900717 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
721 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 break;
724
725 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800726 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
727 break;
728
729 case CMD_NV_READ_ITEM:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
733 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
736 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800742 request.result = "";
743 if (ar.result == null) {
744 loge("nvReadItem: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("nvReadItem: CommandException: " +
747 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 }
751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 break;
754
Jake Hambye994d462014-02-03 13:10:13 -0800755 case CMD_NV_WRITE_ITEM:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
758 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_WRITE_ITEM_DONE:
764 handleNullReturnEvent(msg, "nvWriteItem");
765 break;
766
767 case CMD_NV_WRITE_CDMA_PRL:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800770 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800771 break;
772
773 case EVENT_NV_WRITE_CDMA_PRL_DONE:
774 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
775 break;
776
chen xu6dac5ab2018-10-26 17:39:23 -0700777 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800778 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700779 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800780 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case EVENT_RESET_MODEM_CONFIG_DONE:
784 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
Sooraj Sasindran37444802020-08-11 10:40:43 -0700787 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
790 request);
791 Phone phone = getPhoneFromRequest(request);
792 if (phone != null) {
793 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
794 } else {
795 loge("isNRDualConnectivityEnabled: No phone object");
796 request.result = false;
797 notifyRequester(request);
798 }
799 break;
800 }
801
802 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null && ar.result != null) {
806 request.result = ar.result;
807 } else {
808 // request.result must be set to something non-null
809 // for the calling thread to unblock
810 if (request.result != null) {
811 request.result = ar.result;
812 } else {
813 request.result = false;
814 }
815 if (ar.result == null) {
816 loge("isNRDualConnectivityEnabled: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("isNRDualConnectivityEnabled: CommandException: "
819 + ar.exception);
820 } else {
821 loge("isNRDualConnectivityEnabled: Unknown exception");
822 }
823 }
824 notifyRequester(request);
825 break;
826
827 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
830 Phone phone = getPhoneFromRequest(request);
831 if (phone != null) {
832 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
833 request.workSource);
834 } else {
835 loge("enableNrDualConnectivity: No phone object");
836 request.result =
837 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
838 notifyRequester(request);
839 }
840 break;
841 }
842
843 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result =
848 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
849 } else {
850 request.result =
851 TelephonyManager
852 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
853 if (ar.exception instanceof CommandException) {
854 CommandException.Error error =
855 ((CommandException) (ar.exception)).getCommandError();
856 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
860 }
861 loge("enableNrDualConnectivity" + ": CommandException: "
862 + ar.exception);
863 } else {
864 loge("enableNrDualConnectivity" + ": Unknown exception");
865 }
866 }
867 notifyRequester(request);
868 break;
869 }
870
Jake Hamby7c27be32014-03-03 13:25:59 -0800871 case CMD_GET_PREFERRED_NETWORK_TYPE:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700874 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 break;
876
877 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result; // Integer
882 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530883 // request.result must be set to something non-null
884 // for the calling thread to unblock
885 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 if (ar.result == null) {
887 loge("getPreferredNetworkType: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getPreferredNetworkType: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getPreferredNetworkType: Unknown exception");
893 }
894 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 break;
897
898 case CMD_SET_PREFERRED_NETWORK_TYPE:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
901 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700902 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
905 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
906 handleNullReturnEvent(msg, "setPreferredNetworkType");
907 break;
908
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000909 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
910 request = (MainThreadRequest)msg.obj;
911 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 break;
914
915 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
916 ar = (AsyncResult)msg.obj;
917 request = (MainThreadRequest)ar.userObj;
918 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000920 break;
921
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800922 case CMD_SET_VOICEMAIL_NUMBER:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
925 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800926 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
927 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800928 break;
929
930 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
931 handleNullReturnEvent(msg, "setVoicemailNumber");
932 break;
933
Stuart Scott54788802015-03-30 13:18:01 -0700934 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
937 request);
938 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
939 break;
940
941 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
942 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
943 break;
944
Shishir Agrawal302c8692015-06-19 13:49:39 -0700945 case CMD_PERFORM_NETWORK_SCAN:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
948 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
949 break;
950
Hall Liu27d24262020-09-18 19:04:59 -0700951 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700954 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
955 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
956 request.argument;
957 int callForwardingReason = args.first;
958 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800959 break;
Hall Liu27d24262020-09-18 19:04:59 -0700960 }
961 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700964 TelephonyManager.CallForwardingInfoCallback callback =
965 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
966 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800967 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700968 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800969 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
970 for (CallForwardInfo callForwardInfo : callForwardInfos) {
971 // Service Class is a bit mask per 3gpp 27.007. Search for
972 // any service for voice call.
973 if ((callForwardInfo.serviceClass
974 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700975 callForwardingInfo = new CallForwardingInfo(true,
976 callForwardInfo.reason,
977 callForwardInfo.number,
978 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800979 break;
980 }
981 }
982 // Didn't find a call forward info for voice call.
983 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700984 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
985 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800986 }
Hall Liu27d24262020-09-18 19:04:59 -0700987 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800988 } else {
989 if (ar.result == null) {
990 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
991 }
992 if (ar.exception != null) {
993 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
994 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700995 int errorCode = TelephonyManager
996 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800997 if (ar.exception instanceof CommandException) {
998 CommandException.Error error =
999 ((CommandException) (ar.exception)).getCommandError();
1000 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001001 errorCode = TelephonyManager
1002 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001004 errorCode = TelephonyManager
1005 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 }
1007 }
Hall Liu27d24262020-09-18 19:04:59 -07001008 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001009 }
Shuo Qian4a594052020-01-23 11:59:30 -08001010 break;
Hall Liu27d24262020-09-18 19:04:59 -07001011 }
Shuo Qian4a594052020-01-23 11:59:30 -08001012
Hall Liu27d24262020-09-18 19:04:59 -07001013 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001016 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001017 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001018 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1019 request.argument).first;
1020 request.phone.setCallForwardingOption(
1021 callForwardingInfoToSet.isEnabled()
1022 ? CommandsInterface.CF_ACTION_ENABLE
1023 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001024 callForwardingInfoToSet.getReason(),
1025 callForwardingInfoToSet.getNumber(),
1026 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1027 break;
Hall Liu27d24262020-09-18 19:04:59 -07001028 }
Shuo Qian4a594052020-01-23 11:59:30 -08001029
Hall Liu27d24262020-09-18 19:04:59 -07001030 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001033 Consumer<Integer> callback =
1034 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1035 request.argument).second;
1036 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001037 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 int errorCode = TelephonyManager.CallForwardingInfoCallback
1039 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001040 if (ar.exception instanceof CommandException) {
1041 CommandException.Error error =
1042 ((CommandException) (ar.exception)).getCommandError();
1043 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001044 errorCode = TelephonyManager.CallForwardingInfoCallback
1045 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001046 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001047 errorCode = TelephonyManager.CallForwardingInfoCallback
1048 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
1050 }
1051 callback.accept(errorCode);
1052 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001053 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001054 }
Shuo Qian4a594052020-01-23 11:59:30 -08001055 break;
Hall Liu27d24262020-09-18 19:04:59 -07001056 }
Shuo Qian4a594052020-01-23 11:59:30 -08001057
Hall Liu27d24262020-09-18 19:04:59 -07001058 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1061 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1062 break;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
Shuo Qian4a594052020-01-23 11:59:30 -08001064
Hall Liu27d24262020-09-18 19:04:59 -07001065 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001068 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001069 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1070 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001071 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001072 // Service Class is a bit mask per 3gpp 27.007.
1073 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001074 if (callForwardResults.length > 1
1075 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001076 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001077 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001078 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1079 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001080 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001081 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001082 }
1083 } else {
1084 if (ar.result == null) {
1085 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1086 }
1087 if (ar.exception != null) {
1088 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1089 }
1090 if (ar.exception instanceof CommandException) {
1091 CommandException.Error error =
1092 ((CommandException) (ar.exception)).getCommandError();
1093 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 callForwardingStatus =
1095 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1096 }
1097 }
1098 }
Hall Liu27d24262020-09-18 19:04:59 -07001099 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001100 break;
Hall Liu27d24262020-09-18 19:04:59 -07001101 }
Shuo Qian4a594052020-01-23 11:59:30 -08001102
Hall Liu27d24262020-09-18 19:04:59 -07001103 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001108 break;
Hall Liu27d24262020-09-18 19:04:59 -07001109 }
Shuo Qian4a594052020-01-23 11:59:30 -08001110
Hall Liu27d24262020-09-18 19:04:59 -07001111 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001114 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1115 Consumer<Integer> callback =
1116 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1117 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001118 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001119 if (ar.exception instanceof CommandException) {
1120 CommandException.Error error =
1121 ((CommandException) (ar.exception)).getCommandError();
1122 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1123 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1124 } else {
1125 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1126 }
1127 } else {
1128 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1129 }
1130 } else {
1131 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1132 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Shishir Agrawal302c8692015-06-19 13:49:39 -07001137 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 CellNetworkScanResult cellScanResult;
1141 if (ar.exception == null && ar.result != null) {
1142 cellScanResult = new CellNetworkScanResult(
1143 CellNetworkScanResult.STATUS_SUCCESS,
1144 (List<OperatorInfo>) ar.result);
1145 } else {
1146 if (ar.result == null) {
1147 loge("getCellNetworkScanResults: Empty response");
1148 }
1149 if (ar.exception != null) {
1150 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1151 }
1152 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1153 if (ar.exception instanceof CommandException) {
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
1156 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1157 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1158 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1159 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1160 }
1161 }
1162 cellScanResult = new CellNetworkScanResult(errorCode, null);
1163 }
1164 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 break;
1167
1168 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1169 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001170 ManualNetworkSelectionArgument selArg =
1171 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1173 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001174 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1175 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 break;
1177
1178 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 if (ar.exception == null) {
1182 request.result = true;
1183 } else {
1184 request.result = false;
1185 loge("setNetworkSelectionModeManual " + ar.exception);
1186 }
1187 notifyRequester(request);
1188 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001191 case CMD_GET_MODEM_ACTIVITY_INFO:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001194 if (defaultPhone != null) {
1195 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001196 } else {
1197 ResultReceiver result = (ResultReceiver) request.argument;
1198 Bundle bundle = new Bundle();
1199 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001200 new ModemActivityInfo(0, 0, 0,
1201 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001202 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001203 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001204 break;
1205
Hall Liud0f208c2020-10-14 16:54:44 -07001206 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001209 ResultReceiver result = (ResultReceiver) request.argument;
1210
Hall Liud0f208c2020-10-14 16:54:44 -07001211 ModemActivityInfo ret = null;
1212 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001214 // Update the last modem activity info and the result of the request.
1215 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1216 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001217 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001218 int[] txTimeMs = info.getTransmitTimeMillis();
1219 int[] lastModemTxTimeMs = mLastModemActivityInfo
1220 .getTransmitTimeMillis();
1221 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1222 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1223 }
Hall Liu49656c02020-10-09 19:00:11 -07001224 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1226 + mLastModemActivityInfo.getSleepTimeMillis());
1227 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1228 + mLastModemActivityInfo.getIdleTimeMillis());
1229 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1230 mLastModemActivityInfo.setReceiveTimeMillis(
1231 info.getReceiveTimeMillis()
1232 + mLastModemActivityInfo.getReceiveTimeMillis());
1233 }
Hall Liu49656c02020-10-09 19:00:11 -07001234 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 mLastModemActivityInfo.getSleepTimeMillis(),
1236 mLastModemActivityInfo.getIdleTimeMillis(),
1237 mLastModemActivityInfo.getTransmitTimeMillis(),
1238 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 } else {
1240 if (ar.result == null) {
1241 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001242 error = TelephonyManager.ModemActivityInfoException
1243 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001244 } else if (ar.exception instanceof CommandException) {
1245 loge("queryModemActivityInfo: CommandException: " +
1246 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001247 error = TelephonyManager.ModemActivityInfoException
1248 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 } else {
1250 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001251 error = TelephonyManager.ModemActivityInfoException
1252 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 }
1254 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001255 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001256 if (ret != null) {
1257 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1258 } else {
1259 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1260 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001262 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001263 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001264 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001265
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 case CMD_SET_ALLOWED_CARRIERS:
1267 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001268 CarrierRestrictionRules argument =
1269 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001271 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 break;
1273
1274 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 if (ar.exception == null && ar.result != null) {
1278 request.result = ar.result;
1279 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001280 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1281 if (ar.exception instanceof CommandException) {
1282 loge("setAllowedCarriers: CommandException: " + ar.exception);
1283 CommandException.Error error =
1284 ((CommandException) (ar.exception)).getCommandError();
1285 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1286 request.result =
1287 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1288 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 } else {
1290 loge("setAllowedCarriers: Unknown exception");
1291 }
1292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001293 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001294 break;
1295
1296 case CMD_GET_ALLOWED_CARRIERS:
1297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001299 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
1302 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null && ar.result != null) {
1306 request.result = ar.result;
1307 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001308 request.result = new IllegalStateException(
1309 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 if (ar.result == null) {
1311 loge("getAllowedCarriers: Empty response");
1312 } else if (ar.exception instanceof CommandException) {
1313 loge("getAllowedCarriers: CommandException: " +
1314 ar.exception);
1315 } else {
1316 loge("getAllowedCarriers: Unknown exception");
1317 }
1318 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001319 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 break;
1321
Nathan Haroldb3014052017-01-25 15:57:32 -08001322 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null && ar.result != null) {
1326 request.result = ar.result;
1327 } else {
1328 request.result = new IllegalArgumentException(
1329 "Failed to retrieve Forbidden Plmns");
1330 if (ar.result == null) {
1331 loge("getForbiddenPlmns: Empty response");
1332 } else {
1333 loge("getForbiddenPlmns: Unknown exception");
1334 }
1335 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001336 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001337 break;
1338
1339 case CMD_GET_FORBIDDEN_PLMNS:
1340 request = (MainThreadRequest) msg.obj;
1341 uiccCard = getUiccCardFromRequest(request);
1342 if (uiccCard == null) {
1343 loge("getForbiddenPlmns() UiccCard is null");
1344 request.result = new IllegalArgumentException(
1345 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348 }
1349 Integer appType = (Integer) request.argument;
1350 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1351 if (uiccApp == null) {
1352 loge("getForbiddenPlmns() no app with specified type -- "
1353 + appType);
1354 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001356 break;
1357 } else {
1358 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1359 + " specified type -- " + appType);
1360 }
1361 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1362 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1363 onCompleted);
1364 break;
1365
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001366 case CMD_SWITCH_SLOTS:
1367 request = (MainThreadRequest) msg.obj;
1368 int[] physicalSlots = (int[]) request.argument;
1369 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1370 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1371 break;
1372
1373 case EVENT_SWITCH_SLOTS_DONE:
1374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
1376 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001377 notifyRequester(request);
1378 break;
1379 case CMD_GET_NETWORK_SELECTION_MODE:
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1382 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1383 break;
1384
1385 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception != null) {
1389 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1390 } else {
1391 int mode = ((int[]) ar.result)[0];
1392 if (mode == 0) {
1393 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1394 } else {
1395 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1396 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001397 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001398 notifyRequester(request);
1399 break;
1400 case CMD_GET_CDMA_ROAMING_MODE:
1401 request = (MainThreadRequest) msg.obj;
1402 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1403 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1404 break;
1405 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception != null) {
1409 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1410 } else {
1411 request.result = ((int[]) ar.result)[0];
1412 }
1413 notifyRequester(request);
1414 break;
1415 case CMD_SET_CDMA_ROAMING_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1418 int mode = (int) request.argument;
1419 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1420 break;
1421 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 request.result = ar.exception == null;
1425 notifyRequester(request);
1426 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001427 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1430 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1431 break;
1432 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 if (ar.exception != null) {
1436 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1437 } else {
1438 request.result = ((int[]) ar.result)[0];
1439 }
1440 notifyRequester(request);
1441 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1445 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001446 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1447 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001448 break;
1449 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 request.result = ar.exception == null;
1453 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001454 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 case CMD_GET_ALL_CELL_INFO:
1456 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001458 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 case EVENT_GET_ALL_CELL_INFO_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001463 // If a timeout occurs, the response will be null
1464 request.result = (ar.exception == null && ar.result != null)
1465 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 synchronized (request) {
1467 request.notifyAll();
1468 }
1469 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001470 case CMD_REQUEST_CELL_INFO_UPDATE:
1471 request = (MainThreadRequest) msg.obj;
1472 request.phone.requestCellInfoUpdate(request.workSource,
1473 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1474 break;
1475 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
1478 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1479 try {
1480 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001482 cb.onError(
1483 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1484 ar.exception.getClass().getName(),
1485 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001486 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001487 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001488 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001489 } else {
1490 // use the result as returned
1491 cb.onCellInfo((List<CellInfo>) ar.result);
1492 }
1493 } catch (RemoteException re) {
1494 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1495 }
1496 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001497 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 request = (MainThreadRequest) msg.obj;
1499 WorkSource ws = (WorkSource) request.argument;
1500 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001501 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001503 }
1504 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 ar = (AsyncResult) msg.obj;
1506 request = (MainThreadRequest) ar.userObj;
1507 if (ar.exception == null) {
1508 request.result = ar.result;
1509 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001510 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001512 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001513 }
1514
1515 synchronized (request) {
1516 request.notifyAll();
1517 }
1518 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001519 }
chen xu6dac5ab2018-10-26 17:39:23 -07001520 case CMD_MODEM_REBOOT:
1521 request = (MainThreadRequest) msg.obj;
1522 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001523 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001524 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001525 case EVENT_CMD_MODEM_REBOOT_DONE:
1526 handleNullReturnEvent(msg, "rebootModem");
1527 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001528 case CMD_REQUEST_ENABLE_MODEM:
1529 request = (MainThreadRequest) msg.obj;
1530 boolean enable = (boolean) request.argument;
1531 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001532 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001533 PhoneConfigurationManager.getInstance()
1534 .enablePhone(request.phone, enable, onCompleted);
1535 break;
1536 case EVENT_ENABLE_MODEM_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001540 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001541 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001542 if ((boolean) request.result) {
1543 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1544 updateModemStateMetrics();
1545 } else {
1546 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1547 + ar.exception);
1548 }
1549 notifyRequester(request);
1550 break;
1551 case CMD_GET_MODEM_STATUS:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1554 PhoneConfigurationManager.getInstance()
1555 .getPhoneStatusFromModem(request.phone, onCompleted);
1556 break;
1557 case EVENT_GET_MODEM_STATUS_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 int id = request.phone.getPhoneId();
1561 if (ar.exception == null && ar.result != null) {
1562 request.result = ar.result;
1563 //update the cache as modem status has changed
1564 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1565 (boolean) request.result);
1566 } else {
1567 // Return true if modem status cannot be retrieved. For most cases,
1568 // modem status is on. And for older version modems, GET_MODEM_STATUS
1569 // and disable modem are not supported. Modem is always on.
1570 // TODO: this should be fixed in R to support a third
1571 // status UNKNOWN b/131631629
1572 request.result = true;
1573 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1574 + ar.exception);
1575 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001576 notifyRequester(request);
1577 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001578 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1581 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1582 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1583 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1584 break;
1585 }
1586 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
1589 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1590 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1591 args.second.accept(ar.exception == null);
1592 notifyRequester(request);
1593 break;
1594 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001595 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1596 request = (MainThreadRequest) msg.obj;
1597 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1598 Phone phone = getPhoneFromRequest(request);
1599 if (phone != null) {
1600 phone.getSystemSelectionChannels(onCompleted);
1601 } else {
1602 loge("getSystemSelectionChannels: No phone object");
1603 request.result = new ArrayList<RadioAccessSpecifier>();
1604 notifyRequester(request);
1605 }
1606 break;
1607 }
1608 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception == null && ar.result != null) {
1612 request.result = ar.result;
1613 } else {
1614 request.result = new IllegalArgumentException(
1615 "Failed to retrieve system selection channels");
1616 if (ar.result == null) {
1617 loge("getSystemSelectionChannels: Empty response");
1618 } else {
1619 loge("getSystemSelectionChannels: Unknown exception");
1620 }
1621 }
1622 notifyRequester(request);
1623 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001624 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception == null && ar.result != null) {
1628 request.result = ar.result;
1629 } else {
1630 request.result = -1;
1631 loge("Failed to set Forbidden Plmns");
1632 if (ar.result == null) {
1633 loge("setForbidenPlmns: Empty response");
1634 } else if (ar.exception != null) {
1635 loge("setForbiddenPlmns: Exception: " + ar.exception);
1636 request.result = -1;
1637 } else {
1638 loge("setForbiddenPlmns: Unknown exception");
1639 }
1640 }
1641 notifyRequester(request);
1642 break;
1643 case CMD_SET_FORBIDDEN_PLMNS:
1644 request = (MainThreadRequest) msg.obj;
1645 uiccCard = getUiccCardFromRequest(request);
1646 if (uiccCard == null) {
1647 loge("setForbiddenPlmns: UiccCard is null");
1648 request.result = -1;
1649 notifyRequester(request);
1650 break;
1651 }
1652 Pair<Integer, List<String>> setFplmnsArgs =
1653 (Pair<Integer, List<String>>) request.argument;
1654 appType = setFplmnsArgs.first;
1655 List<String> fplmns = setFplmnsArgs.second;
1656 uiccApp = uiccCard.getApplicationByType(appType);
1657 if (uiccApp == null) {
1658 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1659 request.result = -1;
1660 loge("Failed to get UICC App");
1661 notifyRequester(request);
1662 } else {
1663 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1664 ((SIMRecords) uiccApp.getIccRecords())
1665 .setForbiddenPlmns(onCompleted, fplmns);
1666 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001667 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001668 case CMD_ERASE_MODEM_CONFIG:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1671 defaultPhone.eraseModemConfig(onCompleted);
1672 break;
1673 case EVENT_ERASE_MODEM_CONFIG_DONE:
1674 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001675 break;
zoey chene02881a2019-12-30 16:11:23 +08001676
1677 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1680 Pair<String, String> changed = (Pair<String, String>) request.argument;
1681 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1682 changed.first, changed.second, onCompleted);
1683 break;
1684 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception == null) {
1688 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1689 } else {
1690 request.result = msg.arg1;
1691 }
1692 notifyRequester(request);
1693 break;
1694
1695 case CMD_SET_ICC_LOCK_ENABLED:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1698 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1699 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1700 enabled.first, enabled.second, onCompleted);
1701 break;
1702 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception == null) {
1706 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1707 } else {
1708 request.result = msg.arg1;
1709 }
1710 notifyRequester(request);
1711 break;
1712
Peter Wangdafb9ac2020-01-15 14:13:38 -08001713 case MSG_NOTIFY_USER_ACTIVITY:
1714 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001715 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001716 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1717 getDefaultPhone().getContext().sendBroadcastAsUser(
1718 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1719 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001720
1721 case CMD_SET_DATA_THROTTLING: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1724 DataThrottlingRequest dataThrottlingRequest =
1725 (DataThrottlingRequest) request.argument;
1726 Phone phone = getPhoneFromRequest(request);
1727 if (phone != null) {
1728 phone.setDataThrottling(onCompleted,
1729 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1730 dataThrottlingRequest.getCompletionDurationMillis());
1731 } else {
1732 loge("setDataThrottling: No phone object");
1733 request.result =
1734 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1735 notifyRequester(request);
1736 }
1737
1738 break;
1739 }
1740 case EVENT_SET_DATA_THROTTLING_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743
1744 if (ar.exception == null) {
1745 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1746 } else if (ar.exception instanceof CommandException) {
1747 loge("setDataThrottling: CommandException: " + ar.exception);
1748 CommandException.Error error =
1749 ((CommandException) (ar.exception)).getCommandError();
1750
1751 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1752 request.result = TelephonyManager
1753 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1754 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1755 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1756 } else {
1757 request.result =
1758 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1759 }
1760 } else {
1761 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1762 }
1763 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1764 notifyRequester(request);
1765 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001766
1767 case CMD_SET_SIM_POWER: {
1768 request = (MainThreadRequest) msg.obj;
1769 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1770 request = (MainThreadRequest) msg.obj;
1771 int stateToSet =
1772 ((Pair<Integer, IIntegerConsumer>)
1773 request.argument).first;
1774 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1775 break;
1776 }
1777 case EVENT_SET_SIM_POWER_DONE: {
1778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
1780 IIntegerConsumer callback =
1781 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1782 if (ar.exception != null) {
1783 loge("setSimPower exception: " + ar.exception);
1784 int errorCode = TelephonyManager.CallForwardingInfoCallback
1785 .RESULT_ERROR_UNKNOWN;
1786 if (ar.exception instanceof CommandException) {
1787 CommandException.Error error =
1788 ((CommandException) (ar.exception)).getCommandError();
1789 if (error == CommandException.Error.SIM_ERR) {
1790 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1791 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1792 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1793 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1794 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1795 } else {
1796 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1797 }
1798 }
1799 try {
1800 callback.accept(errorCode);
1801 } catch (RemoteException e) {
1802 // Ignore if the remote process is no longer available to call back.
1803 Log.w(LOG_TAG, "setSimPower: callback not available.");
1804 }
1805 } else {
1806 try {
1807 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1808 } catch (RemoteException e) {
1809 // Ignore if the remote process is no longer available to call back.
1810 Log.w(LOG_TAG, "setSimPower: callback not available.");
1811 }
1812 }
1813 break;
1814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 default:
1817 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1818 break;
1819 }
1820 }
Jake Hambye994d462014-02-03 13:10:13 -08001821
Pengquan Menga1bb6272018-09-06 09:59:22 -07001822 private void notifyRequester(MainThreadRequest request) {
1823 synchronized (request) {
1824 request.notifyAll();
1825 }
1826 }
1827
Jake Hambye994d462014-02-03 13:10:13 -08001828 private void handleNullReturnEvent(Message msg, String command) {
1829 AsyncResult ar = (AsyncResult) msg.obj;
1830 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1831 if (ar.exception == null) {
1832 request.result = true;
1833 } else {
1834 request.result = false;
1835 if (ar.exception instanceof CommandException) {
1836 loge(command + ": CommandException: " + ar.exception);
1837 } else {
1838 loge(command + ": Unknown exception");
1839 }
1840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001841 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 /**
1846 * Posts the specified command to be executed on the main thread,
1847 * waits for the request to complete, and returns the result.
1848 * @see #sendRequestAsync
1849 */
1850 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001851 return sendRequest(
1852 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001853 }
1854
1855 /**
1856 * Posts the specified command to be executed on the main thread,
1857 * waits for the request to complete, and returns the result.
1858 * @see #sendRequestAsync
1859 */
1860 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1861 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001862 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001863 }
1864
1865 /**
1866 * Posts the specified command to be executed on the main thread,
1867 * waits for the request to complete, and returns the result.
1868 * @see #sendRequestAsync
1869 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001870 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001871 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001872 }
1873
1874 /**
1875 * Posts the specified command to be executed on the main thread,
1876 * waits for the request to complete, and returns the result.
1877 * @see #sendRequestAsync
1878 */
Nathan Harold92bed182018-10-12 18:16:49 -07001879 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1880 return sendRequest(command, argument, subId, null, workSource);
1881 }
1882
1883 /**
1884 * Posts the specified command to be executed on the main thread,
1885 * waits for the request to complete, and returns the result.
1886 * @see #sendRequestAsync
1887 */
1888 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1889 return sendRequest(
1890 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1891 }
1892
1893 /**
1894 * Posts the specified command to be executed on the main thread,
1895 * waits for the request to complete, and returns the result.
1896 * @see #sendRequestAsync
1897 */
1898 private Object sendRequest(
1899 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1901 throw new RuntimeException("This method will deadlock if called from the main thread.");
1902 }
1903
Nathan Harold92bed182018-10-12 18:16:49 -07001904 MainThreadRequest request = null;
1905 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1906 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1907 } else if (phone != null) {
1908 request = new MainThreadRequest(argument, phone, workSource);
1909 } else {
1910 request = new MainThreadRequest(argument, subId, workSource);
1911 }
1912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 Message msg = mMainThreadHandler.obtainMessage(command, request);
1914 msg.sendToTarget();
1915
1916 // Wait for the request to complete
1917 synchronized (request) {
1918 while (request.result == null) {
1919 try {
1920 request.wait();
1921 } catch (InterruptedException e) {
1922 // Do nothing, go back and wait until the request is complete
1923 }
1924 }
1925 }
1926 return request.result;
1927 }
1928
1929 /**
1930 * Asynchronous ("fire and forget") version of sendRequest():
1931 * Posts the specified command to be executed on the main thread, and
1932 * returns immediately.
1933 * @see #sendRequest
1934 */
1935 private void sendRequestAsync(int command) {
1936 mMainThreadHandler.sendEmptyMessage(command);
1937 }
1938
1939 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001940 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001941 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001942 */
1943 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001944 sendRequestAsync(command, argument, null, null);
1945 }
1946
1947 /**
1948 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1949 * @see {@link #sendRequest(int,Object)}
1950 */
1951 private void sendRequestAsync(
1952 int command, Object argument, Phone phone, WorkSource workSource) {
1953 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001954 Message msg = mMainThreadHandler.obtainMessage(command, request);
1955 msg.sendToTarget();
1956 }
1957
1958 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 * Initialize the singleton PhoneInterfaceManager instance.
1960 * This is only done once, at startup, from PhoneApp.onCreate().
1961 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001962 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 synchronized (PhoneInterfaceManager.class) {
1964 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001965 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 } else {
1967 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1968 }
1969 return sInstance;
1970 }
1971 }
1972
1973 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001974 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001977 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001978 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1980 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001981 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001982 mTelephonySharedPreferences =
1983 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001984 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001985 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001986 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 publish();
1989 }
1990
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001991 private Phone getDefaultPhone() {
1992 Phone thePhone = getPhone(getDefaultSubscription());
1993 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1994 }
1995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 private void publish() {
1997 if (DBG) log("publish: " + this);
1998
Peter Wangc035ce42020-01-08 21:00:22 -08001999 TelephonyFrameworkInitializer
2000 .getTelephonyServiceManager()
2001 .getTelephonyServiceRegisterer()
2002 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004
Stuart Scott584921c2015-01-15 17:10:34 -08002005 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002006 if (request.phone != null) {
2007 return request.phone;
2008 } else {
2009 return getPhoneFromSubId(request.subId);
2010 }
2011 }
2012
2013 private Phone getPhoneFromSubId(int subId) {
2014 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2015 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002016 }
2017
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002018 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2019 Phone phone = getPhoneFromRequest(request);
2020 return phone == null ? null :
2021 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2022 }
2023
Wink Saville36469e72014-06-11 15:17:00 -07002024 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002025 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002026 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028
Naina Nallurid63128d2019-09-17 14:10:30 -07002029 private void sendEraseModemConfig(Phone phone) {
2030 if (phone != null) {
2031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2032 mApp, phone.getSubId(), "eraseModemConfig");
2033 final long identity = Binder.clearCallingIdentity();
2034 try {
2035 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2036 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2037 } finally {
2038 Binder.restoreCallingIdentity(identity);
2039 }
2040 }
2041 }
2042
Peter Wang44b186e2020-01-13 23:33:09 -08002043 private boolean isImsAvailableOnDevice() {
2044 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2045 if (pm == null) {
2046 // For some reason package manger is not available.. This will fail internally anyway,
2047 // so do not throw error and allow.
2048 return true;
2049 }
2050 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2051 }
2052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002054 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002055 }
2056
Wink Savilleb564aae2014-10-23 10:18:09 -07002057 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 if (DBG) log("dial: " + number);
2059 // No permission check needed here: This is just a wrapper around the
2060 // ACTION_DIAL intent, which is available to any app since it puts up
2061 // the UI before it does anything.
2062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 String url = createTelUrl(number);
2066 if (url == null) {
2067 return;
2068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 // PENDING: should we just silently fail if phone is offhook or ringing?
2071 PhoneConstants.State state = mCM.getState(subId);
2072 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2073 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2074 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2075 mApp.startActivity(intent);
2076 }
2077 } finally {
2078 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080 }
2081
2082 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002083 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002084 }
2085
Wink Savilleb564aae2014-10-23 10:18:09 -07002086 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 if (DBG) log("call: " + number);
2088
2089 // This is just a wrapper around the ACTION_CALL intent, but we still
2090 // need to do a permission check since we're calling startActivity()
2091 // from the context of the phone app.
2092 enforceCallPermission();
2093
Jordan Liu1617b712019-07-10 15:06:26 -07002094 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 != AppOpsManager.MODE_ALLOWED) {
2096 return;
2097 }
2098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 String url = createTelUrl(number);
2102 if (url == null) {
2103 return;
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 boolean isValid = false;
2107 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2108 if (slist != null) {
2109 for (SubscriptionInfo subInfoRecord : slist) {
2110 if (subInfoRecord.getSubscriptionId() == subId) {
2111 isValid = true;
2112 break;
2113 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002114 }
Wink Saville08874612014-08-31 19:19:58 -07002115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116 if (!isValid) {
2117 return;
2118 }
Wink Saville08874612014-08-31 19:19:58 -07002119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2121 intent.putExtra(SUBSCRIPTION_KEY, subId);
2122 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2123 mApp.startActivity(intent);
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
2126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Savilleb564aae2014-10-23 10:18:09 -07002129 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002130 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002131 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2132 }
2133
Wink Savilleb564aae2014-10-23 10:18:09 -07002134 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002135 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002136 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2137 }
2138
Wink Savilleb564aae2014-10-23 10:18:09 -07002139 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141
2142 final long identity = Binder.clearCallingIdentity();
2143 try {
2144 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2145 checkSimPin.start();
2146 return checkSimPin.unlockSim(null, pin);
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
2149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 }
2151
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2158 checkSimPuk.start();
2159 return checkSimPuk.unlockSim(puk, pin);
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
2165 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002166 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 * a synchronous one.
2168 */
2169 private static class UnlockSim extends Thread {
2170
2171 private final IccCard mSimCard;
2172
2173 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002174 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2175 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176
2177 // For replies from SimCard interface
2178 private Handler mHandler;
2179
2180 // For async handler to identify request type
2181 private static final int SUPPLY_PIN_COMPLETE = 100;
2182
2183 public UnlockSim(IccCard simCard) {
2184 mSimCard = simCard;
2185 }
2186
2187 @Override
2188 public void run() {
2189 Looper.prepare();
2190 synchronized (UnlockSim.this) {
2191 mHandler = new Handler() {
2192 @Override
2193 public void handleMessage(Message msg) {
2194 AsyncResult ar = (AsyncResult) msg.obj;
2195 switch (msg.what) {
2196 case SUPPLY_PIN_COMPLETE:
2197 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2198 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002199 mRetryCount = msg.arg1;
2200 if (ar.exception != null) {
2201 if (ar.exception instanceof CommandException &&
2202 ((CommandException)(ar.exception)).getCommandError()
2203 == CommandException.Error.PASSWORD_INCORRECT) {
2204 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002205 } //When UiccCardApp dispose,handle message and return exception
2206 else if (ar.exception instanceof CommandException &&
2207 ((CommandException) (ar.exception)).getCommandError()
2208 == CommandException.Error.ABORTED) {
2209 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002210 } else {
2211 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2212 }
2213 } else {
2214 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 mDone = true;
2217 UnlockSim.this.notifyAll();
2218 }
2219 break;
2220 }
2221 }
2222 };
2223 UnlockSim.this.notifyAll();
2224 }
2225 Looper.loop();
2226 }
2227
2228 /*
2229 * Use PIN or PUK to unlock SIM card
2230 *
2231 * If PUK is null, unlock SIM card with PIN
2232 *
2233 * If PUK is not null, unlock SIM card with PUK and set PIN code
2234 */
Wink Saville9de0f752013-10-22 19:04:03 -07002235 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236
2237 while (mHandler == null) {
2238 try {
2239 wait();
2240 } catch (InterruptedException e) {
2241 Thread.currentThread().interrupt();
2242 }
2243 }
2244 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2245
2246 if (puk == null) {
2247 mSimCard.supplyPin(pin, callback);
2248 } else {
2249 mSimCard.supplyPuk(puk, pin, callback);
2250 }
2251
2252 while (!mDone) {
2253 try {
2254 Log.d(LOG_TAG, "wait for done");
2255 wait();
2256 } catch (InterruptedException e) {
2257 // Restore the interrupted status
2258 Thread.currentThread().interrupt();
2259 }
2260 }
2261 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002262 int[] resultArray = new int[2];
2263 resultArray[0] = mResult;
2264 resultArray[1] = mRetryCount;
2265 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267 }
2268
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002269 /**
2270 * This method has been removed due to privacy and stability concerns.
2271 */
2272 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002274 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2275 return;
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
Nathan Harold1f889d82020-06-04 17:05:26 -07002278 @Override
2279 public void updateServiceLocationWithPackageName(String callingPackage) {
2280 mApp.getSystemService(AppOpsManager.class)
2281 .checkPackage(Binder.getCallingUid(), callingPackage);
2282
Nathan Haroldf096d982020-11-18 17:18:06 -08002283 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002284 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2285 // Callers targeting S have no business invoking this method.
2286 return;
2287 }
2288
2289 LocationAccessPolicy.LocationPermissionResult locationResult =
2290 LocationAccessPolicy.checkLocationPermission(mApp,
2291 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2292 .setCallingPackage(callingPackage)
2293 .setCallingFeatureId(null)
2294 .setCallingPid(Binder.getCallingPid())
2295 .setCallingUid(Binder.getCallingUid())
2296 .setMethod("updateServiceLocation")
2297 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2299 .build());
2300 // Apps that lack location permission have no business calling this method;
2301 // however, because no permission was declared in the public API, denials must
2302 // all be "soft".
2303 switch (locationResult) {
2304 case DENIED_HARD: /* fall through */
2305 case DENIED_SOFT:
2306 return;
2307 }
2308
2309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002312 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002314 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315 }
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002321 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002324 return isRadioOnWithFeature(callingPackage, null);
2325 }
2326
2327
2328 @Override
2329 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2330 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2331 callingFeatureId);
2332 }
2333
2334 @Deprecated
2335 @Override
2336 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2337 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2342 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002344 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return false;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return isRadioOnForSubscriber(subId);
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 }
2355
2356 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2362 } else {
2363 return false;
2364 }
2365 } finally {
2366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369
2370 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002371 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
Wink Saville36469e72014-06-11 15:17:00 -07002373
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 if (phone != null) {
2381 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2382 }
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002385 }
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
2388 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002389 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002390 }
2391
Wink Savilleb564aae2014-10-23 10:18:09 -07002392 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002393 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 final Phone phone = getPhone(subId);
2398 if (phone == null) {
2399 return false;
2400 }
2401 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2402 toggleRadioOnOffForSubscriber(subId);
2403 }
2404 return true;
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
Wink Saville36469e72014-06-11 15:17:00 -07002409
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002410 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002411 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002412 /*
2413 * If any of the Radios are available, it will need to be
2414 * shutdown. So return true if any Radio is available.
2415 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2419 Phone phone = PhoneFactory.getPhone(i);
2420 if (phone != null && phone.isRadioAvailable()) return true;
2421 }
2422 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2423 return false;
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002426 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002427 }
2428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002430 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 enforceModifyPermission();
2432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2436 logv("Shutting down Phone " + i);
2437 shutdownRadioUsingPhoneId(i);
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002441 }
2442 }
2443
2444 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002445 Phone phone = PhoneFactory.getPhone(phoneId);
2446 if (phone != null && phone.isRadioAvailable()) {
2447 phone.shutdownRadio();
2448 }
2449 }
2450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2457 if (defaultPhone != null) {
2458 defaultPhone.setRadioPower(turnOn);
2459 return true;
2460 } else {
2461 loge("There's no default phone.");
2462 return false;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002466 }
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 final Phone phone = getPhone(subId);
2475 if (phone != null) {
2476 phone.setRadioPower(turnOn);
2477 return true;
2478 } else {
2479 return false;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Wink Saville36469e72014-06-11 15:17:00 -07002486 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 public boolean enableDataConnectivity() {
2489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 int subId = mSubscriptionController.getDefaultDataSubId();
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002496 phone.getDataEnabledSettings().setDataEnabled(
2497 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 return true;
2499 } else {
2500 return false;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506
Wink Saville36469e72014-06-11 15:17:00 -07002507 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 public boolean disableDataConnectivity() {
2510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 int subId = mSubscriptionController.getDefaultDataSubId();
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002517 phone.getDataEnabledSettings().setDataEnabled(
2518 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 return true;
2520 } else {
2521 return false;
2522 }
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002529 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002534 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 } else {
2536 return false;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002544 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002545 }
2546
pkanwarae03a6b2016-11-06 20:37:09 -08002547 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 enforceCallPermission();
2549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2553 return;
2554 }
2555 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2556 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
pkanwar32d516d2016-10-14 19:37:38 -07002560 };
2561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2568 return false;
2569 }
2570 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002577 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002580 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 Phone phone = PhoneFactory.getPhone(slotIndex);
2584 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2585 PhoneConstantConversions.convertCallState(phone.getState());
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002592 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2594 }
2595
2596 @Override
2597 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
2602 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2603 } else {
2604 return PhoneConstantConversions.convertDataState(
2605 PhoneConstants.DataState.DISCONNECTED);
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002613 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002614 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2615 }
2616
2617 @Override
2618 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002621 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 if (phone != null) {
2623 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2624 } else {
2625 return TelephonyManager.DATA_ACTIVITY_NONE;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
2632 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002633 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002634 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002635 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002636
2637 LocationAccessPolicy.LocationPermissionResult locationResult =
2638 LocationAccessPolicy.checkLocationPermission(mApp,
2639 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2640 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002641 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002642 .setCallingPid(Binder.getCallingPid())
2643 .setCallingUid(Binder.getCallingUid())
2644 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002645 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002646 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2647 .build());
2648 switch (locationResult) {
2649 case DENIED_HARD:
2650 throw new SecurityException("Not allowed to access cell location");
2651 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002652 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2653 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002660 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002661 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Svetoslav64fad262015-04-14 14:35:21 -07002665 }
2666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002668 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002669 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2670 // registered cell info, so return a NULL country instead.
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002673 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2674 // Get default phone in this case.
2675 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2676 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002677 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002679 if (phone == null) return "";
2680 ServiceStateTracker sst = phone.getServiceStateTracker();
2681 if (sst == null) return "";
2682 LocaleTracker lt = sst.getLocaleTracker();
2683 if (lt == null) return "";
2684 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2685 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2686 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002690 }
2691
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002692 /**
2693 * This method was removed due to potential issues caused by performing partial
2694 * updates of service state, and lack of a credible use case.
2695 *
2696 * This has the ability to break the telephony implementation by disabling notification of
2697 * changes in device connectivity. DO NOT USE THIS!
2698 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002699 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public void enableLocationUpdates() {
2701 mApp.enforceCallingOrSelfPermission(
2702 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002705 /**
2706 * This method was removed due to potential issues caused by performing partial
2707 * updates of service state, and lack of a credible use case.
2708 *
2709 * This has the ability to break the telephony implementation by disabling notification of
2710 * changes in device connectivity. DO NOT USE THIS!
2711 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 @Override
2713 public void disableLocationUpdates() {
2714 mApp.enforceCallingOrSelfPermission(
2715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 @Override
2719 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002720 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2721 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002722 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002723 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2724 throw new SecurityException(
2725 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2726 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002727
Jordan Liu1617b712019-07-10 15:06:26 -07002728 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2730 return null;
2731 }
Svetoslav64fad262015-04-14 14:35:21 -07002732
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002733 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002735 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002736 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737
Nathan Haroldf180aac2018-06-01 18:43:55 -07002738 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2739 for (CellInfo ci : info) {
2740 if (ci instanceof CellInfoGsm) {
2741 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2742 } else if (ci instanceof CellInfoWcdma) {
2743 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002746 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002749 private List<CellInfo> getCachedCellInfo() {
2750 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2751 for (Phone phone : PhoneFactory.getPhones()) {
2752 List<CellInfo> info = phone.getAllCellInfo();
2753 if (info != null) cellInfos.addAll(info);
2754 }
2755 return cellInfos;
2756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757
2758 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002759 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002760 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002761 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002762
2763 LocationAccessPolicy.LocationPermissionResult locationResult =
2764 LocationAccessPolicy.checkLocationPermission(mApp,
2765 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2766 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002767 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002768 .setCallingPid(Binder.getCallingPid())
2769 .setCallingUid(Binder.getCallingUid())
2770 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002771 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002772 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2773 .build());
2774 switch (locationResult) {
2775 case DENIED_HARD:
2776 throw new SecurityException("Not allowed to access cell info");
2777 case DENIED_SOFT:
2778 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Nathan Haroldf096d982020-11-18 17:18:06 -08002781 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002782 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2783 return getCachedCellInfo();
2784 }
2785
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002786 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002787 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2791 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002792 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002793 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 if (info != null) cellInfos.addAll(info);
2795 }
2796 return cellInfos;
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 }
2800 }
2801
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002802 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002803 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2804 String callingFeatureId) {
2805 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2806 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002807 }
2808
2809 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002810 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2811 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002812 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002813 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002814 }
2815
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002816 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2817 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002818 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002819 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002820
2821 LocationAccessPolicy.LocationPermissionResult locationResult =
2822 LocationAccessPolicy.checkLocationPermission(mApp,
2823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2824 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002825 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002826 .setCallingPid(Binder.getCallingPid())
2827 .setCallingUid(Binder.getCallingUid())
2828 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002829 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2830 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002831 .build());
2832 switch (locationResult) {
2833 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 if (TelephonyPermissions
2835 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002836 // Safetynet logging for b/154934934
2837 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2838 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002839 throw new SecurityException("Not allowed to access cell info");
2840 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002841 if (TelephonyPermissions
2842 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002843 // Safetynet logging for b/154934934
2844 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2845 }
Nathan Harold5320c422019-05-09 10:26:08 -07002846 try {
2847 cb.onCellInfo(new ArrayList<CellInfo>());
2848 } catch (RemoteException re) {
2849 // Drop without consequences
2850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002851 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002852 }
2853
Nathan Harolda939a962019-05-09 10:13:47 -07002854
2855 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002856 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2857
2858 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2859 }
2860
2861 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002863 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Shishir Agrawala9f32182016-04-12 12:00:16 -07002874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002876 Phone phone = PhoneFactory.getPhone(slotIndex);
2877 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 return null;
2879 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002880 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002881 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002882 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002883 return null;
2884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 return phone.getImei();
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
2891 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002892 }
2893
2894 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002895 public String getTypeAllocationCodeForSlot(int slotIndex) {
2896 Phone phone = PhoneFactory.getPhone(slotIndex);
2897 String tac = null;
2898 if (phone != null) {
2899 String imei = phone.getImei();
2900 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2901 }
2902 return tac;
2903 }
2904
2905 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002907 Phone phone = PhoneFactory.getPhone(slotIndex);
2908 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002909 return null;
2910 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911
Jeff Davidson913390f2018-02-23 17:11:49 -08002912 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002913 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002914 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002915 return null;
2916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 return phone.getMeid();
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
Jack Yu2af8d712017-03-15 17:14:14 -07002924 }
2925
2926 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002927 public String getManufacturerCodeForSlot(int slotIndex) {
2928 Phone phone = PhoneFactory.getPhone(slotIndex);
2929 String manufacturerCode = null;
2930 if (phone != null) {
2931 String meid = phone.getMeid();
2932 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2933 }
2934 return manufacturerCode;
2935 }
2936
2937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002938 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2939 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002940 Phone phone = PhoneFactory.getPhone(slotIndex);
2941 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002942 return null;
2943 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002944 int subId = phone.getSubId();
2945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002946 mApp, subId, callingPackage, callingFeatureId,
2947 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002948 return null;
2949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 return phone.getDeviceSvn();
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002957 }
2958
fionaxu43304da2017-11-27 22:51:16 -08002959 @Override
2960 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
fionaxu43304da2017-11-27 22:51:16 -08002968 }
2969
2970 @Override
2971 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
fionaxu43304da2017-11-27 22:51:16 -08002979 }
2980
calvinpanffe225e2018-11-01 19:43:06 +08002981 @Override
chen xu0026ca62019-03-06 15:28:50 -08002982 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 final Phone phone = getPhone(subId);
2986 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002987 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
chen xu0026ca62019-03-06 15:28:50 -08002994 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002998 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
chen xu651eec72018-11-11 19:03:44 -08003004 @Override
chen xu864e11c2018-12-06 22:10:03 -08003005 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3006 if (!isSubscriptionMccMnc) {
3007 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3008 }
chen xu651eec72018-11-11 19:03:44 -08003009 final Phone phone = PhoneFactory.getPhone(slotIndex);
3010 if (phone == null) {
3011 return TelephonyManager.UNKNOWN_CARRIER_ID;
3012 }
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 //
3022 // Internal helper methods.
3023 //
3024
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003025 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3027 *
3028 * @throws SecurityException if the caller does not have the required permission
3029 */
3030 private void enforceModifyPermission() {
3031 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3032 }
3033
Shuo Qiancd19c462020-01-16 20:51:11 -08003034 /**
3035 * Make sure the caller is system.
3036 *
3037 * @throws SecurityException if the caller is not system.
3038 */
3039 private void enforceSystemCaller() {
3040 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3041 throw new SecurityException("Caller must be system");
3042 }
3043 }
3044
Shuo Qian3b6ee772019-11-13 17:43:31 -08003045 private void enforceActiveEmergencySessionPermission() {
3046 mApp.enforceCallingOrSelfPermission(
3047 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3048 }
3049
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 /**
3051 * Make sure the caller has the CALL_PHONE permission.
3052 *
3053 * @throws SecurityException if the caller does not have the required permission
3054 */
3055 private void enforceCallPermission() {
3056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3057 }
3058
paulhu5a773602019-08-23 19:17:33 +08003059 private void enforceSettingsPermission() {
3060 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003061 }
3062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 private String createTelUrl(String number) {
3064 if (TextUtils.isEmpty(number)) {
3065 return null;
3066 }
3067
Jake Hambye994d462014-02-03 13:10:13 -08003068 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 }
3070
Ihab Awadf9e92732013-12-05 18:02:52 -08003071 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3073 }
3074
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003075 private static void logv(String msg) {
3076 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3077 }
3078
Ihab Awadf9e92732013-12-05 18:02:52 -08003079 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3081 }
3082
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003083 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003085 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003086 }
3087
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003089 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final Phone phone = PhoneFactory.getPhone(slotIndex);
3093 if (phone == null) {
3094 return PhoneConstants.PHONE_TYPE_NONE;
3095 } else {
3096 return phone.getPhoneType();
3097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 }
3102
3103 /**
3104 * Returns the CDMA ERI icon index to display
3105 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003107 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3108 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3109 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003110 }
3111
Sanket Padawe356d7632015-06-22 14:03:32 -07003112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003113 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3114 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003116 mApp, subId, callingPackage, callingFeatureId,
3117 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003118 return -1;
3119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 final Phone phone = getPhone(subId);
3124 if (phone != null) {
3125 return phone.getCdmaEriIconIndex();
3126 } else {
3127 return -1;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 /**
3135 * Returns the CDMA ERI icon mode,
3136 * 0 - ON
3137 * 1 - FLASHING
3138 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003140 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3141 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3142 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003143 }
3144
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003146 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3147 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003149 mApp, subId, callingPackage, callingFeatureId,
3150 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003151 return -1;
3152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 final Phone phone = getPhone(subId);
3157 if (phone != null) {
3158 return phone.getCdmaEriIconMode();
3159 } else {
3160 return -1;
3161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
3166
3167 /**
3168 * Returns the CDMA ERI text,
3169 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003171 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3172 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3173 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003174 }
3175
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003177 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3178 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 mApp, subId, callingPackage, callingFeatureId,
3181 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003182 return null;
3183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 if (phone != null) {
3189 return phone.getCdmaEriText();
3190 } else {
3191 return null;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003199 * Returns the CDMA MDN.
3200 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003201 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003202 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3204 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 return phone.getLine1Number();
3211 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 return null;
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003217 }
3218 }
3219
3220 /**
3221 * Returns the CDMA MIN.
3222 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003224 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3226 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 final Phone phone = getPhone(subId);
3231 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3232 return phone.getCdmaMin();
3233 } else {
3234 return null;
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003238 }
3239 }
3240
Hall Liud892bec2018-11-30 14:51:45 -08003241 @Override
3242 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3243 INumberVerificationCallback callback, String callingPackage) {
3244 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3245 != PERMISSION_GRANTED) {
3246 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3247 }
3248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3249
3250 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3251 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3252 throw new SecurityException("Calling package must be configured in the device config");
3253 }
3254
3255 if (range == null) {
3256 throw new NullPointerException("Range must be non-null");
3257 }
3258
3259 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003260 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003261
3262 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3263 }
3264
Junda Liuca05d5d2014-08-14 22:36:34 -07003265 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 * Returns true if CDMA provisioning needs to run.
3267 */
3268 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 }
3276
3277 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003278 * Sets the voice mail number of a given subId.
3279 */
3280 @Override
3281 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3283 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3288 new Pair<String, String>(alphaTag, number), new Integer(subId));
3289 return success;
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003293 }
3294
Ta-wei Yen87c49842016-05-13 21:19:52 -07003295 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003296 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003298 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3299 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003300 if (!TextUtils.equals(callingPackage, systemDialer)) {
3301 throw new SecurityException("caller must be system dialer");
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3307 if (phoneAccountHandle == null) {
3308 return null;
3309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 } finally {
3312 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003313 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003314 }
3315
3316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003317 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3318 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003321 mApp, subId, callingPackage, callingFeatureId,
3322 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003323 return null;
3324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003326 final long identity = Binder.clearCallingIdentity();
3327 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003329 } finally {
3330 Binder.restoreCallingIdentity(identity);
3331 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003332 }
3333
3334 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003335 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3336 VisualVoicemailSmsFilterSettings settings) {
3337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003342 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003346 }
3347
3348 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003349 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003355 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003359 }
3360
3361 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003362 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3363 String callingPackage, int subId) {
3364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365
3366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003369 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370 } finally {
3371 Binder.restoreCallingIdentity(identity);
3372 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003373 }
3374
3375 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003376 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003386 }
3387
3388 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003389 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3390 String callingAttributionTag, int subId, String number, int port, String text,
3391 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003393 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003394 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003395 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003396 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3397 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003398 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003399
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003400 /**
fionaxu0152e512016-11-14 13:36:14 -08003401 * Sets the voice activation state of a given subId.
3402 */
3403 @Override
3404 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3406 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 phone.setVoiceActivationState(activationState);
3413 } else {
3414 loge("setVoiceActivationState fails with invalid subId: " + subId);
3415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003418 }
3419 }
3420
3421 /**
3422 * Sets the data activation state of a given subId.
3423 */
3424 @Override
3425 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3427 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 final Phone phone = getPhone(subId);
3432 if (phone != null) {
3433 phone.setDataActivationState(activationState);
3434 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003435 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436 }
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003439 }
3440 }
3441
3442 /**
3443 * Returns the voice activation state of a given subId.
3444 */
3445 @Override
3446 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
fionaxu0152e512016-11-14 13:36:14 -08003449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 if (phone != null) {
3453 return phone.getVoiceActivationState();
3454 } else {
3455 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003459 }
3460 }
3461
3462 /**
3463 * Returns the data activation state of a given subId.
3464 */
3465 @Override
3466 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468
fionaxu0152e512016-11-14 13:36:14 -08003469 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 if (phone != null) {
3473 return phone.getDataActivationState();
3474 } else {
3475 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3476 }
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003479 }
3480 }
3481
3482 /**
Wink Saville36469e72014-06-11 15:17:00 -07003483 * Returns the unread count of voicemails for a subId
3484 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3487 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 mApp, subId, callingPackage, callingFeatureId,
3490 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003491 return 0;
3492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 if (phone != null) {
3497 return phone.getVoiceMessageCount();
3498 } else {
3499 return 0;
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 }
3505
3506 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003507 * returns true, if the device is in a state where both voice and data
3508 * are supported simultaneously. This can change based on location or network condition.
3509 */
3510 @Override
3511 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 final Phone phone = getPhone(subId);
3515 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003519 }
3520
3521 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003522 * Send the dialer code if called from the current default dialer or the caller has
3523 * carrier privilege.
3524 * @param inputCode The dialer code to send
3525 */
3526 @Override
3527 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003530 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3531 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003532 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003533 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
fionaxu235cc5e2017-03-06 22:25:57 -08003543 }
3544
Pengquan Menga1bb6272018-09-06 09:59:22 -07003545 @Override
3546 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003547 TelephonyPermissions
3548 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3549 mApp, subId, "getNetworkSelectionMode");
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 if (!isActiveSubscription(subId)) {
3553 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3554 }
3555 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003559 }
3560
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003562 public boolean isInEmergencySmsMode() {
3563 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 for (Phone phone : PhoneFactory.getPhones()) {
3567 if (phone.isInEmergencySmsMode()) {
3568 return true;
3569 }
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 return false;
3575 }
3576
shilu366312e2019-12-17 09:28:10 -08003577 /**
3578 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3579 * @param subId The subscription to use to check the configuration.
3580 * @param c The callback that will be used to send the result.
3581 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003582 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003583 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3584 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003585 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3586 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003587
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003588 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3589 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3590 "IMS not available on device.");
3591 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 final long token = Binder.clearCallingIdentity();
3593 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003597 } catch (ImsException e) {
3598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 } finally {
3600 Binder.restoreCallingIdentity(token);
3601 }
3602 }
3603
shilu366312e2019-12-17 09:28:10 -08003604 /**
3605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3606 * @param subId The subscription to use to check the configuration.
3607 * @param c The callback that will be used to send the result.
3608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003610 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003611 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3612 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3615 }
Meng Wangafbc5852019-09-19 17:37:13 -07003616 final long token = Binder.clearCallingIdentity();
3617 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003618 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3620 .removeRegistrationCallbackForSubscription(c, subId);
3621 } catch (ImsException e) {
3622 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3623 + "is inactive, ignoring unregister.");
3624 // If the subscription is no longer active, just return, since the callback
3625 // will already have been removed internally.
3626 } finally {
3627 Binder.restoreCallingIdentity(token);
3628 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 }
3630
Brad Ebingera34a6c22019-10-22 17:36:18 -07003631 /**
3632 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3633 */
3634 @Override
3635 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3636 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3637 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3638 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3639 "IMS not available on device.");
3640 }
3641 final long token = Binder.clearCallingIdentity();
3642 try {
3643 Phone phone = getPhone(subId);
3644 if (phone == null) {
3645 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3646 + subId + "'");
3647 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3648 }
3649 phone.getImsRegistrationState(regState -> {
3650 try {
3651 consumer.accept((regState == null)
3652 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3653 } catch (RemoteException e) {
3654 // Ignore if the remote process is no longer available to call back.
3655 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3656 }
3657 });
3658 } finally {
3659 Binder.restoreCallingIdentity(token);
3660 }
3661 }
3662
3663 /**
3664 * Get the transport type for the IMS service registration state.
3665 */
3666 @Override
3667 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003668 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3669 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003670 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3672 "IMS not available on device.");
3673 }
3674 final long token = Binder.clearCallingIdentity();
3675 try {
3676 Phone phone = getPhone(subId);
3677 if (phone == null) {
3678 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3679 + subId + "'");
3680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3681 }
3682 phone.getImsRegistrationTech(regTech -> {
3683 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3684 int regTechConverted = (regTech == null)
3685 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3686 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3687 regTechConverted);
3688 try {
3689 consumer.accept(regTechConverted);
3690 } catch (RemoteException e) {
3691 // Ignore if the remote process is no longer available to call back.
3692 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3693 }
3694 });
3695 } finally {
3696 Binder.restoreCallingIdentity(token);
3697 }
3698 }
3699
shilu366312e2019-12-17 09:28:10 -08003700 /**
3701 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3702 * @param subId The subscription to use to check the configuration.
3703 * @param c The callback that will be used to send the result.
3704 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003706 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3707 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003708 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3709 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3712 "IMS not available on device.");
3713 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3715 final long token = Binder.clearCallingIdentity();
3716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (ImsException e) {
3720 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 } finally {
3722 Binder.restoreCallingIdentity(token);
3723 }
3724 }
3725
shilu366312e2019-12-17 09:28:10 -08003726 /**
3727 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3728 * @param subId The subscription to use to check the configuration.
3729 * @param c The callback that will be used to send the result.
3730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003732 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003733 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3734 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3737 }
Meng Wangafbc5852019-09-19 17:37:13 -07003738
3739 final long token = Binder.clearCallingIdentity();
3740 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003741 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003743 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003744 } catch (ImsException e) {
3745 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3746 + "is inactive, ignoring unregister.");
3747 // If the subscription is no longer active, just return, since the callback
3748 // will already have been removed internally.
3749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 }
3753
3754 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003755 public boolean isCapable(int subId, int capability, int regTech) {
3756 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3758 final long token = Binder.clearCallingIdentity();
3759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3764 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003766 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3767 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 } finally {
3769 Binder.restoreCallingIdentity(token);
3770 }
3771 }
3772
3773 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003774 public boolean isAvailable(int subId, int capability, int regTech) {
3775 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 final long token = Binder.clearCallingIdentity();
3777 try {
3778 Phone phone = getPhone(subId);
3779 if (phone == null) return false;
3780 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003781 } catch (com.android.ims.ImsException e) {
3782 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3783 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 } finally {
3785 Binder.restoreCallingIdentity(token);
3786 }
3787 }
3788
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003789 /**
3790 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3791 * subscription.
3792 * @param subId The subscription to use to check the configuration.
3793 * @param callback The callback that will be used to send the result.
3794 * @param capability The MmTelFeature capability that will be used to send the result.
3795 * @param transportType The transport type of the MmTelFeature capability.
3796 */
3797 @Override
3798 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3799 int transportType) {
3800 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3801 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3803 "IMS not available on device.");
3804 }
3805 final long token = Binder.clearCallingIdentity();
3806 try {
3807 int slotId = getSlotIndex(subId);
3808 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3809 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3810 + subId + "'");
3811 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3812 }
3813 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3814 transportType, aBoolean -> {
3815 try {
3816 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3817 } catch (RemoteException e) {
3818 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3819 + "running. Ignore");
3820 }
3821 });
3822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
3825 }
3826
shilu366312e2019-12-17 09:28:10 -08003827 /**
3828 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3829 * @param subId The subscription to use to check the configuration.
3830 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 @Override
3832 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003833 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3834 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003835
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3837 final long token = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (ImsException e) {
3842 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 } finally {
3844 Binder.restoreCallingIdentity(token);
3845 }
3846 }
3847
3848 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003849 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003851 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003857 } catch (ImsException e) {
3858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
shilu366312e2019-12-17 09:28:10 -08003864 /**
3865 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3866 * @param subId The subscription to use to check the configuration.
3867 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003869 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003870 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3871 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3876 } catch (ImsException e) {
3877 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
3881 }
3882
3883 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003884 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003886 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (ImsException e) {
3892 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
3896 }
3897
shilu366312e2019-12-17 09:28:10 -08003898 /**
3899 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3900 * @param subId The subscription to use to check the configuration.
3901 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 @Override
3903 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003904 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3905 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916 }
3917
3918 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003919 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003921 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003925 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (ImsException e) {
3927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 }
3932
shilu366312e2019-12-17 09:28:10 -08003933 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08003934 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
3935 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3936 * @param subId The subscription to use to check the configuration.
3937 */
3938 @Override
3939 public boolean isCrossSimCallingEnabledByUser(int subId) {
3940 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3941 mApp, subId, "isCrossSimCallingEnabledByUser");
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3945 return ImsManager.getInstance(mApp,
3946 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
3947 } catch (ImsException e) {
3948 throw new ServiceSpecificException(e.getCode());
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 }
3953
3954 /**
3955 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
3956 * Requires MODIFY_PHONE_STATE permission.
3957 * @param subId The subscription to use to check the configuration.
3958 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
3959 * false otherwise
3960 */
3961 @Override
3962 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
3963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3964 "setCrossSimCallingEnabled");
3965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3968 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3969 .setCrossSimCallingEnabled(isEnabled);
3970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
3975 }
3976
3977 /**
shilu366312e2019-12-17 09:28:10 -08003978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 @Override
3982 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003983 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3984 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (ImsException e) {
3991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996
3997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003998 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004000 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004006 } catch (ImsException e) {
4007 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
4011 }
4012
4013 @Override
4014 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4016 "setVoWiFiNonPersistent");
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004021 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (ImsException e) {
4023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
4027 }
4028
shilu366312e2019-12-17 09:28:10 -08004029 /**
4030 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4031 * @param subId The subscription to use to check the configuration.
4032 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 @Override
4034 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004035 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4036 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (ImsException e) {
4043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
4047 }
4048
4049 @Override
4050 public void setVoWiFiModeSetting(int subId, int mode) {
4051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4052 "setVoWiFiModeSetting");
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004058 } catch (ImsException e) {
4059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
4063 }
4064
4065 @Override
4066 public int getVoWiFiRoamingModeSetting(int subId) {
4067 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
4080 @Override
4081 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4083 "setVoWiFiRoamingModeSetting");
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
4096 @Override
4097 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4099 "setRttCapabilityEnabled");
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4104 } catch (ImsException e) {
4105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
4109 }
4110
shilu366312e2019-12-17 09:28:10 -08004111 /**
4112 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4113 * @param subId The subscription to use to check the configuration.
4114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 @Override
4116 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004117 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4118 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004122 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004131 @Override
4132 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4133 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004136 if (!isImsAvailableOnDevice()) {
4137 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4138 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004139 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004142 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
4151 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4152 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4153 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004154 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4155 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4156 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004157 try {
4158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004160 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004162 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4163 + "is inactive, ignoring unregister.");
4164 // If the subscription is no longer active, just return, since the callback will already
4165 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
allenwtsu99c623b2020-01-03 18:24:23 +08004171
4172 private void checkModifyPhoneStatePermission(int subId, String message) {
4173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4174 message);
4175 }
4176
4177 private boolean isImsProvisioningRequired(int subId, int capability,
4178 boolean isMmtelCapability) {
4179 Phone phone = getPhone(subId);
4180 if (phone == null) {
4181 loge("phone instance null for subid " + subId);
4182 return false;
4183 }
4184 if (isMmtelCapability) {
4185 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4186 return false;
4187 }
4188 } else {
4189 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4190 return false;
4191 }
4192 }
4193 return true;
4194 }
4195
4196 @Override
4197 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4198 boolean isProvisioned) {
4199 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4200
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4204 if (!isImsProvisioningRequired(subId, capability, false)) {
4205 return;
4206 }
4207
4208 // this capability requires provisioning, route to the correct API.
4209 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4210 switch (capability) {
4211 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4212 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4213 ims.setEabProvisioned(isProvisioned);
4214 break;
4215 default: {
4216 throw new IllegalArgumentException("Tried to set provisioning for "
4217 + "rcs capability '" + capability + "', which does not require "
4218 + "provisioning.");
4219 }
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224
4225 }
4226
4227
4228 @Override
4229 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4230 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4234 if (!isImsProvisioningRequired(subId, capability, false)) {
4235 return true;
4236 }
4237
4238 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4239 switch (capability) {
4240 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4241 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4242 return ims.isEabProvisionedOnDevice();
4243
4244 default: {
4245 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4246 + "capability '" + capability + "', which does not require "
4247 + "provisioning.");
4248 }
4249 }
4250
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004256 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004257 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4258 boolean isProvisioned) {
4259 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4260 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4261 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4262 }
allenwtsu99c623b2020-01-03 18:24:23 +08004263 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004267 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004268 return;
4269 }
4270
4271 // this capability requires provisioning, route to the correct API.
4272 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4273 switch (capability) {
4274 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4275 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4276 ims.setVolteProvisioned(isProvisioned);
4277 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4278 ims.setWfcProvisioned(isProvisioned);
4279 }
4280 break;
4281 }
4282 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4283 // There is currently no difference in VT provisioning type.
4284 ims.setVtProvisioned(isProvisioned);
4285 break;
4286 }
4287 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4288 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4289 // change the capability of the feature instead if needed.
4290 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4291 == isProvisioned) {
4292 // No change in provisioning.
4293 return;
4294 }
4295 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4296 try {
4297 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004298 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004299 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4300 + ", Exception" + e.getMessage());
4301 }
4302 break;
4303 }
4304 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004305 throw new IllegalArgumentException("Tried to set provisioning for "
4306 + "MmTel capability '" + capability + "', which does not require "
4307 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004308 }
4309 }
4310
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
4317 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4318 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4319 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4320 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4321 }
4322 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004326 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004327 return true;
4328 }
4329
4330 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4331 switch (capability) {
4332 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4333 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4334 return ims.isVolteProvisionedOnDevice();
4335 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4336 return ims.isWfcProvisionedOnDevice();
4337 }
4338 // This should never happen, since we are checking tech above to make sure it
4339 // is either LTE or IWLAN.
4340 throw new IllegalArgumentException("Invalid radio technology for voice "
4341 + "capability.");
4342 }
4343 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4344 // There is currently no difference in VT provisioning type.
4345 return ims.isVtProvisionedOnDevice();
4346 }
4347 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4348 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4349 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4350 }
4351 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004352 throw new IllegalArgumentException(
4353 "Tried to get provisioning for MmTel capability '" + capability
4354 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004355 }
4356 }
4357
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
4364 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4365 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4366 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4367 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4368 }
4369 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4370 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4371 return (provisionedBits & capability) > 0;
4372 }
4373
4374 @Override
4375 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4376 boolean isProvisioned) {
4377 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4378 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4379 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4380 }
4381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4382 "setProvisioningStatusForCapability");
4383 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4384 // If the current provisioning status for capability already matches isProvisioned,
4385 // do nothing.
4386 if (((provisionedBits & capability) > 0) == isProvisioned) {
4387 return;
4388 }
4389 if (isProvisioned) {
4390 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4391 } else {
4392 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4393 }
4394 }
4395
4396 /**
4397 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4398 * technology. The bitfield should mirror the bitfield defined by
4399 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4400 */
4401 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4402 String key = getMmTelProvisioningKey(subId, tech);
4403 // Default is no capabilities are provisioned.
4404 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4405 }
4406
4407 /**
4408 * Sets the MmTel capability provisioning bitfield (defined by
4409 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4410 * technology specified.
4411 *
4412 * Note: This is a synchronous command and should not be called on UI thread.
4413 */
4414 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4415 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4416 String key = getMmTelProvisioningKey(subId, tech);
4417 editor.putInt(key, newField);
4418 editor.commit();
4419 }
4420
4421 private static String getMmTelProvisioningKey(int subId, int tech) {
4422 // resulting key is provision_ims_mmtel_{subId}_{tech}
4423 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4424 }
4425
4426 /**
4427 * Query CarrierConfig to see if the specified capability requires provisioning for the
4428 * carrier associated with the subscription id.
4429 */
4430 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4431 int capability) {
4432 CarrierConfigManager configManager = new CarrierConfigManager(context);
4433 PersistableBundle c = configManager.getConfigForSubId(subId);
4434 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004435 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004436 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4437 false);
4438 boolean requireVoiceVtProvisioning = c.getBoolean(
4439 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4440
4441 // First check to make sure that the capability requires provisioning.
4442 switch (capability) {
4443 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4444 // intentional fallthrough
4445 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4446 if (requireVoiceVtProvisioning) {
4447 // Voice and Video requires provisioning
4448 return true;
4449 }
4450 break;
4451 }
4452 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4453 if (requireUtProvisioning) {
4454 // UT requires provisioning
4455 return true;
4456 }
4457 break;
4458 }
4459 }
4460 return false;
4461 }
4462
allenwtsu99c623b2020-01-03 18:24:23 +08004463 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4464 int capability) {
4465 CarrierConfigManager configManager = new CarrierConfigManager(context);
4466 PersistableBundle c = configManager.getConfigForSubId(subId);
4467
4468 boolean requireRcsProvisioning = c.getBoolean(
4469 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4470
4471 // First check to make sure that the capability requires provisioning.
4472 switch (capability) {
4473 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4474 // intentional fallthrough
4475 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4476 if (requireRcsProvisioning) {
4477 // OPTION or PRESENCE requires provisioning
4478 return true;
4479 }
4480 break;
4481 }
4482 }
4483 return false;
4484 }
4485
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004486 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004487 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004488 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4489 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4490 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004491 enforceReadPrivilegedPermission("getImsProvisioningInt");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004495 int slotId = getSlotIndex(subId);
4496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4497 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4498 + subId + "' for key:" + key);
4499 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4500 }
4501 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4504 + subId + "' for key:" + key);
4505 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4514 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4515 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004516 enforceReadPrivilegedPermission("getImsProvisioningString");
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 int slotId = getSlotIndex(subId);
4521 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4522 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4523 + subId + "' for key:" + key);
4524 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4525 }
4526 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004528 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4529 + subId + "' for key:" + key);
4530 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
4534 }
4535
4536 @Override
4537 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4539 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4540 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4542 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 final long identity = Binder.clearCallingIdentity();
4544 try {
4545 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004546 int slotId = getSlotIndex(subId);
4547 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4548 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4549 + subId + "' for key:" + key);
4550 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4551 }
4552 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004554 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4555 + "' for key:" + key);
4556 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
4563 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4565 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4566 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4568 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 int slotId = getSlotIndex(subId);
4573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4574 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4575 + subId + "' for key:" + key);
4576 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4577 }
4578 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4581 + "' for key:" + key);
4582 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004588 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004589 int slotId = SubscriptionManager.getSlotIndex(subId);
4590 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004591 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4592 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 }
4594 return slotId;
4595 }
4596
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 private int getSlotIndex(int subId) {
4598 int slotId = SubscriptionManager.getSlotIndex(subId);
4599 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4600 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4601 }
4602 return slotId;
4603 }
4604
Wink Saville36469e72014-06-11 15:17:00 -07004605 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004606 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004607 */
4608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004609 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4610 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004611 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004612 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004613 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004614 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004615 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004616 mApp, subId, callingPackage, callingFeatureId,
4617 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4619 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
4622 try {
4623 final Phone phone = getPhone(subId);
4624 if (phone != null) {
4625 return phone.getServiceState().getDataNetworkType();
4626 } else {
4627 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4628 }
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004632 }
4633
4634 /**
4635 * Returns the data network type
4636 */
4637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004638 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4639 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4640 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004641 }
4642
4643 /**
4644 * Returns the data network type for a subId
4645 */
4646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004647 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004650 mApp, subId, callingPackage, callingFeatureId,
4651 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004652 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4653 }
4654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 final Phone phone = getPhone(subId);
4658 if (phone != null) {
4659 return phone.getServiceState().getDataNetworkType();
4660 } else {
4661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4662 }
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004666 }
4667
4668 /**
Wink Saville36469e72014-06-11 15:17:00 -07004669 * Returns the Voice network type for a subId
4670 */
4671 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004672 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4673 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004675 mApp, subId, callingPackage, callingFeatureId,
4676 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004677 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4678 }
4679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 final long identity = Binder.clearCallingIdentity();
4681 try {
4682 final Phone phone = getPhone(subId);
4683 if (phone != null) {
4684 return phone.getServiceState().getVoiceNetworkType();
4685 } else {
4686 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004691 }
4692
4693 /**
4694 * @return true if a ICC card is present
4695 */
4696 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004697 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004698 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4699 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004700 }
4701
4702 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004703 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004704 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004705 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004706 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 final Phone phone = PhoneFactory.getPhone(slotIndex);
4710 if (phone != null) {
4711 return phone.getIccCard().hasIccCard();
4712 } else {
4713 return false;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004718 }
4719
4720 /**
4721 * Return if the current radio is LTE on CDMA. This
4722 * is a tri-state return value as for a period of time
4723 * the mode may be unknown.
4724 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004725 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004726 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004727 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004728 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004730 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4731 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4732 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004733 }
4734
Sanket Padawe356d7632015-06-22 14:03:32 -07004735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004736 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4737 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004738 try {
4739 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4740 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004741 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4742 }
4743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 final Phone phone = getPhone(subId);
4747 if (phone == null) {
4748 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4749 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004750 return TelephonyProperties.lte_on_cdma_device()
4751 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 }
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004755 }
Wink Saville36469e72014-06-11 15:17:00 -07004756 }
4757
Wink Saville36469e72014-06-11 15:17:00 -07004758 /**
4759 * {@hide}
4760 * Returns Default subId, 0 in the case of single standby.
4761 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004762 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004763 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004764 }
4765
Shishir Agrawala9f32182016-04-12 12:00:16 -07004766 private int getSlotForDefaultSubscription() {
4767 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4768 }
4769
Wink Savilleb564aae2014-10-23 10:18:09 -07004770 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004771 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004772 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004773
Pengquan Menge92a50d2018-09-21 15:54:48 -07004774 private boolean isActiveSubscription(int subId) {
4775 return mSubscriptionController.isActiveSubId(subId);
4776 }
4777
Ihab Awadf2177b72013-11-25 13:33:23 -08004778 /**
4779 * @see android.telephony.TelephonyManager.WifiCallingChoices
4780 */
4781 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 final long identity = Binder.clearCallingIdentity();
4783 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004784 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4786 getWhenToMakeWifiCallsDefaultPreference());
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004790 }
4791
4792 /**
4793 * @see android.telephony.TelephonyManager.WifiCallingChoices
4794 */
4795 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004799 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004804 }
4805
Sailesh Nepald1e68152013-12-12 19:08:02 -08004806 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004807 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004808 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004809 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004810
Jordan Liu4c733742019-02-28 12:03:40 -08004811 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4812 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4813 if (phoneId == -1) {
4814 throw new IllegalArgumentException("Given slot index: " + slotIndex
4815 + " does not correspond to an active phone");
4816 }
4817 return PhoneFactory.getPhone(phoneId);
4818 }
4819
Shishir Agrawal566b7612013-10-28 14:41:00 -07004820 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004821 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4822 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4824 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004826 if (DBG) {
4827 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4828 }
4829 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4830 p2);
4831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004832
Jordan Liu4c733742019-02-28 12:03:40 -08004833
4834 @Override
4835 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4836 int slotIndex, String callingPackage, String aid, int p2) {
4837 enforceModifyPermission();
4838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4839 if (DBG) {
4840 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4841 }
4842 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4843 callingPackage, aid, p2);
4844 }
4845
4846 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4847 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 if (TextUtils.equals(ISDR_AID, aid)) {
4851 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004852 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4853 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 if (bestComponent == null
4855 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4856 loge("The calling package is not allowed to access ISD-R.");
4857 throw new SecurityException(
4858 "The calling package is not allowed to access ISD-R.");
4859 }
Derek Tan740e1672017-06-27 14:56:27 -07004860 }
Derek Tan740e1672017-06-27 14:56:27 -07004861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004863 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4864 null /* workSource */);
4865 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 return response;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004870 }
4871
4872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004873 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4875 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004876 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4877 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4878 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004879
Jordan Liu4c733742019-02-28 12:03:40 -08004880 @Override
4881 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4882 enforceModifyPermission();
4883 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4884 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4885 channel);
4886 }
4887
4888 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 if (channel < 0) {
4892 return false;
4893 }
Jordan Liu4c733742019-02-28 12:03:40 -08004894 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4895 null /* workSource */);
4896 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 return success;
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004901 }
4902
4903 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004904 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4907 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004908 if (DBG) {
4909 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4910 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4911 + p3 + " data=" + data);
4912 }
4913 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4914 command, p1, p2, p3, data);
4915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917 @Override
4918 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4919 int command, int p1, int p2, int p3, String data) {
4920 enforceModifyPermission();
4921 if (DBG) {
4922 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4923 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4924 + p3 + " data=" + data);
4925 }
4926 return iccTransmitApduLogicalChannelWithPermission(
4927 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4928 data);
4929 }
4930
4931 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4932 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004935 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 return "";
4937 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004940 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 // Append the returned status code to the end of the response payload.
4945 String s = Integer.toHexString(
4946 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4947 if (response.payload != null) {
4948 s = IccUtils.bytesToHexString(response.payload) + s;
4949 }
4950 return s;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004953 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004954 }
Jake Hambye994d462014-02-03 13:10:13 -08004955
Evan Charltonc66da362014-05-16 14:06:40 -07004956 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004957 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4958 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004962 if (DBG) {
4963 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4964 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4965 }
4966 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4967 cla, command, p1, p2, p3, data);
4968 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004969
Jordan Liu4c733742019-02-28 12:03:40 -08004970 @Override
4971 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4972 int command, int p1, int p2, int p3, String data) {
4973 enforceModifyPermission();
4974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4975 if (DBG) {
4976 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4977 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4978 + " data=" + data);
4979 }
4980
4981 return iccTransmitApduBasicChannelWithPermission(
4982 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4983 p2, p3, data);
4984 }
4985
4986 // open APDU basic channel assuming the caller has sufficient permissions
4987 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4988 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4992 && TextUtils.equals(ISDR_AID, data)) {
4993 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004994 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4995 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 if (bestComponent == null
4997 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4998 loge("The calling package is not allowed to select ISD-R.");
4999 throw new SecurityException(
5000 "The calling package is not allowed to select ISD-R.");
5001 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005002 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005005 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5006 null /* workSource */);
5007 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 // Append the returned status code to the end of the response payload.
5010 String s = Integer.toHexString(
5011 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5012 if (response.payload != null) {
5013 s = IccUtils.bytesToHexString(response.payload) + s;
5014 }
5015 return s;
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005018 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005019 }
5020
5021 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005022 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005023 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5025 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
5029 if (DBG) {
5030 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5031 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5032 }
5033
5034 IccIoResult response =
5035 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5036 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5037 subId);
5038
5039 if (DBG) {
5040 log("Exchange SIM_IO [R]" + response);
5041 }
5042
5043 byte[] result = null;
5044 int length = 2;
5045 if (response.payload != null) {
5046 length = 2 + response.payload.length;
5047 result = new byte[length];
5048 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5049 } else {
5050 result = new byte[length];
5051 }
5052
5053 result[length - 1] = (byte) response.sw2;
5054 result[length - 2] = (byte) response.sw1;
5055 return result;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005059 }
5060
Nathan Haroldb3014052017-01-25 15:57:32 -08005061 /**
5062 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5063 * on a particular subscription
5064 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005065 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5066 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005069 return null;
5070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 if (appType != TelephonyManager.APPTYPE_USIM
5075 && appType != TelephonyManager.APPTYPE_SIM) {
5076 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5077 return null;
5078 }
5079 Object response = sendRequest(
5080 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5081 if (response instanceof String[]) {
5082 return (String[]) response;
5083 }
yincheng zhao2737e882019-09-06 17:06:54 -07005084 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005086 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005089 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005090 }
5091
yincheng zhao2737e882019-09-06 17:06:54 -07005092 /**
5093 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5094 * subscription.
5095 *
5096 * @param subId the id of the subscription.
5097 * @param appType the uicc app type, must be USIM or SIM.
5098 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5099 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005100 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005101 * @return number of fplmns that is successfully written to the SIM.
5102 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005103 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5104 String callingFeatureId) {
5105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5106 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005107 if (DBG) logv("no permissions for setForbiddenplmns");
5108 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5109 }
5110 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5111 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5112 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5113 }
5114 if (fplmns == null) {
5115 throw new IllegalArgumentException("Fplmn List provided is null");
5116 }
5117 for (String fplmn : fplmns) {
5118 if (!CellIdentity.isValidPlmn(fplmn)) {
5119 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5120 }
5121 }
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 Object response = sendRequest(
5125 CMD_SET_FORBIDDEN_PLMNS,
5126 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5127 subId);
5128 return (int) response;
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
5132 }
5133
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005135 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5137 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5142 if (response.payload == null) {
5143 return "";
5144 }
Evan Charltonc66da362014-05-16 14:06:40 -07005145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 // Append the returned status code to the end of the response payload.
5147 String s = Integer.toHexString(
5148 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5149 s = IccUtils.bytesToHexString(response.payload) + s;
5150 return s;
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Evan Charltonc66da362014-05-16 14:06:40 -07005154 }
5155
Jake Hambye994d462014-02-03 13:10:13 -08005156 /**
5157 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5158 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5159 *
5160 * @param itemID the ID of the item to read
5161 * @return the NV item as a String, or null on error.
5162 */
5163 @Override
5164 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005165 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005172 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5174 return value;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Jake Hambye994d462014-02-03 13:10:13 -08005178 }
5179
5180 /**
5181 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5182 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5183 *
5184 * @param itemID the ID of the item to read
5185 * @param itemValue the value to write, as a String
5186 * @return true on success; false on any failure
5187 */
5188 @Override
5189 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5197 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005198 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5200 return success;
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Jake Hambye994d462014-02-03 13:10:13 -08005204 }
5205
5206 /**
5207 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5208 * Used for device configuration by some CDMA operators.
5209 *
5210 * @param preferredRoamingList byte array containing the new PRL
5211 * @return true on success; false on any failure
5212 */
5213 @Override
5214 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5221 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5222 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5223 return success;
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
Jake Hambye994d462014-02-03 13:10:13 -08005227 }
5228
5229 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005230 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005231 * Used for device configuration by some CDMA operators.
5232 *
chen xu6dac5ab2018-10-26 17:39:23 -07005233 * @param slotIndex - device slot.
5234 *
Jake Hambye994d462014-02-03 13:10:13 -08005235 * @return true on success; false on any failure
5236 */
5237 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005238 public boolean resetModemConfig(int slotIndex) {
5239 Phone phone = PhoneFactory.getPhone(slotIndex);
5240 if (phone != null) {
5241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5242 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243
chen xu6dac5ab2018-10-26 17:39:23 -07005244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5247 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5248 return success;
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 }
chen xu6dac5ab2018-10-26 17:39:23 -07005253 return false;
5254 }
5255
5256 /**
5257 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5258 *
5259 * @param slotIndex - device slot.
5260 *
5261 * @return true on success; false on any failure
5262 */
5263 @Override
5264 public boolean rebootModem(int slotIndex) {
5265 Phone phone = PhoneFactory.getPhone(slotIndex);
5266 if (phone != null) {
5267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5268 mApp, phone.getSubId(), "rebootModem");
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5273 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5274 return success;
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
5278 }
5279 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005280 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005281
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005282 public String[] getPcscfAddress(String apnType, String callingPackage,
5283 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005284 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5286 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005287 return new String[0];
5288 }
5289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005292 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Wink Saville36469e72014-06-11 15:17:00 -07005296 }
5297
Brad Ebinger51f743a2017-01-23 13:50:20 -08005298 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005299 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5300 * {@link #disableIms(int)}.
5301 * @param slotIndex device slot.
5302 */
5303 public void resetIms(int slotIndex) {
5304 enforceModifyPermission();
5305
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 if (mImsResolver == null) {
5309 // may happen if the does not support IMS.
5310 return;
5311 }
5312 mImsResolver.disableIms(slotIndex);
5313 mImsResolver.enableIms(slotIndex);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005320 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5321 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005322 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005323 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005324 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005328 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005329 // may happen if the device does not support IMS.
5330 return;
5331 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005332 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005336 }
5337
5338 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005339 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5340 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005341 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005342 public void disableIms(int slotId) {
5343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344
5345 final long identity = Binder.clearCallingIdentity();
5346 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005347 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005348 // may happen if the device does not support IMS.
5349 return;
5350 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005351 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005355 }
5356
5357 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005358 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5359 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005360 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005361 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005362 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005363 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005367 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005368 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5369 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005370 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005371 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005375 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005376 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005377 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5378 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005379 @Override
5380 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005381 enforceModifyPermission();
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005386 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
5390 }
5391
5392 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005393 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005394 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005395 */
5396 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5397 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005401 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005402 // may happen if the device does not support IMS.
5403 return null;
5404 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005405 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005409 }
5410
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005411 /**
5412 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005413 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005414 */
5415 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417
5418 final long identity = Binder.clearCallingIdentity();
5419 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005420 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005421 // may happen if the device does not support IMS.
5422 return null;
5423 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005424 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 }
5429
Brad Ebinger884c07b2018-02-15 16:17:40 -08005430 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005431 * Sets the ImsService Package Name that Telephony will bind to.
5432 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005433 * @param slotIndex the slot ID that the ImsService should bind for.
5434 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005435 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005436 * @param featureTypes An integer array of feature types associated with a packageName.
5437 * @param packageName The name of the package that the current configuration will be replaced
5438 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005439 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005440 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005441 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5442 int[] featureTypes, String packageName) {
5443 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5446 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005447 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005451 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005452 // may happen if the device does not support IMS.
5453 return false;
5454 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005455 Map<Integer, String> featureConfig = new HashMap<>();
5456 for (int featureType : featureTypes) {
5457 featureConfig.put(featureType, packageName);
5458 }
5459 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5460 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005464 }
5465
5466 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005467 * Clears any carrier ImsService overrides for the slot index specified that were previously
5468 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5469 *
5470 * This should only be used for testing.
5471 *
5472 * @param slotIndex the slot ID that the ImsService should bind for.
5473 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5474 */
5475 @Override
5476 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5477 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5479 "clearCarrierImsServiceOverride");
5480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5481 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5482 "clearCarrierImsServiceOverride");
5483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 if (mImsResolver == null) {
5487 // may happen if the device does not support IMS.
5488 return false;
5489 }
5490 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
5494 }
5495
5496 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005497 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005498 *
5499 * @param slotId The slot that the ImsService is associated with.
5500 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5501 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005502 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005503 * @return the package name of the ImsService configuration.
5504 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005505 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5506 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005507 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005508 TelephonyPermissions
5509 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5510 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5511 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005515 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005516 // may happen if the device does not support IMS.
5517 return "";
5518 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005519 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005520 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5521 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005525 }
5526
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005527 /**
5528 * Get the MmTelFeature state associated with the requested subscription id.
5529 * @param subId The subscription that the MmTelFeature is associated with.
5530 * @param callback A callback with an integer containing the
5531 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5532 */
5533 @Override
5534 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5535 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5536 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5537 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5538 "IMS not available on device.");
5539 }
5540 final long token = Binder.clearCallingIdentity();
5541 try {
5542 int slotId = getSlotIndex(subId);
5543 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5544 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5545 + subId + "'");
5546 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5547 }
5548 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5549 try {
5550 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5551 } catch (RemoteException e) {
5552 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5553 + "Ignore");
5554 }
5555 });
5556 } finally {
5557 Binder.restoreCallingIdentity(token);
5558 }
5559 }
5560
Wink Saville36469e72014-06-11 15:17:00 -07005561 public void setImsRegistrationState(boolean registered) {
5562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563
5564 final long identity = Binder.clearCallingIdentity();
5565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005566 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Wink Saville36469e72014-06-11 15:17:00 -07005570 }
5571
5572 /**
Stuart Scott54788802015-03-30 13:18:01 -07005573 * Set the network selection mode to automatic.
5574 *
5575 */
5576 @Override
5577 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
shilufc958392020-01-20 11:36:01 -08005583 if (!isActiveSubscription(subId)) {
5584 return;
5585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5587 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Stuart Scott54788802015-03-30 13:18:01 -07005591 }
5592
Jack Yud10cdd42020-09-28 20:28:01 -07005593 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005594 * Ask the radio to connect to the input network and change selection mode to manual.
5595 *
5596 * @param subId the id of the subscription.
5597 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5598 * the operator to attach to.
5599 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5600 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5601 * normal network selection next time.
5602 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005603 */
5604 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005605 public boolean setNetworkSelectionModeManual(
5606 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005609
5610 if (!isActiveSubscription(subId)) {
5611 return false;
5612 }
5613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005616 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005618 if (DBG) {
5619 log("setNetworkSelectionModeManual: subId: " + subId
5620 + " operator: " + operatorInfo);
5621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005626 }
shilu84f6e8b2019-12-19 13:58:01 -08005627 /**
5628 * Get the manual network selection
5629 *
5630 * @param subId the id of the subscription.
5631 *
5632 * @return the previously saved user selected PLMN
5633 */
5634 @Override
5635 public String getManualNetworkSelectionPlmn(int subId) {
5636 TelephonyPermissions
5637 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5638 mApp, subId, "getManualNetworkSelectionPlmn");
5639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005643 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005644 }
5645
5646 final Phone phone = getPhone(subId);
5647 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005648 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005649 }
5650 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5651 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5652 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
5656 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005657
5658 /**
5659 * Scans for available networks.
5660 */
5661 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005662 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5663 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5665 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005666 LocationAccessPolicy.LocationPermissionResult locationResult =
5667 LocationAccessPolicy.checkLocationPermission(mApp,
5668 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5669 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005670 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005671 .setCallingPid(Binder.getCallingPid())
5672 .setCallingUid(Binder.getCallingUid())
5673 .setMethod("getCellNetworkScanResults")
5674 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005675 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5676 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005677 .build());
5678 switch (locationResult) {
5679 case DENIED_HARD:
5680 throw new SecurityException("Not allowed to access scan results -- location");
5681 case DENIED_SOFT:
5682 return null;
5683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684
Pengquan Menga1bb6272018-09-06 09:59:22 -07005685 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 try {
5687 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005688 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005693 }
5694
5695 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005696 * Get the call forwarding info, given the call forwarding reason.
5697 */
5698 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005699 public void getCallForwarding(int subId, int callForwardingReason,
5700 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005701 enforceReadPrivilegedPermission("getCallForwarding");
5702 long identity = Binder.clearCallingIdentity();
5703 try {
5704 if (DBG) {
5705 log("getCallForwarding: subId " + subId
5706 + " callForwardingReason" + callForwardingReason);
5707 }
Hall Liu27d24262020-09-18 19:04:59 -07005708
5709 Phone phone = getPhone(subId);
5710 if (phone == null) {
5711 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005712 callback.onError(
5713 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005714 } catch (RemoteException e) {
5715 // ignore
5716 }
5717 return;
5718 }
5719
5720 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5721 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5722 @Override
5723 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5724 try {
5725 callback.onCallForwardingInfoAvailable(info);
5726 } catch (RemoteException e) {
5727 // ignore
5728 }
5729 }
5730
5731 @Override
5732 public void onError(int error) {
5733 try {
5734 callback.onError(error);
5735 } catch (RemoteException e) {
5736 // ignore
5737 }
5738 }
5739 });
5740 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
5744 }
5745
5746 /**
5747 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5748 * reason, the number to forward, and the timeout before the forwarding is attempted.
5749 */
5750 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005751 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5752 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005753 enforceModifyPermission();
5754 long identity = Binder.clearCallingIdentity();
5755 try {
5756 if (DBG) {
5757 log("setCallForwarding: subId " + subId
5758 + " callForwardingInfo" + callForwardingInfo);
5759 }
Hall Liu27d24262020-09-18 19:04:59 -07005760
5761 Phone phone = getPhone(subId);
5762 if (phone == null) {
5763 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005764 callback.accept(
5765 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005766 } catch (RemoteException e) {
5767 // ignore
5768 }
5769 return;
5770 }
5771
5772 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5773 FunctionalUtils.ignoreRemoteException(callback::accept));
5774
5775 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
5781 /**
Hall Liu27d24262020-09-18 19:04:59 -07005782 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005783 */
5784 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005785 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005786 enforceReadPrivilegedPermission("getCallForwarding");
5787 long identity = Binder.clearCallingIdentity();
5788 try {
Hall Liu27d24262020-09-18 19:04:59 -07005789
5790 Phone phone = getPhone(subId);
5791 if (phone == null) {
5792 try {
5793 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5794 } catch (RemoteException e) {
5795 // ignore
5796 }
5797 return;
5798 }
5799
5800 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5801
Shuo Qian4a594052020-01-23 11:59:30 -08005802 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005803 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
5807 }
5808
5809 /**
Hall Liu27d24262020-09-18 19:04:59 -07005810 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005811 */
5812 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005813 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005814 enforceModifyPermission();
5815 long identity = Binder.clearCallingIdentity();
5816 try {
Hall Liu27d24262020-09-18 19:04:59 -07005817 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5818
5819 Phone phone = getPhone(subId);
5820 if (phone == null) {
5821 try {
5822 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5823 } catch (RemoteException e) {
5824 // ignore
5825 }
5826 return;
5827 }
5828
5829 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5830 FunctionalUtils.ignoreRemoteException(callback::accept));
5831
5832 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 /**
yinxub1bed742017-04-17 11:45:04 -07005839 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005840 *
yinxub1bed742017-04-17 11:45:04 -07005841 * @param subId id of the subscription
5842 * @param request contains the radio access networks with bands/channels to scan
5843 * @param messenger callback messenger for scan results or errors
5844 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005845 * @return the id of the requested scan which can be used to stop the scan.
5846 */
5847 @Override
5848 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005849 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5851 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005852 LocationAccessPolicy.LocationPermissionResult locationResult =
5853 LocationAccessPolicy.checkLocationPermission(mApp,
5854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5855 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005856 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005857 .setCallingPid(Binder.getCallingPid())
5858 .setCallingUid(Binder.getCallingUid())
5859 .setMethod("requestNetworkScan")
5860 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005861 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5862 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005863 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005864 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005865 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5866 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005867 if (e != null) {
5868 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5869 throw e;
5870 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005871 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005872 return TelephonyScanManager.INVALID_SCAN_ID;
5873 }
5874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 }
Hall Liu912dfd32019-04-25 14:02:26 -07005876 int callingUid = Binder.getCallingUid();
5877 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 return mNetworkScanRequestTracker.startNetworkScan(
5881 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005882 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
yinxu504e1392017-04-12 16:03:22 -07005886 }
5887
Hall Liub2ac8ef2019-02-28 15:56:23 -08005888 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005889 NetworkScanRequest request, int subId, String callingPackage) {
5890 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005891 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5892 boolean hasNetworkScanPermission =
5893 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5894 == PERMISSION_GRANTED;
5895
5896 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5897 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5898 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005899 }
5900
5901 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5902 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005903 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5904 return new SecurityException("Specific channels must not be"
5905 + " scanned without location access.");
5906 }
5907 }
5908 }
5909
Hall Liub2ac8ef2019-02-28 15:56:23 -08005910 return null;
5911 }
5912
yinxu504e1392017-04-12 16:03:22 -07005913 /**
5914 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005915 *
5916 * @param subId id of the subscription
5917 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005918 */
5919 @Override
5920 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923
Hall Liu912dfd32019-04-25 14:02:26 -07005924 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 final long identity = Binder.clearCallingIdentity();
5926 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005927 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
yinxu504e1392017-04-12 16:03:22 -07005931 }
5932
5933 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005934 * Get the calculated preferred network type.
5935 * Used for debugging incorrect network type.
5936 *
5937 * @return the preferred network type, defined in RILConstants.java.
5938 */
5939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005940 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941 final Phone defaultPhone = getDefaultPhone();
5942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005943 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005944 return RILConstants.PREFERRED_NETWORK_MODE;
5945 }
5946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005950 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 } finally {
5952 Binder.restoreCallingIdentity(identity);
5953 }
Junda Liu84d15a22014-07-02 11:21:04 -07005954 }
5955
5956 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005957 * Get the preferred network type.
5958 * Used for device configuration by some CDMA operators.
5959 *
5960 * @return the preferred network type, defined in RILConstants.java.
5961 */
5962 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005963 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005964 TelephonyPermissions
5965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5966 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 if (DBG) log("getPreferredNetworkType");
5971 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5972 int networkType = (result != null ? result[0] : -1);
5973 if (DBG) log("getPreferredNetworkType: " + networkType);
5974 return networkType;
5975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005978 }
5979
5980 /**
5981 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005982 *
5983 * @param networkType the preferred network type, defined in RILConstants.java.
5984 * @return true on success; false on any failure.
5985 */
5986 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005987 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5989 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
calvinpan8ed33732020-03-12 14:17:55 +08005993 Boolean success = (Boolean) sendRequest(
5994 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005995
5996 if (success) {
5997 Settings.Global.putInt(mApp.getContentResolver(),
5998 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5999 }
calvinpan8ed33732020-03-12 14:17:55 +08006000 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6001 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 } finally {
6003 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006004 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006005 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006006
6007 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08006008 * Get the allowed network types that store in the telephony provider.
6009 *
6010 * @param subId the id of the subscription.
6011 * @return allowedNetworkTypes the allowed network types.
6012 */
6013 @Override
6014 public long getAllowedNetworkTypes(int subId) {
6015 TelephonyPermissions
6016 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6017 mApp, subId, "getAllowedNetworkTypes");
6018
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 return SubscriptionManager.getLongSubscriptionProperty(
6022 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6023 } finally {
6024 Binder.restoreCallingIdentity(identity);
6025 }
6026 }
6027
6028 /**
6029 * Set the allowed network types.
6030 *
6031 * @param subId the id of the subscription.
6032 * @param allowedNetworkTypes the allowed network types.
6033 * @return true on success; false on any failure.
6034 */
6035 @Override
6036 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6038 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08006039
calvinpan8ed33732020-03-12 14:17:55 +08006040 SubscriptionManager.setSubscriptionProperty(subId,
6041 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6042 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08006043
calvinpan8ed33732020-03-12 14:17:55 +08006044 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6045 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6046 RILConstants.PREFERRED_NETWORK_MODE);
6047 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006048 }
6049
6050 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006051 * Get the allowed network types for certain reason.
6052 *
6053 * @param subId the id of the subscription.
6054 * @param reason the reason the allowed network type change is taking place
6055 * @return the allowed network types.
6056 */
6057 @Override
6058 public long getAllowedNetworkTypesForReason(int subId,
6059 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6060 TelephonyPermissions
6061 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6062 mApp, subId, "getAllowedNetworkTypesForReason");
6063 final long identity = Binder.clearCallingIdentity();
6064 try {
6065 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
6069 }
6070
6071 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006072 * Enable/Disable E-UTRA-NR Dual Connectivity
6073 * @param subId subscription id of the sim card
6074 * @param nrDualConnectivityState expected NR dual connectivity state
6075 * This can be passed following states
6076 * <ol>
6077 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6078 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6079 * <li>Disable NR dual connectivity and force secondary cell to be released
6080 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6081 * </ol>
6082 * @return operation result.
6083 */
6084 @Override
6085 public int setNrDualConnectivityState(int subId,
6086 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6088 mApp, subId, "enableNRDualConnectivity");
6089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6093 nrDualConnectivityState, subId,
6094 workSource);
6095 if (DBG) log("enableNRDualConnectivity result: " + result);
6096 return result;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
6100 }
6101
6102 /**
6103 * Is E-UTRA-NR Dual Connectivity enabled
6104 * @return true if dual connectivity is enabled else false
6105 */
6106 @Override
6107 public boolean isNrDualConnectivityEnabled(int subId) {
6108 TelephonyPermissions
6109 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6110 mApp, subId, "isNRDualConnectivityEnabled");
6111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6115 null, subId, workSource);
6116 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6117 return isEnabled;
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
6121 }
6122
6123 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006124 * get carrier bandwidth per primary and secondary carrier
6125 * @param subId subscription id of the sim card
6126 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6127 */
6128 @Override
6129 public CarrierBandwidth getCarrierBandwidth(int subId) {
6130 TelephonyPermissions
6131 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6132 mApp, subId, "isNRDualConnectivityEnabled");
6133 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 CarrierBandwidth carrierBandwidth =
6137 getPhoneFromSubId(subId).getCarrierBandwidth();
6138 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6139 return carrierBandwidth;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
6143 }
6144
6145 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006146 * Get the effective allowed network types on the device.
6147 * This API will return an intersection of allowed network types for all reasons,
6148 * including the configuration done through setAllowedNetworkTypes
6149 *
6150 * @param subId the id of the subscription.
6151 * @return the allowed network types
6152 */
6153 @Override
6154 public long getEffectiveAllowedNetworkTypes(int subId) {
6155 TelephonyPermissions
6156 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6157 mApp, subId, "getEffectiveAllowedNetworkTypes");
6158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
6164 }
6165
6166 /**
6167 * Set the allowed network types of the device and
6168 * provide the reason triggering the allowed network change.
6169 *
6170 * @param subId the id of the subscription.
6171 * @param reason the reason the allowed network type change is taking place
6172 * @param allowedNetworkTypes the allowed network types.
6173 * @return true on success; false on any failure.
6174 */
6175 @Override
6176 public boolean setAllowedNetworkTypesForReason(int subId,
6177 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6179 mApp, subId, "setAllowedNetworkTypesForReason");
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6183 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6184 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6185 RILConstants.PREFERRED_NETWORK_MODE);
6186 return setPreferredNetworkType(subId, preferredNetworkMode);
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Miaoa84611c2019-03-15 09:21:10 +08006193 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006194 *
Miaoa84611c2019-03-15 09:21:10 +08006195 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006196 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006197 * @hide
6198 */
6199 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006200 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006203 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 try {
Miaoa84611c2019-03-15 09:21:10 +08006205 if (phone != null) {
6206 return phone.hasMatchedTetherApnSetting();
6207 } else {
6208 return false;
6209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006212 }
Junda Liu475951f2014-11-07 16:45:03 -08006213 }
6214
6215 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006216 * Enable or disable always reporting signal strength changes from radio.
6217 *
6218 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6219 */
6220 @Override
6221 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6222 enforceModifyPermission();
6223 enforceSystemCaller();
6224
6225 final long identity = Binder.clearCallingIdentity();
6226 final Phone phone = getPhone(subId);
6227 try {
6228 if (phone != null) {
6229 if (DBG) {
6230 log("setAlwaysReportSignalStrength: subId=" + subId
6231 + " isEnable=" + isEnable);
6232 }
6233 phone.setAlwaysReportSignalStrength(isEnable);
6234 } else {
6235 loge("setAlwaysReportSignalStrength: no phone found for subId="
6236 + subId);
6237 }
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
6241 }
6242
6243 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006244 * Get the user enabled state of Mobile Data.
6245 *
6246 * TODO: remove and use isUserDataEnabled.
6247 * This can't be removed now because some vendor codes
6248 * calls through ITelephony directly while they should
6249 * use TelephonyManager.
6250 *
6251 * @return true on enabled
6252 */
6253 @Override
6254 public boolean getDataEnabled(int subId) {
6255 return isUserDataEnabled(subId);
6256 }
6257
6258 /**
6259 * Get whether mobile data is enabled per user setting.
6260 *
6261 * There are other factors deciding whether mobile data is actually enabled, but they are
6262 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006263 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006264 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006265 *
6266 * @return {@code true} if data is enabled else {@code false}
6267 */
6268 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006269 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006270 try {
6271 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6272 null);
6273 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6275 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277
6278 final long identity = Binder.clearCallingIdentity();
6279 try {
6280 int phoneId = mSubscriptionController.getPhoneId(subId);
6281 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6282 Phone phone = PhoneFactory.getPhone(phoneId);
6283 if (phone != null) {
6284 boolean retVal = phone.isUserDataEnabled();
6285 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6286 return retVal;
6287 } else {
6288 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6289 return false;
6290 }
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006293 }
6294 }
6295
6296 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006297 * Checks if the device is capable of mobile data by considering whether whether the
6298 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6299 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006300 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006301 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006302 */
6303 @Override
6304 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006305 try {
6306 try {
6307 mApp.enforceCallingOrSelfPermission(
6308 android.Manifest.permission.ACCESS_NETWORK_STATE,
6309 null);
6310 } catch (Exception e) {
6311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6312 "isDataEnabled");
6313 }
6314 } catch (Exception e) {
6315 enforceReadPrivilegedPermission("isDataEnabled");
6316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 int phoneId = mSubscriptionController.getPhoneId(subId);
6321 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6322 Phone phone = PhoneFactory.getPhone(phoneId);
6323 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006324 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6326 return retVal;
6327 } else {
6328 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6329 return false;
6330 }
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006333 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006334 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006335
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006336 /**
6337 * Check if data is enabled for a specific reason
6338 * @param subId Subscription index
6339 * @param reason the reason the data enable change is taking place
6340 * @return {@code true} if the overall data is enabled; {@code false} if not.
6341 */
6342 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006343 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006344 @TelephonyManager.DataEnabledReason int reason) {
6345 try {
6346 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6347 null);
6348 } catch (Exception e) {
6349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006350 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006351 }
6352
6353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 int phoneId = mSubscriptionController.getPhoneId(subId);
6357 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006358 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006359 + " reason=" + reason);
6360 }
6361 Phone phone = PhoneFactory.getPhone(phoneId);
6362 if (phone != null) {
6363 boolean retVal;
6364 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6365 retVal = phone.isUserDataEnabled();
6366 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006367 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006368 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006369 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006370 return retVal;
6371 } else {
6372 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006373 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006374 + subId + " retVal=false");
6375 }
6376 return false;
6377 }
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
6382
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006383 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006384 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006385 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6386 // Skip the check if it's one of these special uids
6387 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6388 }
6389
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006390 //load access rules from carrier configs, and check those as well: b/139133814
6391 SubscriptionController subController = SubscriptionController.getInstance();
6392 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6393 || subController == null) return privilegeFromSim;
6394
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006395 PackageManager pkgMgr = phone.getContext().getPackageManager();
6396 String[] packages = pkgMgr.getPackagesForUid(uid);
6397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006400 int subId = phone.getSubId();
6401 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6402 // A test override is in place for the privileges for this subId, so don't try to
6403 // read the subscription privileges.
6404 return privilegeFromSim;
6405 }
6406 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006407 SubscriptionManager subManager = (SubscriptionManager)
6408 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6409 for (String pkg : packages) {
6410 if (subManager.canManageSubscription(subInfo, pkg)) {
6411 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6412 }
6413 }
6414 return privilegeFromSim;
6415 } finally {
6416 Binder.restoreCallingIdentity(identity);
6417 }
6418 }
6419
6420 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6421 String pkgName) {
6422 //load access rules from carrier configs, and check those as well: b/139133814
6423 SubscriptionController subController = SubscriptionController.getInstance();
6424 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6425 || subController == null) return privilegeFromSim;
6426
6427 final long identity = Binder.clearCallingIdentity();
6428 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006429 int subId = phone.getSubId();
6430 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6431 // A test override is in place for the privileges for this subId, so don't try to
6432 // read the subscription privileges.
6433 return privilegeFromSim;
6434 }
6435 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006436 SubscriptionManager subManager = (SubscriptionManager)
6437 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6438 return subManager.canManageSubscription(subInfo, pkgName)
6439 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006445 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006446 public int getCarrierPrivilegeStatus(int subId) {
6447 final Phone phone = getPhone(subId);
6448 if (phone == null) {
6449 loge("getCarrierPrivilegeStatus: Invalid subId");
6450 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6451 }
6452 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006453 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006454 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006455 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6456 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006457
6458 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6459 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006460 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006461 }
Junda Liu29340342014-07-10 15:23:27 -07006462
6463 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006464 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006465 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006466 final Phone phone = getPhone(subId);
6467 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006468 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6470 }
6471 UiccProfile profile =
6472 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6473 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006474 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006475 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6476 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006477 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006478 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006479 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006480 }
6481
6482 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006483 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6484 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006485 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006486 }
6487
6488 int phoneId = SubscriptionManager.getPhoneId(subId);
6489 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006490 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006491 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006492 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6493 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006494 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6495 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6496 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006497 }
6498
6499 @Override
6500 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006501 if (TextUtils.isEmpty(pkgName))
6502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006503 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6504 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6505 UiccCard card = UiccController.getInstance().getUiccCard(i);
6506 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006507 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006508 continue;
6509 }
6510
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006511 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6512 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6513 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006514 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6515 break;
6516 }
6517 }
6518
6519 return result;
Junda Liu29340342014-07-10 15:23:27 -07006520 }
Derek Tan89e89d42014-07-08 17:00:10 -07006521
6522 @Override
Junda Liue64de782015-04-16 17:19:16 -07006523 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6524 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6525 loge("phoneId " + phoneId + " is not valid.");
6526 return null;
6527 }
6528 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006529 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006530 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006531 return null ;
6532 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006533 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006534 }
6535
Amith Yamasani6e118872016-02-19 12:53:51 -08006536 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006537 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006538 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006539 List<String> privilegedPackages = new ArrayList<>();
6540 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006541 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6542 // has UICC in that slot.
6543 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006544 if (card.hasCarrierPrivilegeRules()) {
6545 if (packages == null) {
6546 // Only check packages in user 0 for now
6547 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006548 PackageManager.MATCH_DISABLED_COMPONENTS
6549 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006550 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006551 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006552 }
6553 for (int p = packages.size() - 1; p >= 0; p--) {
6554 PackageInfo pkgInfo = packages.get(p);
6555 if (pkgInfo != null && pkgInfo.packageName != null
6556 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006557 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006558 privilegedPackages.add(pkgInfo.packageName);
6559 }
6560 }
6561 }
6562 }
6563 return privilegedPackages;
6564 }
6565
chen xuf7e9fe82019-05-09 19:31:02 -07006566 @Override
6567 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006568 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6569
6570 final long identity = Binder.clearCallingIdentity();
6571
chen xuf7e9fe82019-05-09 19:31:02 -07006572 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006573 try {
6574 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6575 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6576 }
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006579 }
6580 return privilegedPackages;
6581 }
6582
Wink Savilleb564aae2014-10-23 10:18:09 -07006583 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006584 final Phone phone = getPhone(subId);
6585 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006586 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006587 return null;
6588 }
6589 String iccId = card.getIccId();
6590 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006591 return null;
6592 }
6593 return iccId;
6594 }
6595
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006596 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006597 public void setCallComposerStatus(int subId, int status) {
6598 enforceModifyPermission();
6599
6600 final long identity = Binder.clearCallingIdentity();
6601 try {
6602 Phone phone = getPhone(subId);
6603 if (phone != null) {
6604 Phone defaultPhone = phone.getImsPhone();
6605 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6606 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6607 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006608 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6609 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006610 }
6611 }
Shuo Qian284ae752020-12-22 19:10:14 -08006612 } catch (ImsException e) {
6613 throw new ServiceSpecificException(e.getCode());
6614 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 @Override
6620 public int getCallComposerStatus(int subId) {
6621 enforceReadPrivilegedPermission("getCallComposerStatus");
6622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 Phone phone = getPhone(subId);
6626 if (phone != null) {
6627 Phone defaultPhone = phone.getImsPhone();
6628 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6629 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6630 return imsPhone.getCallComposerStatus();
6631 }
6632 }
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
6636 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6637 }
6638
6639 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006640 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6641 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006642 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006643 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 final String iccId = getIccId(subId);
6648 final Phone phone = getPhone(subId);
6649 if (phone == null) {
6650 return false;
6651 }
6652 final String subscriberId = phone.getSubscriberId();
6653
6654 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006655 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 + subscriberId + " to " + number);
6657 }
6658
6659 if (TextUtils.isEmpty(iccId)) {
6660 return false;
6661 }
6662
6663 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6664
6665 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6666 if (alphaTag == null) {
6667 editor.remove(alphaTagPrefKey);
6668 } else {
6669 editor.putString(alphaTagPrefKey, alphaTag);
6670 }
6671
6672 // Record both the line number and IMSI for this ICCID, since we need to
6673 // track all merged IMSIs based on line number
6674 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6675 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6676 if (number == null) {
6677 editor.remove(numberPrefKey);
6678 editor.remove(subscriberPrefKey);
6679 } else {
6680 editor.putString(numberPrefKey, number);
6681 editor.putString(subscriberPrefKey, subscriberId);
6682 }
6683
6684 editor.commit();
6685 return true;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006688 }
Derek Tan7226c842014-07-02 17:42:23 -07006689 }
6690
6691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006692 public String getLine1NumberForDisplay(int subId, String callingPackage,
6693 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006694 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006697 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006698 return null;
6699 }
Derek Tan97ebb422014-09-05 16:55:38 -07006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 String iccId = getIccId(subId);
6704 if (iccId != null) {
6705 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6706 if (DBG_MERGE) {
6707 log("getLine1NumberForDisplay returning "
6708 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6709 }
6710 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6713 return null;
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006716 }
Derek Tan7226c842014-07-02 17:42:23 -07006717 }
6718
6719 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006720 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6721 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006723 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006724 return null;
6725 }
Derek Tan97ebb422014-09-05 16:55:38 -07006726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 String iccId = getIccId(subId);
6730 if (iccId != null) {
6731 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6732 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6733 }
6734 return null;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006737 }
Derek Tan7226c842014-07-02 17:42:23 -07006738 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006739
6740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006741 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6742 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006743 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6744 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006746 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006747 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006748 return null;
6749 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006750
Jordan Liub49b04b2019-05-06 14:45:15 -07006751 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6752 // the process, where TelephonyManager was instantiated.
6753 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006754 final long identity = Binder.clearCallingIdentity();
6755 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006756 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 final TelephonyManager tele = TelephonyManager.from(context);
6758 final SubscriptionManager sub = SubscriptionManager.from(context);
6759
6760 // Figure out what subscribers are currently active
6761 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
Jordan Liub49b04b2019-05-06 14:45:15 -07006763 // Only consider subs which match the current subId
6764 // This logic can be simplified. See b/131189269 for progress.
6765 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006766 activeSubscriberIds.add(tele.getSubscriberId(subId));
6767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768
6769 // First pass, find a number override for an active subscriber
6770 String mergeNumber = null;
6771 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6772 for (String key : prefs.keySet()) {
6773 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6774 final String subscriberId = (String) prefs.get(key);
6775 if (activeSubscriberIds.contains(subscriberId)) {
6776 final String iccId = key.substring(
6777 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6778 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6779 mergeNumber = (String) prefs.get(numberKey);
6780 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006781 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 + " for active subscriber " + subscriberId);
6783 }
6784 if (!TextUtils.isEmpty(mergeNumber)) {
6785 break;
6786 }
6787 }
6788 }
6789 }
6790
6791 // Shortcut when no active merged subscribers
6792 if (TextUtils.isEmpty(mergeNumber)) {
6793 return null;
6794 }
6795
6796 // Second pass, find all subscribers under that line override
6797 final ArraySet<String> result = new ArraySet<>();
6798 for (String key : prefs.keySet()) {
6799 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6800 final String number = (String) prefs.get(key);
6801 if (mergeNumber.equals(number)) {
6802 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6803 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6804 final String subscriberId = (String) prefs.get(subscriberKey);
6805 if (!TextUtils.isEmpty(subscriberId)) {
6806 result.add(subscriberId);
6807 }
6808 }
6809 }
6810 }
6811
6812 final String[] resultArray = result.toArray(new String[result.size()]);
6813 Arrays.sort(resultArray);
6814 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006815 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6817 }
6818 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006821 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006822 }
6823
6824 @Override
zoey chen38003472019-12-13 17:16:31 +08006825 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6826 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006827
6828 final long identity = Binder.clearCallingIdentity();
6829 try {
6830 final TelephonyManager telephonyManager = mApp.getSystemService(
6831 TelephonyManager.class);
6832 String subscriberId = telephonyManager.getSubscriberId(subId);
6833 if (subscriberId == null) {
6834 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006835 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006836 + subId);
6837 }
6838 return null;
6839 }
6840
6841 final SubscriptionInfo info = SubscriptionController.getInstance()
6842 .getSubscriptionInfo(subId);
6843 final ParcelUuid groupUuid = info.getGroupUuid();
6844 // If it doesn't belong to any group, return just subscriberId of itself.
6845 if (groupUuid == null) {
6846 return new String[]{subscriberId};
6847 }
6848
6849 // Get all subscriberIds from the group.
6850 final List<String> mergedSubscriberIds = new ArrayList<>();
6851 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006852 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006853 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006854 for (SubscriptionInfo subInfo : groupInfos) {
6855 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6856 if (subscriberId != null) {
6857 mergedSubscriberIds.add(subscriberId);
6858 }
6859 }
6860
6861 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864
6865 }
6866 }
6867
6868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006869 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006871 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 final Phone phone = getPhone(subId);
6876 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006880 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006881
6882 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006883 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006884 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6885 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006886 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6887 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 final Phone phone = getPhone(subId);
6892 if (phone == null) {
6893 return false;
6894 }
6895 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6896 cdmaNonRoamingList);
6897 } finally {
6898 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006899 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006900 }
6901
6902 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006903 @Deprecated
6904 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6905 enforceModifyPermission();
6906
6907 int returnValue = 0;
6908 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006909 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006910 if(result.exception == null) {
6911 if (result.result != null) {
6912 byte[] responseData = (byte[])(result.result);
6913 if(responseData.length > oemResp.length) {
6914 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6915 responseData.length + "bytes. Buffer Size is " +
6916 oemResp.length + "bytes.");
6917 }
6918 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6919 returnValue = responseData.length;
6920 }
6921 } else {
6922 CommandException ex = (CommandException) result.exception;
6923 returnValue = ex.getCommandError().ordinal();
6924 if(returnValue > 0) returnValue *= -1;
6925 }
6926 } catch (RuntimeException e) {
6927 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6928 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6929 if(returnValue > 0) returnValue *= -1;
6930 }
6931
6932 return returnValue;
6933 }
6934
6935 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006936 public void setRadioCapability(RadioAccessFamily[] rafs) {
6937 try {
6938 ProxyController.getInstance().setRadioCapability(rafs);
6939 } catch (RuntimeException e) {
6940 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6941 }
6942 }
6943
6944 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006945 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006946 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006947 try {
6948 TelephonyPermissions
6949 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6950 mApp, phone.getSubId(), "getRadioAccessFamily");
6951 } catch (SecurityException e) {
6952 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6953 throw e;
6954 }
chen xub97461a2018-10-26 14:17:57 -07006955 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006956 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006957 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 final long identity = Binder.clearCallingIdentity();
6960 try {
chen xub97461a2018-10-26 14:17:57 -07006961 TelephonyPermissions
6962 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6963 mApp, phone.getSubId(), "getRadioAccessFamily");
6964 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
chen xub97461a2018-10-26 14:17:57 -07006968 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006969 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006970
6971 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006972 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
6973 ParcelFileDescriptor fd, ResultReceiver callback) {
6974 try {
6975 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6976 Binder.getCallingUid())) {
6977 throw new SecurityException("Package uid and package name do not match: "
6978 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6979 }
6980 } catch (PackageManager.NameNotFoundException e) {
6981 throw new SecurityException("Package name invalid:" + callingPackage);
6982 }
6983 RoleManager rm = mApp.getSystemService(RoleManager.class);
6984 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6985 if (!dialerRoleHolders.contains(callingPackage)) {
6986 throw new SecurityException("App must be the dialer role holder to"
6987 + " upload a call composer pic");
6988 }
6989
6990 Executors.newSingleThreadExecutor().execute(() -> {
6991 ByteArrayOutputStream output = new ByteArrayOutputStream(
6992 (int) TelephonyManager.getMaximumCallComposerPictureSize());
6993 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
6994 boolean readUntilEnd = false;
6995 int totalBytesRead = 0;
6996 byte[] buffer = new byte[16 * 1024];
6997 while (true) {
6998 int numRead;
6999 try {
7000 numRead = input.read(buffer);
7001 } catch (IOException e) {
7002 try {
7003 fd.checkError();
7004 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7005 null);
7006 } catch (IOException e1) {
7007 // This means that the other side closed explicitly with an error. If this
7008 // happens, log and ignore.
7009 loge("Remote end of call composer picture pipe closed: " + e1);
7010 }
7011 break;
7012 }
7013 if (numRead == -1) {
7014 readUntilEnd = true;
7015 break;
7016 }
7017 totalBytesRead += numRead;
7018 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7019 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7020 try {
7021 input.close();
7022 } catch (IOException e) {
7023 // ignore
7024 }
7025 break;
7026 }
7027 output.write(buffer, 0, numRead);
7028 }
7029 // Generally, the remote end will close the file descriptors. The only case where we
7030 // close is above, where the picture size is too big.
7031
7032 try {
7033 fd.checkError();
7034 } catch (IOException e) {
7035 loge("Remote end for call composer closed with an error: " + e);
7036 return;
7037 }
7038
7039 // TODO: pass along the bytes read to the carrier somehow
7040
7041 ParcelUuid result = new ParcelUuid(UUID.randomUUID());
7042 // TODO: cache this uuid that's been associated with the picture
7043 Bundle outputResult = new Bundle();
7044 outputResult.putParcelable(TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, result);
7045 callback.send(-1, outputResult);
7046 });
7047 }
7048
7049 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007050 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007051 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 ImsManager.getInstance(defaultPhone.getContext(),
7057 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007061 }
7062
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7067 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007068 return false;
7069 }
Svet Ganovb320e182015-04-16 12:30:10 -07007070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 // Check the user preference and the system-level IMS setting. Even if the user has
7074 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7075 // In the long run, we may instead need to check if there exists a connection service
7076 // which can support video calling.
7077 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 return imsManager.isVtEnabledByPlatform()
7080 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7081 && imsManager.isVtEnabledByUser();
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007085 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007086
Andrew Leea1239f22015-03-02 17:44:07 -08007087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007088 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7089 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 mApp, subId, callingPackage, callingFeatureId,
7092 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 return false;
7094 }
7095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 CarrierConfigManager configManager =
7099 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007100 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Andrew Leea1239f22015-03-02 17:44:07 -08007105 }
7106
7107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007110 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 return false;
7112 }
7113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 CarrierConfigManager configManager =
7117 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
Andrew Leea1239f22015-03-02 17:44:07 -08007123 }
7124
Andrew Lee9431b832015-03-09 18:46:45 -07007125 @Override
7126 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007127 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007128 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007129 }
7130
7131 @Override
7132 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Andrew Lee9431b832015-03-09 18:46:45 -07007139 }
7140
Hall Liuf6668912018-10-31 17:05:23 -07007141 /**
7142 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7143 * support for the feature and device firmware support.
7144 *
7145 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7146 */
7147 @Override
7148 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007150 final Phone phone = getPhone(subscriptionId);
7151 if (phone == null) {
7152 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7153 return false;
7154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7158 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007159 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 return isCarrierSupported && isDeviceSupported;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
Hall Liu98187582018-01-22 19:15:32 -08007164 }
7165
Hall Liuf6668912018-10-31 17:05:23 -07007166 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007167 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7168 * RTT setting, will return true if the device and carrier both support RTT.
7169 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007170 */
7171 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 final long identity = Binder.clearCallingIdentity();
7173 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007174 boolean isRttSupported = isRttSupported(subscriptionId);
7175 boolean isUserRttSettingOn = Settings.Secure.getInt(
7176 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7177 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7178 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7179 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007183 }
7184
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 @Deprecated
7186 @Override
7187 public String getDeviceId(String callingPackage) {
7188 return getDeviceIdWithFeature(callingPackage, null);
7189 }
7190
Sanket Padawe7310cc72015-01-14 09:53:20 -08007191 /**
7192 * Returns the unique device ID of phone, for example, the IMEI for
7193 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7194 *
7195 * <p>Requires Permission:
7196 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7197 */
7198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007199 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007200 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007201 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007202 return null;
7203 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007204 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007205 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007206 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007207 return null;
7208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 return phone.getDeviceId();
7213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007216 }
7217
Ping Sunc67b7c22016-03-02 19:16:45 +08007218 /**
7219 * {@hide}
7220 * Returns the IMS Registration Status on a particular subid
7221 *
7222 * @param subId
7223 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007224 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007225 Phone phone = getPhone(subId);
7226 if (phone != null) {
7227 return phone.isImsRegistered();
7228 } else {
7229 return false;
7230 }
7231 }
7232
Santos Cordon7a1885b2015-02-03 11:15:19 -08007233 @Override
7234 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007241 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007242
Tyler Gunnf70ed162019-04-03 15:28:53 -07007243 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007244 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007245 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007247 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007248 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7249 }
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
7258 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007259 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007260 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7261 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 Phone phone = getPhone(subscriptionId);
7265 if (phone == null) {
7266 return null;
7267 }
7268 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007274 /**
7275 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007276 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007277 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 Phone phone = getPhone(subId);
7281 if (phone != null) {
7282 return phone.isWifiCallingEnabled();
7283 } else {
7284 return false;
7285 }
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007288 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007289 }
7290
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007291 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007293 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 Phone phone = getPhone(subId);
7298 if (phone != null) {
7299 return phone.isVideoEnabled();
7300 } else {
7301 return false;
7302 }
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007305 }
7306 }
7307
7308 /**
7309 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7310 * defined in {@link ImsRegistrationImplBase}.
7311 */
7312 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 Phone phone = getPhone(subId);
7316 if (phone != null) {
7317 return phone.getImsRegistrationTech();
7318 } else {
7319 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007323 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007324 }
7325
Stuart Scott8eef64f2015-04-08 15:13:54 -07007326 @Override
7327 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007328 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007329 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7330 return;
7331 }
7332
Svet Ganovcc087f82015-05-12 20:35:54 -07007333 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007334
Svet Ganovcc087f82015-05-12 20:35:54 -07007335 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007336 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7337 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007338 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007339 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007340 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007341 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7343 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007344 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007345 // There has been issues when Sms raw table somehow stores orphan
7346 // fragments. They lead to garbled message when new fragments come
7347 // in and combined with those stale ones. In case this happens again,
7348 // user can reset all network settings which will clean up this table.
7349 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007350 // Clean up IMS settings as well here.
7351 int slotId = getSlotIndex(subId);
7352 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7353 ImsManager.getInstance(mApp, slotId).factoryReset();
7354 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007355
7356 // Erase modem config if erase modem on network setting is enabled.
7357 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7358 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7359 if (configValue != null && Boolean.parseBoolean(configValue)) {
7360 sendEraseModemConfig(getDefaultPhone());
7361 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007362 } finally {
7363 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007364 }
7365 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007366
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007367 private void cleanUpSmsRawTable(Context context) {
7368 ContentResolver resolver = context.getContentResolver();
7369 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7370 resolver.delete(uri, null, null);
7371 }
7372
Narayan Kamath1c496c22015-04-16 14:40:19 +01007373 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007374 public String getSimLocaleForSubscriber(int subId) {
7375 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7376 final Phone phone = getPhone(subId);
7377 if (phone == null) {
7378 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007379 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
chen xu5d3637b2019-01-21 23:31:38 -08007383 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007384 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007385 if (info == null) {
7386 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7387 return null;
7388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 // Try and fetch the locale from the carrier properties or from the SIM language
7390 // preferences (EF-PL and EF-LI)...
7391 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007393 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7394 if (localeFromDefaultSim != null) {
7395 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7396 if (DBG) log("Using locale from subId: " + subId + " locale: "
7397 + localeFromDefaultSim);
7398 return localeFromDefaultSim.toLanguageTag();
7399 } else {
7400 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 }
7402 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 // The SIM language preferences only store a language (e.g. fr = French), not an
7405 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7406 // the SIM and carrier preferences does not include a country we add the country
7407 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007408 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007410 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 return mccLocale.toLanguageTag();
7412 }
7413
7414 if (DBG) log("No locale found - returning null");
7415 return null;
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007419 }
7420
7421 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007422 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007423 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007424 }
7425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 /**
7427 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7428 */
7429 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007430 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007431 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007432 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007433
Chenjie Yu1ba97252018-01-11 18:16:20 -08007434 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007435 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007436
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007437 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007438 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7439 * representing the state of the modem.
7440 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007441 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7442 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007443 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007444 */
7445 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007446 public void requestModemActivityInfo(ResultReceiver result) {
7447 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007448 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007452 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007455 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007456 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007457
Siddharth Rayb8114062018-06-17 15:02:38 -07007458 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7459 // less than total activity duration.
7460 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7461 if (info == null) {
7462 return false;
7463 }
7464 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007465 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7466 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7467
Siddharth Rayb8114062018-06-17 15:02:38 -07007468 return (info.isValid()
7469 && (info.getSleepTimeMillis() <= activityDurationMs)
7470 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007471 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007472 && (totalTxTimeMs <= activityDurationMs));
7473 }
7474
Jack Yu85bd38a2015-11-09 11:34:32 -08007475 /**
7476 * {@hide}
7477 * Returns the service state information on specified subscription.
7478 */
7479 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007480 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7481 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007484 return null;
7485 }
7486
Hall Liuf19c44f2018-11-27 14:38:17 -08007487 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7488 LocationAccessPolicy.checkLocationPermission(mApp,
7489 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7490 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007491 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007492 .setCallingPid(Binder.getCallingPid())
7493 .setCallingUid(Binder.getCallingUid())
7494 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007495 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007496 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007497 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7498 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007499 .build());
7500
7501 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7502 LocationAccessPolicy.checkLocationPermission(mApp,
7503 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7504 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007505 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007506 .setCallingPid(Binder.getCallingPid())
7507 .setCallingUid(Binder.getCallingUid())
7508 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007509 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007510 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007511 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7512 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007513 .build());
7514 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7515 boolean hasFinePermission =
7516 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7517 boolean hasCoarsePermission =
7518 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7519
Jack Yu479f40e2020-10-27 21:29:25 -07007520 final Phone phone = getPhone(subId);
7521 if (phone == null) {
7522 return null;
7523 }
7524
Jordan Liu0f2bc442020-11-18 16:47:37 -08007525 final long identity = Binder.clearCallingIdentity();
7526
Jack Yu479f40e2020-10-27 21:29:25 -07007527 boolean isCallingPackageDataService = phone.getDataServicePackages()
7528 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007530 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7531 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7532 Rlog.d(LOG_TAG,
7533 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7534 return null;
7535 }
7536
Hall Liuf19c44f2018-11-27 14:38:17 -08007537 ServiceState ss = phone.getServiceState();
7538
7539 // Scrub out the location info in ServiceState depending on what level of access
7540 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007541 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007542 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7543 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007547 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007548
7549 /**
7550 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7551 *
7552 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7553 * voicemail ringtone.
7554 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7555 * PhoneAccount.
7556 */
7557 @Override
7558 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7562 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007570 }
7571
7572 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 * Sets the per-account voicemail ringtone.
7574 *
7575 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7576 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7577 *
7578 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7579 * voicemail ringtone.
7580 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7581 * PhoneAccount.
7582 */
7583 @Override
7584 public void setVoicemailRingtoneUri(String callingPackage,
7585 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007588 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7589 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7591 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7592 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7598 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 }
7601 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007604 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007605 }
7606
7607 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007608 * Returns whether vibration is set for voicemail notification in Phone settings.
7609 *
7610 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7611 * voicemail vibration setting.
7612 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7613 */
7614 @Override
7615 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 final long identity = Binder.clearCallingIdentity();
7617 try {
7618 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7619 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007627 }
7628
Youhan Wange64578a2016-05-02 15:32:42 -07007629 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007630 * Sets the per-account voicemail vibration.
7631 *
7632 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7633 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7634 *
7635 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7636 * voicemail vibration setting.
7637 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7638 * specific PhoneAccount.
7639 */
7640 @Override
7641 public void setVoicemailVibrationEnabled(String callingPackage,
7642 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007645 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7646 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7648 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7649 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007650 }
7651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7655 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 }
7658 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007661 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007662 }
7663
7664 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007665 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7666 *
7667 * @throws SecurityException if the caller does not have the required permission
7668 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007669 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007672 }
7673
7674 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007675 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7676 * permission.
7677 *
7678 * @throws SecurityException if the caller does not have the required permission
7679 */
7680 private void enforceSendSmsPermission() {
7681 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7682 }
7683
7684 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007685 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007686 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007687 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007688 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007689 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (componentName == null) {
7695 throw new SecurityException(
7696 "Caller not current active visual voicemail package[null]");
7697 }
7698 String vvmPackage = componentName.getPackageName();
7699 if (!callingPackage.equals(vvmPackage)) {
7700 throw new SecurityException("Caller not current active visual voicemail package["
7701 + vvmPackage + "]");
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007705 }
7706 }
7707
7708 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007709 * Return the application ID for the app type.
7710 *
7711 * @param subId the subscription ID that this request applies to.
7712 * @param appType the uicc app type.
7713 * @return Application ID for specificied app type, or null if no uicc.
7714 */
7715 @Override
7716 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007717 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007718 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719
7720 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007721 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 if (phone == null) {
7723 return null;
7724 }
7725 String aid = null;
7726 try {
7727 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7728 .getApplicationByType(appType).getAid();
7729 } catch (Exception e) {
7730 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7731 }
7732 return aid;
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007735 }
Youhan Wange64578a2016-05-02 15:32:42 -07007736 }
7737
Youhan Wang4001d252016-05-11 10:29:41 -07007738 /**
7739 * Return the Electronic Serial Number.
7740 *
7741 * @param subId the subscription ID that this request applies to.
7742 * @return ESN or null if error.
7743 */
7744 @Override
7745 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007747 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748
7749 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007750 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 if (phone == null) {
7752 return null;
7753 }
7754 String esn = null;
7755 try {
7756 esn = phone.getEsn();
7757 } catch (Exception e) {
7758 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7759 }
7760 return esn;
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007763 }
Youhan Wang4001d252016-05-11 10:29:41 -07007764 }
7765
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007766 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007767 * Return the Preferred Roaming List Version.
7768 *
7769 * @param subId the subscription ID that this request applies to.
7770 * @return PRLVersion or null if error.
7771 */
7772 @Override
7773 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007774 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007775 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776
7777 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007778 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 if (phone == null) {
7780 return null;
7781 }
7782 String cdmaPrlVersion = null;
7783 try {
7784 cdmaPrlVersion = phone.getCdmaPrlVersion();
7785 } catch (Exception e) {
7786 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7787 }
7788 return cdmaPrlVersion;
7789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007791 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007792 }
7793
7794 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007795 * Get snapshot of Telephony histograms
7796 * @return List of Telephony histograms
7797 * @hide
7798 */
7799 @Override
7800 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7802 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 return RIL.getTelephonyRILTimingHistograms();
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007810 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007811
7812 /**
7813 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007814 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7815 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007816 * Require system privileges. In the future we may add this to carrier APIs.
7817 *
Michele Berionne482f8202018-11-27 18:57:59 -08007818 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007819 */
7820 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007821 @TelephonyManager.SetCarrierRestrictionResult
7822 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007823 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007825
Michele Berionne482f8202018-11-27 18:57:59 -08007826 if (carrierRestrictionRules == null) {
7827 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007828 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 final long identity = Binder.clearCallingIdentity();
7831 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007832 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007833 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007837 }
7838
7839 /**
7840 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007841 * Get the allowed carrier list and the excluded carrier list, including the priority between
7842 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007843 * Require system privileges. In the future we may add this to carrier APIs.
7844 *
Michele Berionne482f8202018-11-27 18:57:59 -08007845 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007846 */
7847 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007848 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007849 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851
7852 final long identity = Binder.clearCallingIdentity();
7853 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007854 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7855 if (response instanceof CarrierRestrictionRules) {
7856 return (CarrierRestrictionRules) response;
7857 }
7858 // Response is an Exception of some kind,
7859 // which is signalled to the user as a NULL retval
7860 return null;
7861 } catch (Exception e) {
7862 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7863 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007867 }
7868
fionaxu59545b42016-05-25 15:53:37 -07007869 /**
fionaxu59545b42016-05-25 15:53:37 -07007870 * Action set from carrier signalling broadcast receivers to enable/disable radio
7871 * @param subId the subscription ID that this action applies to.
7872 * @param enabled control enable or disable radio.
7873 * {@hide}
7874 */
7875 @Override
7876 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7877 enforceModifyPermission();
7878 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879
7880 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007881 if (phone == null) {
7882 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7883 return;
7884 }
7885 try {
7886 phone.carrierActionSetRadioEnabled(enabled);
7887 } catch (Exception e) {
7888 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 } finally {
7890 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007891 }
7892 }
7893
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007894 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007895 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7896 * network status based on which carrier apps could apply actions accordingly,
7897 * enable/disable default url handler for example.
7898 *
7899 * @param subId the subscription ID that this action applies to.
7900 * @param report control start/stop reporting the default network status.
7901 * {@hide}
7902 */
7903 @Override
7904 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7905 enforceModifyPermission();
7906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907
7908 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007909 if (phone == null) {
7910 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7911 return;
7912 }
7913 try {
7914 phone.carrierActionReportDefaultNetworkStatus(report);
7915 } catch (Exception e) {
7916 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 } finally {
7918 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007919 }
7920 }
7921
7922 /**
fionaxud9622282017-07-17 17:51:30 -07007923 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7924 * @param subId the subscription ID that this action applies to.
7925 * {@hide}
7926 */
7927 @Override
7928 public void carrierActionResetAll(int subId) {
7929 enforceModifyPermission();
7930 final Phone phone = getPhone(subId);
7931 if (phone == null) {
7932 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7933 return;
7934 }
7935 try {
7936 phone.carrierActionResetAll();
7937 } catch (Exception e) {
7938 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7939 }
7940 }
7941
7942 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007943 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7944 * bug report is being generated.
7945 */
7946 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007947 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007948 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7949 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007950 writer.println("Permission Denial: can't dump Phone from pid="
7951 + Binder.getCallingPid()
7952 + ", uid=" + Binder.getCallingUid()
7953 + "without permission "
7954 + android.Manifest.permission.DUMP);
7955 return;
7956 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007957 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007958 }
Jack Yueb89b242016-06-22 13:27:47 -07007959
Brad Ebingerdac2f002018-04-03 15:17:52 -07007960 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007961 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7962 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7963 @NonNull String[] args) {
7964 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7965 this, in.getFileDescriptor(), out.getFileDescriptor(),
7966 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007967 }
7968
Jack Yueb89b242016-06-22 13:27:47 -07007969 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007970 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007971 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007972 * @param reason the reason the data enable change is taking place
7973 * @param enabled True if enabling the data, otherwise disabling.
7974 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007975 */
7976 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007977 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007978 boolean enabled) {
7979 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7980 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7981 try {
7982 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007983 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007984 } catch (SecurityException se) {
7985 enforceModifyPermission();
7986 }
7987 } else {
7988 enforceModifyPermission();
7989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 Phone phone = getPhone(subId);
7994 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007995 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7996 phone.carrierActionSetMeteredApnsEnabled(enabled);
7997 } else {
7998 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 }
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008003 }
8004 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008005
8006 /**
8007 * Get Client request stats
8008 * @return List of Client Request Stats
8009 * @hide
8010 */
8011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008012 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8013 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008015 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016 return null;
8017 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008018 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
8022 if (phone != null) {
8023 return phone.getClientRequestStats();
8024 }
8025
8026 return null;
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008030 }
8031
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008032 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008033 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008034 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008035 }
Jack Yueb4124c2017-02-16 15:32:43 -08008036
8037 /**
Grace Chen70990072017-03-24 17:21:30 -07008038 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008039 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008040 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008041 * @param state State of SIM (power down, power up, pass through)
8042 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8043 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8044 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008045 *
8046 **/
8047 @Override
Grace Chen70990072017-03-24 17:21:30 -07008048 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008049 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008050 Phone phone = PhoneFactory.getPhone(slotIndex);
8051
vagdeviaf9a5b92018-08-15 16:01:53 -07008052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008057 phone.setSimPowerState(state, null, workSource);
8058 }
8059 } finally {
8060 Binder.restoreCallingIdentity(identity);
8061 }
8062 }
8063
8064 /**
8065 * Set SIM card power state.
8066 *
8067 * @param slotIndex SIM slot id.
8068 * @param state State of SIM (power down, power up, pass through)
8069 * @param callback callback to trigger after success or failure
8070 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8071 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8072 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8073 *
8074 **/
8075 @Override
8076 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8077 IIntegerConsumer callback) {
8078 enforceModifyPermission();
8079 Phone phone = PhoneFactory.getPhone(slotIndex);
8080
8081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8082
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 if (phone != null) {
8086 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8087 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 }
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008091 }
8092 }
Shuo Qiandd210312017-04-12 22:11:33 +00008093
Tyler Gunn65d45c22017-06-05 11:22:26 -07008094 private boolean isUssdApiAllowed(int subId) {
8095 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008097 if (configManager == null) {
8098 return false;
8099 }
8100 PersistableBundle pb = configManager.getConfigForSubId(subId);
8101 if (pb == null) {
8102 return false;
8103 }
8104 return pb.getBoolean(
8105 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8106 }
8107
Shuo Qiandd210312017-04-12 22:11:33 +00008108 /**
8109 * Check if phone is in emergency callback mode
8110 * @return true if phone is in emergency callback mode
8111 * @param subId sub id
8112 */
goneil9c5f4872017-12-05 14:07:56 -08008113 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008114 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008116 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117
8118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 if (phone != null) {
8121 return phone.isInEcm();
8122 } else {
8123 return false;
8124 }
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008127 }
8128 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008129
8130 /**
8131 * Get the current signal strength information for the given subscription.
8132 * Because this information is not updated when the device is in a low power state
8133 * it should not be relied-upon to be current.
8134 * @param subId Subscription index
8135 * @return the most recent cached signal strength info from the modem
8136 */
8137 @Override
8138 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 Phone p = getPhone(subId);
8142 if (p == null) {
8143 return null;
8144 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 return p.getSignalStrength();
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
8149 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008151
Pengquan Meng77b7f132018-08-22 14:49:57 -07008152 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008153 * Get the current modem radio state for the given slot.
8154 * @param slotIndex slot index.
8155 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008156 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008157 * @return the current radio power state from the modem
8158 */
8159 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008160 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008161 Phone phone = PhoneFactory.getPhone(slotIndex);
8162 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8164 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008165 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8166 }
8167
8168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 return phone.getRadioPowerState();
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
8174 }
8175 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8176 }
8177
8178 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008179 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8180 *
8181 * <p>Requires one of the following permissions:
8182 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8183 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8184 * privileges.
8185 *
8186 * @param subId subscription id
8187 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8188 * {@code false}.
8189 */
8190 @Override
8191 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008192 try {
8193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8194 null);
8195 } catch (Exception e) {
8196 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8197 mApp, subId, "isDataRoamingEnabled");
8198 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008199
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 boolean isEnabled = false;
8201 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008202 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008203 Phone phone = getPhone(subId);
8204 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008205 } finally {
8206 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008208 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008209 }
8210
8211
8212 /**
8213 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8214 *
8215 * <p> Requires permission:
8216 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8217 * privileges.
8218 *
8219 * @param subId subscription id
8220 * @param isEnabled {@code true} means enable, {@code false} means disable.
8221 */
8222 @Override
8223 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8225 mApp, subId, "setDataRoamingEnabled");
8226
Pengquan Menga1bb6272018-09-06 09:59:22 -07008227 final long identity = Binder.clearCallingIdentity();
8228 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008229 Phone phone = getPhone(subId);
8230 if (phone != null) {
8231 phone.setDataRoamingEnabled(isEnabled);
8232 }
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008235 }
8236 }
8237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008238 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008239 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008240 TelephonyPermissions
8241 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008242 mApp, subId, "isManualNetworkSelectionAllowed");
8243
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008244 boolean isAllowed = true;
8245 final long identity = Binder.clearCallingIdentity();
8246 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008247 Phone phone = getPhone(subId);
8248 if (phone != null) {
8249 isAllowed = phone.isCspPlmnEnabled();
8250 }
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 return isAllowed;
8255 }
8256
8257 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008258 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008259 // Verify that tha callingPackage belongs to the calling UID
8260 mApp.getSystemService(AppOpsManager.class)
8261 .checkPackage(Binder.getCallingUid(), callingPackage);
8262
Jordan Liu1e142fc2019-04-22 15:10:43 -07008263 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008264 try {
8265 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008266 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008267 } catch (SecurityException e) {
8268 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8269 // has carrier privileges on an active UICC
8270 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8271 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008272 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008273 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008274 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008278 UiccController uiccController = UiccController.getInstance();
8279 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008280 if (hasReadPermission) {
8281 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008282 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008283
8284 // Remove private info if the caller doesn't have access
8285 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8286 for (UiccCardInfo cardInfo : cardInfos) {
8287 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8288 // is available
8289 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8290 if (card == null || card.getUiccProfile() == null) {
8291 // assume no access if the card or profile is unavailable
8292 filteredInfos.add(cardInfo.getUnprivileged());
8293 continue;
8294 }
8295 UiccProfile profile = card.getUiccProfile();
8296 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8297 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8298 filteredInfos.add(cardInfo);
8299 } else {
8300 filteredInfos.add(cardInfo.getUnprivileged());
8301 }
8302 }
8303 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
8307 }
8308
8309 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008310 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008311 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8316 if (slots == null) {
8317 Rlog.i(LOG_TAG, "slots is null.");
8318 return null;
8319 }
8320
8321 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8322 for (int i = 0; i < slots.length; i++) {
8323 UiccSlot slot = slots[i];
8324 if (slot == null) {
8325 continue;
8326 }
8327
Jordan Liu7be7e652019-05-06 18:55:02 +00008328 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 UiccCard card = slot.getUiccCard();
8330 if (card != null) {
8331 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008332 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008333 cardId = slot.getEid();
8334 if (TextUtils.isEmpty(cardId)) {
8335 cardId = slot.getIccId();
8336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 }
8338
Jordan Liu857451f2019-05-09 16:35:35 -07008339 if (cardId != null) {
8340 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8341 // if cardId is an EID, it's all digits so this is fine
8342 cardId = IccUtils.stripTrailingFs(cardId);
8343 }
8344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 int cardState = 0;
8346 switch (slot.getCardState()) {
8347 case CARDSTATE_ABSENT:
8348 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8349 break;
8350 case CARDSTATE_PRESENT:
8351 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8352 break;
8353 case CARDSTATE_ERROR:
8354 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8355 break;
8356 case CARDSTATE_RESTRICTED:
8357 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8358 break;
8359 default:
8360 break;
8361
8362 }
8363
8364 infos[i] = new UiccSlotInfo(
8365 slot.isActive(),
8366 slot.isEuicc(),
8367 cardId,
8368 cardState,
8369 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008370 slot.isExtendedApduSupported(),
8371 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 }
8373 return infos;
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008376 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008377 }
8378
8379 @Override
8380 public boolean switchSlots(int[] physicalSlots) {
8381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
8388 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008389 }
Jack Yu4c988042018-02-27 15:30:01 -08008390
8391 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008392 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 return UiccController.getInstance().getCardIdForDefaultEuicc();
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
8400
Pengquan Meng85728fb2018-03-12 16:31:21 -07008401 /**
goneil47ffb6e2018-04-06 15:40:58 -07008402 * A test API to reload the UICC profile.
8403 *
8404 * <p>Requires that the calling app has permission
8405 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8406 * @hide
8407 */
8408 @Override
8409 public void refreshUiccProfile(int subId) {
8410 enforceModifyPermission();
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 Phone phone = getPhone(subId);
8415 if (phone == null) {
8416 return;
8417 }
8418 UiccCard uiccCard = phone.getUiccCard();
8419 if (uiccCard == null) {
8420 return;
8421 }
8422 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8423 if (uiccProfile == null) {
8424 return;
8425 }
8426 uiccProfile.refresh();
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
8432 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008433 * Returns false if the mobile data is disabled by default, otherwise return true.
8434 */
8435 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008436 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008437 }
8438
8439 /**
8440 * Returns true if the data roaming is enabled by default, i.e the system property
8441 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8442 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8443 */
8444 private boolean getDefaultDataRoamingEnabled(int subId) {
8445 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008446 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008447 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008448 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8449 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8450 return isDataRoamingEnabled;
8451 }
8452
8453 /**
8454 * Returns the default network type for the given {@code subId}, if the default network type is
8455 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8456 */
8457 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008458 List<Integer> list = TelephonyProperties.default_network();
8459 int phoneId = mSubscriptionController.getPhoneId(subId);
8460 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8461 return list.get(phoneId);
8462 }
8463 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008464 }
fionaxua13278b2018-03-21 00:08:13 -07008465
8466 @Override
8467 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008468 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470
8471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 final Phone phone = getPhone(subId);
8474 if (phone == null) {
8475 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8476 return;
8477 }
chen xueaba88a2019-03-15 13:15:10 -07008478 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8479 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008480 if (carrierPrivilegeRules == null) {
8481 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8482 } else {
8483 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485 } finally {
8486 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008487 }
fionaxua13278b2018-03-21 00:08:13 -07008488 }
8489
8490 @Override
8491 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008492 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 final Phone phone = getPhone(subId);
8497 if (phone == null) {
8498 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8499 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8500 }
8501 return phone.getCarrierIdListVersion();
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008504 }
fionaxua13278b2018-03-21 00:08:13 -07008505 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008506
8507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8509 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008511 mApp, subId, callingPackage, callingFeatureId,
8512 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008513 return -1;
8514 }
8515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008523
8524 @Override
8525 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008526 TelephonyPermissions
8527 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008528 mApp, subId, "getCdmaRoamingMode");
8529
8530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
8535 }
8536 }
8537
8538 @Override
8539 public boolean setCdmaRoamingMode(int subId, int mode) {
8540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8541 mApp, subId, "setCdmaRoamingMode");
8542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008552 public int getCdmaSubscriptionMode(int subId) {
8553 TelephonyPermissions
8554 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8555 mApp, subId, "getCdmaSubscriptionMode");
8556
8557 final long identity = Binder.clearCallingIdentity();
8558 try {
8559 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 }
8564
8565 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008566 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8568 mApp, subId, "setCdmaSubscriptionMode");
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008577
sqianc5eccab2018-10-19 18:46:41 -07008578 @Override
sqian8c685422019-02-22 15:55:18 -08008579 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008580 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008582 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8583 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008584 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8585 }
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
sqian854d44b2018-12-12 16:48:18 -08008588 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8589 for (Phone phone: PhoneFactory.getPhones()) {
8590 if (phone.getEmergencyNumberTracker() != null
8591 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8592 emergencyNumberListInternal.put(
8593 phone.getSubId(),
8594 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8595 }
sqian11b7a0e2018-12-05 18:48:28 -08008596 }
sqian854d44b2018-12-12 16:48:18 -08008597 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
sqianc5eccab2018-10-19 18:46:41 -07008601 }
8602
8603 @Override
sqian8c685422019-02-22 15:55:18 -08008604 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008605 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008606 if (!exactMatch) {
8607 TelephonyPermissions
8608 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008609 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008610 }
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
sqian854d44b2018-12-12 16:48:18 -08008613 for (Phone phone: PhoneFactory.getPhones()) {
8614 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008615 && phone.getEmergencyNumberTracker()
8616 .isEmergencyNumber(number, exactMatch)) {
8617 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008618 }
sqian11b7a0e2018-12-05 18:48:28 -08008619 }
8620 return false;
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
sqianf4ca7ed2019-01-15 18:32:07 -08008626 /**
8627 * Update emergency number list for test mode.
8628 */
8629 @Override
8630 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8632 "updateEmergencyNumberListTestMode");
8633
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 for (Phone phone: PhoneFactory.getPhones()) {
8637 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8638 if (tracker != null) {
8639 tracker.executeEmergencyNumberTestModeCommand(action, num);
8640 }
8641 }
8642 } finally {
8643 Binder.restoreCallingIdentity(identity);
8644 }
8645 }
8646
8647 /**
8648 * Get the full emergency number list for test mode.
8649 */
8650 @Override
8651 public List<String> getEmergencyNumberListTestMode() {
8652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8653 "getEmergencyNumberListTestMode");
8654
8655 final long identity = Binder.clearCallingIdentity();
8656 try {
8657 Set<String> emergencyNumbers = new HashSet<>();
8658 for (Phone phone: PhoneFactory.getPhones()) {
8659 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8660 if (tracker != null) {
8661 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8662 emergencyNumbers.add(num.getNumber());
8663 }
8664 }
8665 }
8666 return new ArrayList<>(emergencyNumbers);
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 }
8671
chen xud6b45bd2018-10-30 22:27:10 -07008672 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008673 public int getEmergencyNumberDbVersion(int subId) {
8674 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8675
8676 final long identity = Binder.clearCallingIdentity();
8677 try {
8678 final Phone phone = getPhone(subId);
8679 if (phone == null) {
8680 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8681 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8682 }
8683 return phone.getEmergencyNumberDbVersion();
8684 } finally {
8685 Binder.restoreCallingIdentity(identity);
8686 }
8687 }
8688
8689 @Override
8690 public void notifyOtaEmergencyNumberDbInstalled() {
8691 enforceModifyPermission();
8692
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
8695 for (Phone phone: PhoneFactory.getPhones()) {
8696 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8697 if (tracker != null) {
8698 tracker.updateOtaEmergencyNumberDatabase();
8699 }
8700 }
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 }
8705
8706 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008707 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008708 enforceActiveEmergencySessionPermission();
8709
8710 final long identity = Binder.clearCallingIdentity();
8711 try {
8712 for (Phone phone: PhoneFactory.getPhones()) {
8713 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8714 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008715 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8716 }
8717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 }
8722
8723 @Override
8724 public void resetOtaEmergencyNumberDbFilePath() {
8725 enforceActiveEmergencySessionPermission();
8726
8727 final long identity = Binder.clearCallingIdentity();
8728 try {
8729 for (Phone phone: PhoneFactory.getPhones()) {
8730 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8731 if (tracker != null) {
8732 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008733 }
8734 }
8735 } finally {
8736 Binder.restoreCallingIdentity(identity);
8737 }
8738 }
8739
8740 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008741 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8742 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8743 Phone phone = getPhone(subId);
8744 if (phone == null) {
8745 return null;
8746 }
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 UiccProfile profile = UiccController.getInstance()
8750 .getUiccProfileForPhone(phone.getPhoneId());
8751 if (profile != null) {
8752 return profile.getCertsFromCarrierPrivilegeAccessRules();
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 return null;
8758 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008759
8760 /**
8761 * Enable or disable a modem stack.
8762 */
8763 @Override
8764 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8765 enforceModifyPermission();
8766
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 Phone phone = PhoneFactory.getPhone(slotIndex);
8770 if (phone == null) {
8771 return false;
8772 } else {
8773 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8774 }
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
8777 }
8778 }
Michelecea4cf22018-12-21 15:00:11 -08008779
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008780 /**
8781 * Whether a modem stack is enabled or not.
8782 */
8783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008784 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8785 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008786 Phone phone = PhoneFactory.getPhone(slotIndex);
8787 if (phone == null) return false;
8788
8789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008790 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8791 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008792 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8793 }
8794
8795 final long identity = Binder.clearCallingIdentity();
8796 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008797 try {
8798 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8799 } catch (NoSuchElementException ex) {
8800 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8801 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
Michelecea4cf22018-12-21 15:00:11 -08008807 @Override
Michele0ea7d782019-03-19 14:58:42 -07008808 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008809 enforceModifyPermission();
8810
8811 final long identity = Binder.clearCallingIdentity();
8812 try {
8813 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008814 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008815 .commit();
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
8820
8821 @Override
Michele0ea7d782019-03-19 14:58:42 -07008822 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008823 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008825 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8826 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008827 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008828 }
Michelecea4cf22018-12-21 15:00:11 -08008829
8830 final long identity = Binder.clearCallingIdentity();
8831 try {
Michele0ea7d782019-03-19 14:58:42 -07008832 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008833 } finally {
8834 Binder.restoreCallingIdentity(identity);
8835 }
8836 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008837
Michele0ea7d782019-03-19 14:58:42 -07008838 @TelephonyManager.IsMultiSimSupportedResult
8839 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008840 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8841 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8842 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008843 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8844 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008845 }
8846 // Check if the hardware supports multisim functionality. If usage of multisim is not
8847 // supported by the modem, indicate that it is restricted.
8848 PhoneCapability staticCapability =
8849 mPhoneConfigurationManager.getStaticPhoneCapability();
8850 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008851 loge("isMultiSimSupportedInternal: no static configuration available");
8852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008853 }
Sarah Chin7caee492020-02-18 20:49:02 +00008854 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008855 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8856 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008857 }
8858 // Check if support of multiple SIMs is restricted by carrier
8859 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008860 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008861 }
8862
Michele0ea7d782019-03-19 14:58:42 -07008863 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008864 }
8865
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008866 /**
8867 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008868 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8869 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8870 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008871 * @param numOfSims number of active sims we want to switch to
8872 */
8873 @Override
8874 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008875 if (numOfSims == 1) {
8876 enforceModifyPermission();
8877 } else {
8878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8879 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8880 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008881 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008882
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008883 try {
Michele30b57b22019-03-01 12:01:14 -08008884 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008885 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008886 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8887 return;
8888 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008889 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
8893 }
8894
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008895 @Override
8896 public boolean isApplicationOnUicc(int subId, int appType) {
8897 enforceReadPrivilegedPermission("isApplicationOnUicc");
8898 Phone phone = getPhone(subId);
8899 if (phone == null) {
8900 return false;
8901 }
8902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 UiccCard uiccCard = phone.getUiccCard();
8905 if (uiccCard == null) {
8906 return false;
8907 }
8908 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8909 if (uiccProfile == null) {
8910 return false;
8911 }
8912 if (TelephonyManager.APPTYPE_SIM <= appType
8913 && appType <= TelephonyManager.APPTYPE_ISIM) {
8914 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8915 }
8916 return false;
8917 } finally {
8918 Binder.restoreCallingIdentity(identity);
8919 }
8920 }
8921
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008922 /**
chen xub4baa772019-04-03 10:23:41 -07008923 * Get whether making changes to modem configurations will trigger reboot.
8924 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008925 */
8926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008927 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8928 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008930 mApp, subId, callingPackage, callingFeatureId,
8931 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008932 return false;
8933 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
8939 }
8940 }
8941
Nathan Harold29f5f052019-02-15 13:41:57 -08008942 private void updateModemStateMetrics() {
8943 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8944 // TODO: check the state for each modem if the api is ready.
8945 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8946 }
8947
Pengquan Meng3889a572019-01-23 11:16:29 -08008948 @Override
8949 public int[] getSlotsMapping() {
8950 enforceReadPrivilegedPermission("getSlotsMapping");
8951
8952 final long identity = Binder.clearCallingIdentity();
8953 try {
8954 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8955 // All logical slots should have a mapping to a physical slot.
8956 int[] logicalSlotsMapping = new int[phoneCount];
8957 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8958 for (int i = 0; i < slotInfos.length; i++) {
8959 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8960 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8961 }
8962 }
8963 return logicalSlotsMapping;
8964 } finally {
8965 Binder.restoreCallingIdentity(identity);
8966 }
8967 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008968
8969 /**
8970 * Get the IRadio HAL Version
8971 */
8972 @Override
8973 public int getRadioHalVersion() {
8974 Phone phone = getDefaultPhone();
8975 if (phone == null) return -1;
8976 HalVersion hv = phone.getHalVersion();
8977 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8978 return hv.major * 100 + hv.minor;
8979 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008980
8981 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008982 * Get the current calling package name.
8983 * @return the current calling package name
8984 */
8985 @Override
8986 public String getCurrentPackageName() {
8987 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8988 }
8989
8990 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008991 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8992 * corresponding network requests on a subId.
8993 *
8994 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008995 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008996 * 2) APN is un-metered for this subscription, or
8997 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008998 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008999 *
9000 * @return whether data is allowed for a apn type.
9001 *
9002 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009003 */
9004 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009005 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009006 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9007 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009008
9009 // Now that all security checks passes, perform the operation as ourselves.
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 Phone phone = getPhone(subId);
9013 if (phone == null) return false;
9014
Jack Yu41407ee2019-05-13 16:54:09 -07009015 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009016 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
9020 }
9021
9022 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009023 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009024 enforceReadPrivilegedPermission("isApnMetered");
9025
9026 // Now that all security checks passes, perform the operation as ourselves.
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 Phone phone = getPhone(subId);
9030 if (phone == null) return true; // By default return true.
9031
Jack Yu41407ee2019-05-13 16:54:09 -07009032 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
9036 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009037
9038 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009039 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9040 int subscriptionId, IBooleanConsumer resultCallback) {
9041 enforceModifyPermission();
9042 long token = Binder.clearCallingIdentity();
9043 try {
9044 Phone phone = getPhone(subscriptionId);
9045 if (phone == null) {
9046 try {
9047 if (resultCallback != null) {
9048 resultCallback.accept(false);
9049 }
9050 } catch (RemoteException e) {
9051 // ignore
9052 }
9053 return;
9054 }
9055 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9056 Pair.create(specifiers, (x) -> {
9057 try {
9058 if (resultCallback != null) {
9059 resultCallback.accept(x);
9060 }
9061 } catch (RemoteException e) {
9062 // ignore
9063 }
9064 });
9065 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9066 } finally {
9067 Binder.restoreCallingIdentity(token);
9068 }
9069 }
9070
9071 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009072 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9073 TelephonyPermissions
9074 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9075 mApp, subId, "getSystemSelectionChannels");
9076 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 List<RadioAccessSpecifier> specifiers =
9080 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9081 null, subId, workSource);
9082 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9083 return specifiers;
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
9086 }
9087 }
9088
9089 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009090 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009091 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009092 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9093 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9094 if (iccRecords == null) {
9095 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9096 return false;
9097 }
9098 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9099 }
9100
9101 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009102 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9103 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009104 if (callingPackage == null) {
9105 callingPackage = getCurrentPackageName();
9106 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009107 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9108 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009109 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9110 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009111 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9112 }
9113 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9114 Intent intent = new Intent();
9115 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9116 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9117 // Bring up choose default SMS subscription dialog right now
9118 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9119 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9120 mApp.startActivity(intent);
9121 }
chen xud5ca2d52019-05-28 15:20:57 -07009122
9123 @Override
9124 public String getMmsUAProfUrl(int subId) {
9125 //TODO investigate if this API should require proper permission check in R b/133791609
9126 final long identity = Binder.clearCallingIdentity();
9127 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009128 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9129 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9130 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9131 return carrierUAProfUrl;
9132 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009133 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9134 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 @Override
9141 public String getMmsUserAgent(int subId) {
9142 //TODO investigate if this API should require proper permission check in R b/133791609
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009145 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9146 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9147 if (!TextUtils.isEmpty(carrierUserAgent)) {
9148 return carrierUserAgent;
9149 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009150 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9151 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
9155 }
Jack Yub07d4972019-05-28 16:12:25 -07009156
9157 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009158 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9159 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009160
Jack Yub07d4972019-05-28 16:12:25 -07009161 final long identity = Binder.clearCallingIdentity();
9162 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009163 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009164 if (phone == null) return false;
9165
Hall Liua62f5da2020-09-25 10:42:19 -07009166 switch (policy) {
9167 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9168 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9169 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9170 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9171 default:
9172 throw new IllegalArgumentException(policy + " is not a valid policy");
9173 }
Jack Yub07d4972019-05-28 16:12:25 -07009174 } finally {
9175 Binder.restoreCallingIdentity(identity);
9176 }
9177 }
9178
9179 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009180 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9181 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009182 enforceModifyPermission();
9183
changbettyd5c246e2019-12-24 15:40:37 +08009184 final long identity = Binder.clearCallingIdentity();
9185 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009186 Phone phone = getPhone(subscriptionId);
9187 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009188
Hall Liua62f5da2020-09-25 10:42:19 -07009189 switch (policy) {
9190 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9191 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9192 break;
9193 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9194 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9195 break;
9196 default:
9197 throw new IllegalArgumentException(policy + " is not a valid policy");
9198 }
changbettyd5c246e2019-12-24 15:40:37 +08009199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009204 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009205 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009206 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9207 * otherwise.
9208 */
9209 @Override
9210 public void setCepEnabled(boolean isCepEnabled) {
9211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9216 for (Phone phone : PhoneFactory.getPhones()) {
9217 Phone defaultPhone = phone.getImsPhone();
9218 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9219 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9220 ImsPhoneCallTracker imsPhoneCallTracker =
9221 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9222 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9223 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9224 + imsPhone.getMsisdn());
9225 }
9226 }
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 }
allenwtsu46dcc572020-01-08 18:24:03 +08009231
9232 /**
9233 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9234 *
9235 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9236 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9237 * before being read.
9238 */
9239 @Override
9240 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9241 isCompressed) {
9242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9243 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009244 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9245 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9246 }
9247 if (!isImsAvailableOnDevice()) {
9248 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9249 "IMS not available on device.");
9250 }
9251
9252 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009253 try {
Hui Wang761a6682020-10-31 05:12:53 +00009254 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9255 } finally {
9256 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009257 }
9258 }
zoey chene02881a2019-12-30 16:11:23 +08009259
9260 @Override
9261 public boolean isIccLockEnabled(int subId) {
9262 enforceReadPrivilegedPermission("isIccLockEnabled");
9263
9264 // Now that all security checks passes, perform the operation as ourselves.
9265 final long identity = Binder.clearCallingIdentity();
9266 try {
9267 Phone phone = getPhone(subId);
9268 if (phone != null && phone.getIccCard() != null) {
9269 return phone.getIccCard().getIccLockEnabled();
9270 } else {
9271 return false;
9272 }
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
9278 /**
9279 * Set the ICC pin lock enabled or disabled.
9280 *
9281 * @return an integer representing the status of IccLock enabled or disabled in the following
9282 * three cases:
9283 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9284 * successfully.
9285 * - Positive number and zero for remaining password attempts.
9286 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9287 *
9288 */
9289 @Override
9290 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9291 enforceModifyPermission();
9292
9293 Phone phone = getPhone(subId);
9294 if (phone == null) {
9295 return 0;
9296 }
9297 // Now that all security checks passes, perform the operation as ourselves.
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9301 new Pair<Boolean, String>(enabled, password), phone, null);
9302 return attemptsRemaining;
9303
9304 } catch (Exception e) {
9305 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 return 0;
9310 }
9311
9312 /**
9313 * Change the ICC password used in ICC pin lock.
9314 *
9315 * @return an integer representing the status of IccLock changed in the following three cases:
9316 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9317 * - Positive number and zero for remaining password attempts.
9318 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9319 *
9320 */
9321 @Override
9322 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9323 enforceModifyPermission();
9324
9325 Phone phone = getPhone(subId);
9326 if (phone == null) {
9327 return 0;
9328 }
9329 // Now that all security checks passes, perform the operation as ourselves.
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
9332 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9333 new Pair<String, String>(oldPassword, newPassword), phone, null);
9334 return attemptsRemaining;
9335
9336 } catch (Exception e) {
9337 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 return 0;
9342 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009343
9344 /**
9345 * Request for receiving user activity notification
9346 */
9347 @Override
9348 public void requestUserActivityNotification() {
9349 if (!mNotifyUserActivity.get()
9350 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9351 mNotifyUserActivity.set(true);
9352 }
9353 }
9354
9355 /**
9356 * Called when userActivity is signalled in the power manager.
9357 * This is safe to call from any thread, with any window manager locks held or not.
9358 */
9359 @Override
9360 public void userActivity() {
9361 // ***************************************
9362 // * Inherited from PhoneWindowManager *
9363 // ***************************************
9364 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9365 // WITH ITS LOCKS HELD.
9366 //
9367 // This code must be VERY careful about the locks
9368 // it acquires.
9369 // In fact, the current code acquires way too many,
9370 // and probably has lurking deadlocks.
9371
9372 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9373 throw new SecurityException("Only the OS may call notifyUserActivity()");
9374 }
9375
9376 if (mNotifyUserActivity.getAndSet(false)) {
9377 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9378 USER_ACTIVITY_NOTIFICATION_DELAY);
9379 }
9380 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009381
9382 @Override
9383 public boolean canConnectTo5GInDsdsMode() {
9384 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9385 }
Jack Yud10cdd42020-09-28 20:28:01 -07009386
9387 @Override
9388 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9389 String callingFeatureId) {
9390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9391 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9392 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9393 }
9394
9395 Phone phone = getPhone(subId);
9396 if (phone == null) {
9397 throw new RuntimeException("phone is not available");
9398 }
9399 // Now that all security checks passes, perform the operation as ourselves.
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 return phone.getEquivalentHomePlmns();
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
Daniel Bright59e67312020-11-13 11:49:37 -08009407
9408 @Override
9409 public boolean isRadioInterfaceCapabilitySupported(
9410 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9411 RadioInterfaceCapabilities radioInterfaceCapabilities =
9412 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9413 if (radioInterfaceCapabilities == null) {
9414 throw new RuntimeException("radio interface capabilities are not available");
9415 } else {
9416 return radioInterfaceCapabilities.isSupported(capability);
9417 }
9418 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009419
Hui Wang641e81c2020-10-12 12:14:23 -07009420 @Override
9421 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9422 UaSecurityProtocolIdentifier securityProtocol,
9423 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9424 throws RemoteException {
9425 enforceModifyPermission();
9426 if (DBG) {
9427 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9428 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9429 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9430 }
9431
9432 if (!SubscriptionManager.isValidSubscriptionId(subId)
9433 || appType < TelephonyManager.APPTYPE_UNKNOWN
9434 || appType > TelephonyManager.APPTYPE_ISIM
9435 || nafUrl == null || securityProtocol == null || callback == null) {
9436 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9437 if (callback != null) {
9438 try {
9439 callback.onAuthenticationFailure(
9440 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9441 } catch (RemoteException exception) {
9442 log("Fail to notify onAuthenticationFailure due to " + exception);
9443 }
9444 return;
9445 }
9446 }
9447
9448 final long token = Binder.clearCallingIdentity();
9449 try {
9450 getGbaManager(subId).bootstrapAuthenticationRequest(
9451 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9452 forceBootStrapping, callback));
9453 } finally {
9454 Binder.restoreCallingIdentity(token);
9455 }
9456 }
9457
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009458 /**
9459 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9460 * requested radio power state will actually be set. See {@link
9461 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9462 *
9463 * @param subId the subscription ID of the phone requesting to set the radio power state.
9464 * @param enable {@code true} if trying to turn radio on.
9465 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9466 * false}.
9467 */
9468 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9469 Phone phone = getPhone(subId);
9470 if (phone != null) {
9471 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9472 return true;
9473 }
9474 return false;
9475 }
9476
9477 private int handleDataThrottlingRequest(int subId,
9478 DataThrottlingRequest dataThrottlingRequest) {
9479 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9480 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9481 if (!setRadioPowerForThermal(subId, true)) {
9482 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9483 }
9484
9485 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9486
9487 int thermalMitigationResult =
9488 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9489 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9490 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9491 }
9492 return thermalMitigationResult;
9493 }
9494
9495 /**
9496 * Thermal mitigation request to control functionalities at modem.
9497 *
9498 * @param subId the id of the subscription.
9499 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9500 *
9501 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9502 */
9503 @Override
9504 @ThermalMitigationResult
9505 public int sendThermalMitigationRequest(
9506 int subId,
9507 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9508 enforceModifyPermission();
9509
9510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9511 final long identity = Binder.clearCallingIdentity();
9512
9513 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9514 try {
9515 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9516 switch (thermalMitigationAction) {
9517 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9518 thermalMitigationResult =
9519 handleDataThrottlingRequest(subId,
9520 thermalMitigationRequest.getDataThrottlingRequest());
9521 break;
9522 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9523 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9524 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9525 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9526 }
9527
9528 // Ensure that radio is on. If not able to power on due to phone being
9529 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9530 if (!setRadioPowerForThermal(subId, true)) {
9531 thermalMitigationResult =
9532 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9533 break;
9534 }
9535
9536 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9537 false);
9538 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9539 break;
9540 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9541 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9542 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9543 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9544 }
9545
9546 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9547 if (registry != null) {
9548 TelephonyConnectionService service =
9549 registry.getTelephonyConnectionService();
9550 Phone phone = getPhone(subId);
9551 if (phone == null) {
9552 thermalMitigationResult =
9553 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9554 break;
9555 }
9556
9557 if (PhoneConstantConversions.convertCallState(phone.getState())
9558 != TelephonyManager.CALL_STATE_IDLE
9559 || phone.isInEmergencySmsMode() || phone.isInEcm()
9560 || (service != null && service.isEmergencyCallPending())) {
9561 String errorMessage = "Phone state is not valid. call state = "
9562 + PhoneConstantConversions.convertCallState(phone.getState())
9563 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9564 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9565 errorMessage += service == null
9566 ? " TelephonyConnectionService is null"
9567 : " isEmergencyCallPending = "
9568 + service.isEmergencyCallPending();
9569 Log.e(LOG_TAG, errorMessage);
9570 thermalMitigationResult =
9571 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9572 break;
9573 }
9574 } else {
9575 thermalMitigationResult =
9576 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9577 break;
9578 }
9579
9580 // Turn radio off. If not able to power off due to phone being unavailable,
9581 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9582 if (!setRadioPowerForThermal(subId, false)) {
9583 thermalMitigationResult =
9584 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9585 break;
9586 }
9587 thermalMitigationResult =
9588 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9589 break;
9590 default:
9591 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9592 + "not exist. Requested action: " + thermalMitigationAction);
9593 }
9594 } catch (IllegalArgumentException e) {
9595 throw e;
9596 } catch (Exception e) {
9597 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9598 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602
9603 if (DBG) {
9604 log("thermalMitigationRequest returning with thermalMitigationResult: "
9605 + thermalMitigationResult);
9606 }
9607
9608 return thermalMitigationResult;
9609 }
Hui Wang641e81c2020-10-12 12:14:23 -07009610
9611 /**
9612 * Set the GbaService Package Name that Telephony will bind to.
9613 *
9614 * @param subId The sim that the GbaService is associated with.
9615 * @param packageName The name of the package to be replaced with.
9616 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9617 */
9618 @Override
9619 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9620 enforceModifyPermission();
9621
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
9624 return getGbaManager(subId).overrideServicePackage(packageName);
9625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
9628 }
9629
9630 /**
9631 * Return the package name of the currently bound GbaService.
9632 *
9633 * @param subId The sim that the GbaService is associated with.
9634 * @return the package name of the GbaService configuration, null if GBA is not supported.
9635 */
9636 @Override
9637 public String getBoundGbaService(int subId) {
9638 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9639
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
9642 return getGbaManager(subId).getServicePackage();
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
9648 /**
9649 * Set the release time for telephony to unbind GbaService.
9650 *
9651 * @param subId The sim that the GbaService is associated with.
9652 * @param interval The release time to unbind GbaService by millisecond.
9653 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9654 */
9655 @Override
9656 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9657 enforceModifyPermission();
9658
9659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 return getGbaManager(subId).overrideReleaseTime(interval);
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 /**
9668 * Return the release time for telephony to unbind GbaService.
9669 *
9670 * @param subId The sim that the GbaService is associated with.
9671 * @return The release time to unbind GbaService by millisecond.
9672 */
9673 @Override
9674 public int getGbaReleaseTime(int subId) {
9675 enforceReadPrivilegedPermission("getGbaReleaseTime");
9676
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 return getGbaManager(subId).getReleaseTime();
9680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
9684
9685 private GbaManager getGbaManager(int subId) {
9686 GbaManager instance = GbaManager.getInstance(subId);
9687 if (instance == null) {
9688 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9689 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9690 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9691 }
9692 return instance;
9693 }
Hui Wang761a6682020-10-31 05:12:53 +00009694
9695 /**
9696 * indicate whether the device and the carrier can support
9697 * RCS VoLTE single registration.
9698 */
9699 @Override
9700 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9701 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9702
9703 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9704 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9705 }
9706
9707 final long identity = Binder.clearCallingIdentity();
9708 try {
9709 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9710 if (rpm != null) {
9711 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9712 }
9713 return false;
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
9719 /**
9720 * Register RCS provisioning callback.
9721 */
9722 @Override
9723 public void registerRcsProvisioningChangedCallback(int subId,
9724 IRcsConfigCallback callback) {
9725 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9726
9727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9728 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9729 }
9730 if (!isImsAvailableOnDevice()) {
9731 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9732 "IMS not available on device.");
9733 }
9734
9735 final long identity = Binder.clearCallingIdentity();
9736 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009737 if (!RcsProvisioningMonitor.getInstance()
9738 .registerRcsProvisioningChangedCallback(subId, callback)) {
9739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9740 "Service not available for the subscription.");
9741 }
Hui Wang761a6682020-10-31 05:12:53 +00009742 } finally {
9743 Binder.restoreCallingIdentity(identity);
9744 }
9745 }
9746
9747 /**
9748 * Unregister RCS provisioning callback.
9749 */
9750 @Override
9751 public void unregisterRcsProvisioningChangedCallback(int subId,
9752 IRcsConfigCallback callback) {
9753 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9754
9755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9756 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9757 }
9758 if (!isImsAvailableOnDevice()) {
9759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9760 "IMS not available on device.");
9761 }
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009765 RcsProvisioningMonitor.getInstance()
9766 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 /**
9773 * trigger RCS reconfiguration.
9774 */
9775 public void triggerRcsReconfiguration(int subId) {
9776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9777 mApp, subId, "triggerRcsReconfiguration");
9778
9779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9780 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9781 }
9782 if (!isImsAvailableOnDevice()) {
9783 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9784 "IMS not available on device.");
9785 }
9786
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
9794
9795 /**
9796 * Provide the client configuration parameters of the RCS application.
9797 */
9798 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9800 mApp, subId, "setRcsClientConfiguration");
9801
9802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9803 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9804 }
9805 if (!isImsAvailableOnDevice()) {
9806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9807 "IMS not available on device.");
9808 }
9809
9810 final long identity = Binder.clearCallingIdentity();
9811
9812 try {
9813 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9814 if (configBinder == null) {
9815 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9816 } else {
9817 configBinder.setRcsClientConfiguration(rcc);
9818 }
9819 } catch (RemoteException e) {
9820 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 }
9825
9826 /**
9827 * Overrides the config of RCS VoLTE single registration enabled for the device.
9828 */
9829 @Override
9830 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9831 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9832 "setDeviceSingleRegistrationEnabledOverride");
9833 enforceModifyPermission();
9834
9835 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9836 : Boolean.parseBoolean(enabledStr);
9837 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9838 }
9839
9840 /**
9841 * Gets the config of RCS VoLTE single registration enabled for the device.
9842 */
9843 @Override
9844 public boolean getDeviceSingleRegistrationEnabled() {
9845 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9846 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9847 }
9848
9849 /**
9850 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9851 */
9852 @Override
9853 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9855 "setCarrierSingleRegistrationEnabledOverride");
9856 enforceModifyPermission();
9857
9858 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9859 : Boolean.parseBoolean(enabledStr);
9860 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9861 subId, enabled);
9862 }
9863
9864 /**
9865 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9866 */
9867 @Override
9868 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9869 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9870 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9871 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009872
9873 /**
9874 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9875 * their mobile plan.
9876 */
9877 @Override
9878 public String getMobileProvisioningUrl() {
9879 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 return getDefaultPhone().getMobileProvisioningUrl();
9883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009887}