blob: 8cf8f51ab1f3a72c048d31b467b2e6b7988ab744 [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;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080066import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080078import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080091import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080092import android.telephony.SignalStrengthUpdateRequest;
93import android.telephony.SignalThresholdInfo;
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 Nudelman24d51a52020-11-24 12:08:04 -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 Wang0866fcc2020-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 Wang068ab862020-10-31 05:12:53 +0000111import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-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 Wang068ab862020-10-31 05:12:53 +0000118import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-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 Liuaa4283b2020-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;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -0800139import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-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 Liud0d1dc92020-01-20 13:42:00 -0800143import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900173import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-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 chen84e2b212019-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 Liua1acea22020-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 Nudelman24d51a52020-11-24 12:08:04 -0800192import com.android.services.telephony.TelecomAccountRegistry;
193import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800194import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800195
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700196import java.io.FileDescriptor;
197import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800199import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800200import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800201import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800202import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100203import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700205import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800206import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800207import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800208import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800209import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210
211/**
212 * Implementation of the ITelephony interface.
213 */
Santos Cordon117fee72014-05-16 17:56:12 -0700214public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215 private static final String LOG_TAG = "PhoneInterfaceManager";
216 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
217 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
220 // Message codes used with mMainThreadHandler
221 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700222 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
223 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700224 private static final int CMD_OPEN_CHANNEL = 9;
225 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
226 private static final int CMD_CLOSE_CHANNEL = 11;
227 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800228 private static final int CMD_NV_READ_ITEM = 13;
229 private static final int EVENT_NV_READ_ITEM_DONE = 14;
230 private static final int CMD_NV_WRITE_ITEM = 15;
231 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
232 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
233 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700234 private static final int CMD_RESET_MODEM_CONFIG = 19;
235 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800236 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
237 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
238 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
239 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800240 private static final int CMD_SEND_ENVELOPE = 25;
241 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000242 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
243 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700244 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
245 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
246 private static final int CMD_EXCHANGE_SIM_IO = 31;
247 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800248 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
249 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700250 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
251 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700252 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
253 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700254 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
255 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
256 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
257 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700258 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
259 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
260 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
261 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700262 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800263 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
264 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000265 private static final int CMD_SWITCH_SLOTS = 50;
266 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700267 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
268 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
269 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
270 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
271 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
272 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
273 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
274 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700275 private static final int CMD_GET_ALL_CELL_INFO = 60;
276 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
277 private static final int CMD_GET_CELL_LOCATION = 62;
278 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700279 private static final int CMD_MODEM_REBOOT = 64;
280 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700281 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
282 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800283 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
284 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700285 private static final int CMD_GET_MODEM_STATUS = 70;
286 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700287 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
288 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700289 private static final int CMD_ERASE_MODEM_CONFIG = 74;
290 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800291 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
292 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
293 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
294 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800295 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
296 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800297 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800298 private static final int CMD_GET_CALL_FORWARDING = 83;
299 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
300 private static final int CMD_SET_CALL_FORWARDING = 85;
301 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
302 private static final int CMD_GET_CALL_WAITING = 87;
303 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
304 private static final int CMD_SET_CALL_WAITING = 89;
305 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700306 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
307 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
308 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
309 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700310 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
311 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800312 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
313 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800314 private static final int CMD_SET_DATA_THROTTLING = 99;
315 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800316 private static final int CMD_SET_SIM_POWER = 101;
317 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800318 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
319 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
320 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
321 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800323 // Parameters of select command.
324 private static final int SELECT_COMMAND = 0xA4;
325 private static final int SELECT_P1 = 0x04;
326 private static final int SELECT_P2 = 0;
327 private static final int SELECT_P3 = 0x10;
328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 /** The singleton instance. */
330 private static PhoneInterfaceManager sInstance;
331
Wink Saville3ab207e2014-11-20 13:07:20 -0800332 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800334 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700335 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private AppOpsManager mAppOps;
337 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800338 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700340 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Peter Wangdafb9ac2020-01-15 14:13:38 -0800342 /** User Activity */
343 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800344 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
345
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700346 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
347
Derek Tan97ebb422014-09-05 16:55:38 -0700348 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
349 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800350 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800351 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700352
Michelecea4cf22018-12-21 15:00:11 -0800353 // String to store multi SIM allowed
354 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
355
Derek Tan740e1672017-06-27 14:56:27 -0700356 // The AID of ISD-R.
357 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
358
yinxub1bed742017-04-17 11:45:04 -0700359 private NetworkScanRequestTracker mNetworkScanRequestTracker;
360
David Kelly5e06a7f2018-03-12 14:10:59 +0000361 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
362 private static final int MANUFACTURER_CODE_LENGTH = 8;
363
Jack Nudelman24d51a52020-11-24 12:08:04 -0800364 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
365
Derek Tan89e89d42014-07-08 17:00:10 -0700366 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700367 * Experiment flag to enable erase modem config on reset network, default value is false
368 */
369 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
370 "reset_network_erase_modem_config_enabled";
371
372 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700373 * A request object to use for transmitting data to an ICC.
374 */
375 private static final class IccAPDUArgument {
376 public int channel, cla, command, p1, p2, p3;
377 public String data;
378
379 public IccAPDUArgument(int channel, int cla, int command,
380 int p1, int p2, int p3, String data) {
381 this.channel = channel;
382 this.cla = cla;
383 this.command = command;
384 this.p1 = p1;
385 this.p2 = p2;
386 this.p3 = p3;
387 this.data = data;
388 }
389 }
390
391 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700392 * A request object to use for transmitting data to an ICC.
393 */
394 private static final class ManualNetworkSelectionArgument {
395 public OperatorInfo operatorInfo;
396 public boolean persistSelection;
397
398 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
399 this.operatorInfo = operatorInfo;
400 this.persistSelection = persistSelection;
401 }
402 }
403
404 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
406 * request after sending. The main thread will notify the request when it is complete.
407 */
408 private static final class MainThreadRequest {
409 /** The argument to use for the request */
410 public Object argument;
411 /** The result of the request that is run on the main thread */
412 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800413 // The subscriber id that this request applies to. Defaults to
414 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
415 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
Nathan Harold92bed182018-10-12 18:16:49 -0700417 // In cases where subId is unavailable, the caller needs to specify the phone.
418 public Phone phone;
419
vagdeviaf9a5b92018-08-15 16:01:53 -0700420 public WorkSource workSource;
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 public MainThreadRequest(Object argument) {
423 this.argument = argument;
424 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800425
Nathan Harold92bed182018-10-12 18:16:49 -0700426 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
427 this.argument = argument;
428 if (phone != null) {
429 this.phone = phone;
430 }
431 this.workSource = workSource;
432 }
433
vagdeviaf9a5b92018-08-15 16:01:53 -0700434 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800435 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800436 if (subId != null) {
437 this.subId = subId;
438 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 }
442
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800443 private static final class IncomingThirdPartyCallArgs {
444 public final ComponentName component;
445 public final String callId;
446 public final String callerDisplayName;
447
448 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
449 String callerDisplayName) {
450 this.component = component;
451 this.callId = callId;
452 this.callerDisplayName = callerDisplayName;
453 }
454 }
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 /**
457 * A handler that processes messages on the main thread in the phone process. Since many
458 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
459 * inbound binder threads to the main thread in the phone process. The Binder thread
460 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
461 * on, which will be notified when the operation completes and will contain the result of the
462 * request.
463 *
464 * <p>If a MainThreadRequest object is provided in the msg.obj field,
465 * note that request.result must be set to something non-null for the calling thread to
466 * unblock.
467 */
468 private final class MainThreadHandler extends Handler {
469 @Override
470 public void handleMessage(Message msg) {
471 MainThreadRequest request;
472 Message onCompleted;
473 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800474 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800476 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477
478 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 case CMD_HANDLE_USSD_REQUEST: {
480 request = (MainThreadRequest) msg.obj;
481 final Phone phone = getPhoneFromRequest(request);
482 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
483 String ussdRequest = ussdObject.first;
484 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700485
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 if (!isUssdApiAllowed(request.subId)) {
487 // Carrier does not support use of this API, return failure.
488 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
489 UssdResponse response = new UssdResponse(ussdRequest, null);
490 Bundle returnData = new Bundle();
491 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
492 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700493
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 request.result = true;
495 notifyRequester(request);
496 return;
497 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700498
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 try {
500 request.result = phone != null
501 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
502 } catch (CallStateException cse) {
503 request.result = false;
504 }
505 // Wake up the requesting thread
506 notifyRequester(request);
507 break;
pkanwar32d516d2016-10-14 19:37:38 -0700508 }
509
Yorke Lee716f67e2015-06-17 15:39:16 -0700510 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700512 final Phone phone = getPhoneFromRequest(request);
513 request.result = phone != null ?
514 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
515 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800524 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 if (uiccCard == null) {
526 loge("iccTransmitApduLogicalChannel: No UICC");
527 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
531 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 iccArgument.channel, iccArgument.cla, iccArgument.command,
534 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 break;
538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 if (ar.result == null) {
547 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800548 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800550 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 } else {
552 loge("iccTransmitApduLogicalChannel: Unknown exception");
553 }
554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 break;
557
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
559 request = (MainThreadRequest) msg.obj;
560 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 if (uiccCard == null) {
563 loge("iccTransmitApduBasicChannel: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
568 request);
569 uiccCard.iccTransmitApduBasicChannel(
570 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
571 iccArgument.p3, iccArgument.data, onCompleted);
572 }
573 break;
574
575 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
580 } else {
581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("iccTransmitApduBasicChannel: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("iccTransmitApduBasicChannel: CommandException: " +
586 ar.exception);
587 } else {
588 loge("iccTransmitApduBasicChannel: Unknown exception");
589 }
590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 break;
593
594 case CMD_EXCHANGE_SIM_IO:
595 request = (MainThreadRequest) msg.obj;
596 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 if (uiccCard == null) {
599 loge("iccExchangeSimIO: No UICC");
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
604 request);
605 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
606 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
607 iccArgument.data, onCompleted);
608 }
609 break;
610
611 case EVENT_EXCHANGE_SIM_IO_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
614 if (ar.exception == null && ar.result != null) {
615 request.result = ar.result;
616 } else {
617 request.result = new IccIoResult(0x6f, 0, (byte[])null);
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 break;
621
Derek Tan4d5e5c12014-02-04 11:54:58 -0800622 case CMD_SEND_ENVELOPE:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("sendEnvelopeWithStatus: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
631 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
632 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800633 break;
634
635 case EVENT_SEND_ENVELOPE_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700641 request.result = new IccIoResult(0x6F, 0, (byte[])null);
642 if (ar.result == null) {
643 loge("sendEnvelopeWithStatus: Empty response");
644 } else if (ar.exception instanceof CommandException) {
645 loge("sendEnvelopeWithStatus: CommandException: " +
646 ar.exception);
647 } else {
648 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
649 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800652 break;
653
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 case CMD_OPEN_CHANNEL:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800657 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 if (uiccCard == null) {
659 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800660 request.result = new IccOpenLogicalChannelResponse(-1,
661 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800665 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
666 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
670 case EVENT_OPEN_CHANNEL_DONE:
671 ar = (AsyncResult) msg.obj;
672 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 int[] result = (int[]) ar.result;
676 int channelId = result[0];
677 byte[] selectResponse = null;
678 if (result.length > 1) {
679 selectResponse = new byte[result.length - 1];
680 for (int i = 1; i < result.length; ++i) {
681 selectResponse[i - 1] = (byte) result[i];
682 }
683 }
684 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700685 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 if (ar.result == null) {
688 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 if (ar.exception != null) {
691 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
692 }
693
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700695 if (ar.exception instanceof CommandException) {
696 CommandException.Error error =
697 ((CommandException) (ar.exception)).getCommandError();
698 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700699 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700700 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 }
703 }
704 openChannelResp = new IccOpenLogicalChannelResponse(
705 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700707 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
711 case CMD_CLOSE_CHANNEL:
712 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800713 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 if (uiccCard == null) {
715 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900716 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 } else {
719 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
720 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 break;
723
724 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800725 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
726 break;
727
728 case CMD_NV_READ_ITEM:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800731 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
732 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800733 break;
734
735 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 ar = (AsyncResult) msg.obj;
737 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800738 if (ar.exception == null && ar.result != null) {
739 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800741 request.result = "";
742 if (ar.result == null) {
743 loge("nvReadItem: Empty response");
744 } else if (ar.exception instanceof CommandException) {
745 loge("nvReadItem: CommandException: " +
746 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800748 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 }
750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 break;
753
Jake Hambye994d462014-02-03 13:10:13 -0800754 case CMD_NV_WRITE_ITEM:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
757 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800758 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700759 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800760 break;
761
762 case EVENT_NV_WRITE_ITEM_DONE:
763 handleNullReturnEvent(msg, "nvWriteItem");
764 break;
765
766 case CMD_NV_WRITE_CDMA_PRL:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800769 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800770 break;
771
772 case EVENT_NV_WRITE_CDMA_PRL_DONE:
773 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
774 break;
775
chen xu6dac5ab2018-10-26 17:39:23 -0700776 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800777 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700778 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800780 break;
781
chen xu6dac5ab2018-10-26 17:39:23 -0700782 case EVENT_RESET_MODEM_CONFIG_DONE:
783 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700786 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
789 request);
790 Phone phone = getPhoneFromRequest(request);
791 if (phone != null) {
792 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
793 } else {
794 loge("isNRDualConnectivityEnabled: No phone object");
795 request.result = false;
796 notifyRequester(request);
797 }
798 break;
799 }
800
801 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null && ar.result != null) {
805 request.result = ar.result;
806 } else {
807 // request.result must be set to something non-null
808 // for the calling thread to unblock
809 if (request.result != null) {
810 request.result = ar.result;
811 } else {
812 request.result = false;
813 }
814 if (ar.result == null) {
815 loge("isNRDualConnectivityEnabled: Empty response");
816 } else if (ar.exception instanceof CommandException) {
817 loge("isNRDualConnectivityEnabled: CommandException: "
818 + ar.exception);
819 } else {
820 loge("isNRDualConnectivityEnabled: Unknown exception");
821 }
822 }
823 notifyRequester(request);
824 break;
825
826 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
829 Phone phone = getPhoneFromRequest(request);
830 if (phone != null) {
831 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
832 request.workSource);
833 } else {
834 loge("enableNrDualConnectivity: No phone object");
835 request.result =
836 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
837 notifyRequester(request);
838 }
839 break;
840 }
841
842 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result =
847 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
848 } else {
849 request.result =
850 TelephonyManager
851 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
852 if (ar.exception instanceof CommandException) {
853 CommandException.Error error =
854 ((CommandException) (ar.exception)).getCommandError();
855 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
856 request.result =
857 TelephonyManager
858 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
859 }
860 loge("enableNrDualConnectivity" + ": CommandException: "
861 + ar.exception);
862 } else {
863 loge("enableNrDualConnectivity" + ": Unknown exception");
864 }
865 }
866 notifyRequester(request);
867 break;
868 }
869
Jake Hamby7c27be32014-03-03 13:25:59 -0800870 case CMD_GET_PREFERRED_NETWORK_TYPE:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700873 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800874 break;
875
876 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
877 ar = (AsyncResult) msg.obj;
878 request = (MainThreadRequest) ar.userObj;
879 if (ar.exception == null && ar.result != null) {
880 request.result = ar.result; // Integer
881 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530882 // request.result must be set to something non-null
883 // for the calling thread to unblock
884 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800885 if (ar.result == null) {
886 loge("getPreferredNetworkType: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getPreferredNetworkType: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getPreferredNetworkType: Unknown exception");
892 }
893 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 break;
896
897 case CMD_SET_PREFERRED_NETWORK_TYPE:
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
900 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700901 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 break;
903
904 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
905 handleNullReturnEvent(msg, "setPreferredNetworkType");
906 break;
907
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000908 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
909 request = (MainThreadRequest)msg.obj;
910 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000912 break;
913
914 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
915 ar = (AsyncResult)msg.obj;
916 request = (MainThreadRequest)ar.userObj;
917 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000919 break;
920
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800921 case CMD_SET_VOICEMAIL_NUMBER:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
924 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800925 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
926 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800927 break;
928
929 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
930 handleNullReturnEvent(msg, "setVoicemailNumber");
931 break;
932
Stuart Scott54788802015-03-30 13:18:01 -0700933 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
936 request);
937 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
938 break;
939
940 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
941 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
942 break;
943
Shishir Agrawal302c8692015-06-19 13:49:39 -0700944 case CMD_PERFORM_NETWORK_SCAN:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
947 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
948 break;
949
Hall Liua1acea22020-09-18 19:04:59 -0700950 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700953 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
954 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
955 request.argument;
956 int callForwardingReason = args.first;
957 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800958 break;
Hall Liua1acea22020-09-18 19:04:59 -0700959 }
960 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700963 TelephonyManager.CallForwardingInfoCallback callback =
964 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
965 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800966 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700967 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800968 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
969 for (CallForwardInfo callForwardInfo : callForwardInfos) {
970 // Service Class is a bit mask per 3gpp 27.007. Search for
971 // any service for voice call.
972 if ((callForwardInfo.serviceClass
973 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700974 callForwardingInfo = new CallForwardingInfo(true,
975 callForwardInfo.reason,
976 callForwardInfo.number,
977 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800978 break;
979 }
980 }
981 // Didn't find a call forward info for voice call.
982 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700983 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
984 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800985 }
Hall Liua1acea22020-09-18 19:04:59 -0700986 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800987 } else {
988 if (ar.result == null) {
989 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
990 }
991 if (ar.exception != null) {
992 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
993 }
Hall Liuae527aa2020-09-29 17:10:18 -0700994 int errorCode = TelephonyManager
995 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800996 if (ar.exception instanceof CommandException) {
997 CommandException.Error error =
998 ((CommandException) (ar.exception)).getCommandError();
999 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001000 errorCode = TelephonyManager
1001 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001002 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001003 errorCode = TelephonyManager
1004 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001005 }
1006 }
Hall Liua1acea22020-09-18 19:04:59 -07001007 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001008 }
sqian80370722020-01-29 15:02:51 -08001009 break;
Hall Liua1acea22020-09-18 19:04:59 -07001010 }
sqian80370722020-01-29 15:02:51 -08001011
Hall Liua1acea22020-09-18 19:04:59 -07001012 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001015 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001016 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001017 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1018 request.argument).first;
1019 request.phone.setCallForwardingOption(
1020 callForwardingInfoToSet.isEnabled()
1021 ? CommandsInterface.CF_ACTION_ENABLE
1022 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001023 callForwardingInfoToSet.getReason(),
1024 callForwardingInfoToSet.getNumber(),
1025 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1026 break;
Hall Liua1acea22020-09-18 19:04:59 -07001027 }
sqian80370722020-01-29 15:02:51 -08001028
Hall Liua1acea22020-09-18 19:04:59 -07001029 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001032 Consumer<Integer> callback =
1033 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1034 request.argument).second;
1035 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001036 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001037 int errorCode = TelephonyManager.CallForwardingInfoCallback
1038 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001039 if (ar.exception instanceof CommandException) {
1040 CommandException.Error error =
1041 ((CommandException) (ar.exception)).getCommandError();
1042 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001043 errorCode = TelephonyManager.CallForwardingInfoCallback
1044 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001045 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001046 errorCode = TelephonyManager.CallForwardingInfoCallback
1047 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001048 }
1049 }
1050 callback.accept(errorCode);
1051 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001052 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001053 }
sqian80370722020-01-29 15:02:51 -08001054 break;
Hall Liua1acea22020-09-18 19:04:59 -07001055 }
sqian80370722020-01-29 15:02:51 -08001056
Hall Liua1acea22020-09-18 19:04:59 -07001057 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001058 request = (MainThreadRequest) msg.obj;
1059 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1060 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1061 break;
Hall Liua1acea22020-09-18 19:04:59 -07001062 }
sqian80370722020-01-29 15:02:51 -08001063
Hall Liua1acea22020-09-18 19:04:59 -07001064 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001067 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001068 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1069 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001070 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001071 // Service Class is a bit mask per 3gpp 27.007.
1072 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001073 if (callForwardResults.length > 1
1074 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001075 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001076 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001077 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1078 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001079 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001080 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001081 }
1082 } else {
1083 if (ar.result == null) {
1084 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1085 }
1086 if (ar.exception != null) {
1087 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1088 }
1089 if (ar.exception instanceof CommandException) {
1090 CommandException.Error error =
1091 ((CommandException) (ar.exception)).getCommandError();
1092 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1093 callForwardingStatus =
1094 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1095 }
1096 }
1097 }
Hall Liua1acea22020-09-18 19:04:59 -07001098 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001099 break;
Hall Liua1acea22020-09-18 19:04:59 -07001100 }
sqian80370722020-01-29 15:02:51 -08001101
Hall Liua1acea22020-09-18 19:04:59 -07001102 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001103 request = (MainThreadRequest) msg.obj;
1104 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001105 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1106 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001107 break;
Hall Liua1acea22020-09-18 19:04:59 -07001108 }
sqian80370722020-01-29 15:02:51 -08001109
Hall Liua1acea22020-09-18 19:04:59 -07001110 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001113 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1114 Consumer<Integer> callback =
1115 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1116 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001117 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001118 if (ar.exception instanceof CommandException) {
1119 CommandException.Error error =
1120 ((CommandException) (ar.exception)).getCommandError();
1121 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1122 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1123 } else {
1124 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1125 }
1126 } else {
1127 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1128 }
1129 } else {
1130 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1131 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001132 }
sqian80370722020-01-29 15:02:51 -08001133 break;
Hall Liua1acea22020-09-18 19:04:59 -07001134 }
sqian80370722020-01-29 15:02:51 -08001135
Shishir Agrawal302c8692015-06-19 13:49:39 -07001136 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1137 ar = (AsyncResult) msg.obj;
1138 request = (MainThreadRequest) ar.userObj;
1139 CellNetworkScanResult cellScanResult;
1140 if (ar.exception == null && ar.result != null) {
1141 cellScanResult = new CellNetworkScanResult(
1142 CellNetworkScanResult.STATUS_SUCCESS,
1143 (List<OperatorInfo>) ar.result);
1144 } else {
1145 if (ar.result == null) {
1146 loge("getCellNetworkScanResults: Empty response");
1147 }
1148 if (ar.exception != null) {
1149 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1150 }
1151 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1152 if (ar.exception instanceof CommandException) {
1153 CommandException.Error error =
1154 ((CommandException) (ar.exception)).getCommandError();
1155 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1156 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1157 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1158 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1159 }
1160 }
1161 cellScanResult = new CellNetworkScanResult(errorCode, null);
1162 }
1163 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001164 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 break;
1166
1167 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1168 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001169 ManualNetworkSelectionArgument selArg =
1170 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001171 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1172 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001173 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1174 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001175 break;
1176
1177 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 loge("setNetworkSelectionModeManual " + ar.exception);
1185 }
1186 notifyRequester(request);
1187 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001188 break;
1189
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001190 case CMD_GET_MODEM_ACTIVITY_INFO:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001193 if (defaultPhone != null) {
1194 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001195 } else {
1196 ResultReceiver result = (ResultReceiver) request.argument;
1197 Bundle bundle = new Bundle();
1198 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1199 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1200 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001201 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001202 break;
1203
1204 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1205 ar = (AsyncResult) msg.obj;
1206 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001207 ResultReceiver result = (ResultReceiver) request.argument;
1208
1209 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001210 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001211 // Update the last modem activity info and the result of the request.
1212 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1213 if (isModemActivityInfoValid(info)) {
1214 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1215 int[] txTimeMs = info.getTransmitTimeMillis();
1216 int[] lastModemTxTimeMs = mLastModemActivityInfo
1217 .getTransmitTimeMillis();
1218 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1219 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1220 }
1221 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1222 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1223 + mLastModemActivityInfo.getSleepTimeMillis());
1224 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1225 + mLastModemActivityInfo.getIdleTimeMillis());
1226 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1227 mLastModemActivityInfo.setReceiveTimeMillis(
1228 info.getReceiveTimeMillis()
1229 + mLastModemActivityInfo.getReceiveTimeMillis());
1230 }
1231 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1232 mLastModemActivityInfo.getSleepTimeMillis(),
1233 mLastModemActivityInfo.getIdleTimeMillis(),
1234 mLastModemActivityInfo.getTransmitTimeMillis(),
1235 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 } else {
1237 if (ar.result == null) {
1238 loge("queryModemActivityInfo: Empty response");
1239 } else if (ar.exception instanceof CommandException) {
1240 loge("queryModemActivityInfo: CommandException: " +
1241 ar.exception);
1242 } else {
1243 loge("queryModemActivityInfo: Unknown exception");
1244 }
1245 }
sqian1a1be542020-03-05 11:37:28 -08001246 Bundle bundle = new Bundle();
1247 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1248 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001249 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001250 break;
1251
Meng Wang1a7c35a2016-05-05 20:56:15 -07001252 case CMD_SET_ALLOWED_CARRIERS:
1253 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001254 CarrierRestrictionRules argument =
1255 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001256 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001257 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001258 break;
1259
1260 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 if (ar.exception == null && ar.result != null) {
1264 request.result = ar.result;
1265 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001266 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1267 if (ar.exception instanceof CommandException) {
1268 loge("setAllowedCarriers: CommandException: " + ar.exception);
1269 CommandException.Error error =
1270 ((CommandException) (ar.exception)).getCommandError();
1271 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1272 request.result =
1273 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1274 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001275 } else {
1276 loge("setAllowedCarriers: Unknown exception");
1277 }
1278 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001279 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 break;
1281
1282 case CMD_GET_ALLOWED_CARRIERS:
1283 request = (MainThreadRequest) msg.obj;
1284 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001285 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 break;
1287
1288 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
1291 if (ar.exception == null && ar.result != null) {
1292 request.result = ar.result;
1293 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001294 request.result = new IllegalStateException(
1295 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001296 if (ar.result == null) {
1297 loge("getAllowedCarriers: Empty response");
1298 } else if (ar.exception instanceof CommandException) {
1299 loge("getAllowedCarriers: CommandException: " +
1300 ar.exception);
1301 } else {
1302 loge("getAllowedCarriers: Unknown exception");
1303 }
1304 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001305 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
Nathan Haroldb3014052017-01-25 15:57:32 -08001308 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null && ar.result != null) {
1312 request.result = ar.result;
1313 } else {
1314 request.result = new IllegalArgumentException(
1315 "Failed to retrieve Forbidden Plmns");
1316 if (ar.result == null) {
1317 loge("getForbiddenPlmns: Empty response");
1318 } else {
1319 loge("getForbiddenPlmns: Unknown exception");
1320 }
1321 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001323 break;
1324
1325 case CMD_GET_FORBIDDEN_PLMNS:
1326 request = (MainThreadRequest) msg.obj;
1327 uiccCard = getUiccCardFromRequest(request);
1328 if (uiccCard == null) {
1329 loge("getForbiddenPlmns() UiccCard is null");
1330 request.result = new IllegalArgumentException(
1331 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001332 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001333 break;
1334 }
1335 Integer appType = (Integer) request.argument;
1336 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1337 if (uiccApp == null) {
1338 loge("getForbiddenPlmns() no app with specified type -- "
1339 + appType);
1340 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001341 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001342 break;
1343 } else {
1344 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1345 + " specified type -- " + appType);
1346 }
1347 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1348 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1349 onCompleted);
1350 break;
1351
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001352 case CMD_SWITCH_SLOTS:
1353 request = (MainThreadRequest) msg.obj;
1354 int[] physicalSlots = (int[]) request.argument;
1355 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1356 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1357 break;
1358
1359 case EVENT_SWITCH_SLOTS_DONE:
1360 ar = (AsyncResult) msg.obj;
1361 request = (MainThreadRequest) ar.userObj;
1362 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
1364 break;
1365 case CMD_GET_NETWORK_SELECTION_MODE:
1366 request = (MainThreadRequest) msg.obj;
1367 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1368 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1369 break;
1370
1371 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1372 ar = (AsyncResult) msg.obj;
1373 request = (MainThreadRequest) ar.userObj;
1374 if (ar.exception != null) {
1375 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1376 } else {
1377 int mode = ((int[]) ar.result)[0];
1378 if (mode == 0) {
1379 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1380 } else {
1381 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1382 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001383 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001384 notifyRequester(request);
1385 break;
1386 case CMD_GET_CDMA_ROAMING_MODE:
1387 request = (MainThreadRequest) msg.obj;
1388 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1389 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1390 break;
1391 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 if (ar.exception != null) {
1395 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1396 } else {
1397 request.result = ((int[]) ar.result)[0];
1398 }
1399 notifyRequester(request);
1400 break;
1401 case CMD_SET_CDMA_ROAMING_MODE:
1402 request = (MainThreadRequest) msg.obj;
1403 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1404 int mode = (int) request.argument;
1405 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1406 break;
1407 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 request.result = ar.exception == null;
1411 notifyRequester(request);
1412 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001413 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1414 request = (MainThreadRequest) msg.obj;
1415 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1416 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1417 break;
1418 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception != null) {
1422 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1423 } else {
1424 request.result = ((int[]) ar.result)[0];
1425 }
1426 notifyRequester(request);
1427 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001428 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1429 request = (MainThreadRequest) msg.obj;
1430 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1431 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001432 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1433 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 break;
1435 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 request.result = ar.exception == null;
1439 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001440 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001441 case CMD_GET_ALL_CELL_INFO:
1442 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001443 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001444 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 case EVENT_GET_ALL_CELL_INFO_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001449 // If a timeout occurs, the response will be null
1450 request.result = (ar.exception == null && ar.result != null)
1451 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 synchronized (request) {
1453 request.notifyAll();
1454 }
1455 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001456 case CMD_REQUEST_CELL_INFO_UPDATE:
1457 request = (MainThreadRequest) msg.obj;
1458 request.phone.requestCellInfoUpdate(request.workSource,
1459 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1460 break;
1461 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1465 try {
1466 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001467 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001468 cb.onError(
1469 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1470 ar.exception.getClass().getName(),
1471 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001472 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001474 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001475 } else {
1476 // use the result as returned
1477 cb.onCellInfo((List<CellInfo>) ar.result);
1478 }
1479 } catch (RemoteException re) {
1480 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1481 }
1482 break;
Sarah Chincc055732020-11-18 13:39:35 -08001483 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 request = (MainThreadRequest) msg.obj;
1485 WorkSource ws = (WorkSource) request.argument;
1486 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001487 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 break;
Sarah Chincc055732020-11-18 13:39:35 -08001489 }
1490 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 ar = (AsyncResult) msg.obj;
1492 request = (MainThreadRequest) ar.userObj;
1493 if (ar.exception == null) {
1494 request.result = ar.result;
1495 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001496 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001498 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 }
1500
1501 synchronized (request) {
1502 request.notifyAll();
1503 }
1504 break;
Sarah Chincc055732020-11-18 13:39:35 -08001505 }
chen xu6dac5ab2018-10-26 17:39:23 -07001506 case CMD_MODEM_REBOOT:
1507 request = (MainThreadRequest) msg.obj;
1508 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001509 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001510 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001511 case EVENT_CMD_MODEM_REBOOT_DONE:
1512 handleNullReturnEvent(msg, "rebootModem");
1513 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001514 case CMD_REQUEST_ENABLE_MODEM:
1515 request = (MainThreadRequest) msg.obj;
1516 boolean enable = (boolean) request.argument;
1517 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001518 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001519 PhoneConfigurationManager.getInstance()
1520 .enablePhone(request.phone, enable, onCompleted);
1521 break;
1522 case EVENT_ENABLE_MODEM_DONE:
1523 ar = (AsyncResult) msg.obj;
1524 request = (MainThreadRequest) ar.userObj;
1525 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001526 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001527 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001528 if ((boolean) request.result) {
1529 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1530 updateModemStateMetrics();
1531 } else {
1532 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1533 + ar.exception);
1534 }
1535 notifyRequester(request);
1536 break;
1537 case CMD_GET_MODEM_STATUS:
1538 request = (MainThreadRequest) msg.obj;
1539 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1540 PhoneConfigurationManager.getInstance()
1541 .getPhoneStatusFromModem(request.phone, onCompleted);
1542 break;
1543 case EVENT_GET_MODEM_STATUS_DONE:
1544 ar = (AsyncResult) msg.obj;
1545 request = (MainThreadRequest) ar.userObj;
1546 int id = request.phone.getPhoneId();
1547 if (ar.exception == null && ar.result != null) {
1548 request.result = ar.result;
1549 //update the cache as modem status has changed
1550 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1551 (boolean) request.result);
1552 } else {
1553 // Return true if modem status cannot be retrieved. For most cases,
1554 // modem status is on. And for older version modems, GET_MODEM_STATUS
1555 // and disable modem are not supported. Modem is always on.
1556 // TODO: this should be fixed in R to support a third
1557 // status UNKNOWN b/131631629
1558 request.result = true;
1559 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1560 + ar.exception);
1561 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001562 notifyRequester(request);
1563 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001564 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1567 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1568 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1569 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1570 break;
1571 }
1572 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1576 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1577 args.second.accept(ar.exception == null);
1578 notifyRequester(request);
1579 break;
1580 }
Sarah Chincc055732020-11-18 13:39:35 -08001581 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1582 request = (MainThreadRequest) msg.obj;
1583 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1584 Phone phone = getPhoneFromRequest(request);
1585 if (phone != null) {
1586 phone.getSystemSelectionChannels(onCompleted);
1587 } else {
1588 loge("getSystemSelectionChannels: No phone object");
1589 request.result = new ArrayList<RadioAccessSpecifier>();
1590 notifyRequester(request);
1591 }
1592 break;
1593 }
1594 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 if (ar.exception == null && ar.result != null) {
1598 request.result = ar.result;
1599 } else {
1600 request.result = new IllegalArgumentException(
1601 "Failed to retrieve system selection channels");
1602 if (ar.result == null) {
1603 loge("getSystemSelectionChannels: Empty response");
1604 } else {
1605 loge("getSystemSelectionChannels: Unknown exception");
1606 }
1607 }
1608 notifyRequester(request);
1609 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001610 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception == null && ar.result != null) {
1614 request.result = ar.result;
1615 } else {
1616 request.result = -1;
1617 loge("Failed to set Forbidden Plmns");
1618 if (ar.result == null) {
1619 loge("setForbidenPlmns: Empty response");
1620 } else if (ar.exception != null) {
1621 loge("setForbiddenPlmns: Exception: " + ar.exception);
1622 request.result = -1;
1623 } else {
1624 loge("setForbiddenPlmns: Unknown exception");
1625 }
1626 }
1627 notifyRequester(request);
1628 break;
1629 case CMD_SET_FORBIDDEN_PLMNS:
1630 request = (MainThreadRequest) msg.obj;
1631 uiccCard = getUiccCardFromRequest(request);
1632 if (uiccCard == null) {
1633 loge("setForbiddenPlmns: UiccCard is null");
1634 request.result = -1;
1635 notifyRequester(request);
1636 break;
1637 }
1638 Pair<Integer, List<String>> setFplmnsArgs =
1639 (Pair<Integer, List<String>>) request.argument;
1640 appType = setFplmnsArgs.first;
1641 List<String> fplmns = setFplmnsArgs.second;
1642 uiccApp = uiccCard.getApplicationByType(appType);
1643 if (uiccApp == null) {
1644 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1645 request.result = -1;
1646 loge("Failed to get UICC App");
1647 notifyRequester(request);
1648 } else {
1649 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1650 ((SIMRecords) uiccApp.getIccRecords())
1651 .setForbiddenPlmns(onCompleted, fplmns);
1652 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001653 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001654 case CMD_ERASE_MODEM_CONFIG:
1655 request = (MainThreadRequest) msg.obj;
1656 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1657 defaultPhone.eraseModemConfig(onCompleted);
1658 break;
1659 case EVENT_ERASE_MODEM_CONFIG_DONE:
1660 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001661 break;
zoey chenf95ca592019-12-30 16:11:23 +08001662
1663 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1664 request = (MainThreadRequest) msg.obj;
1665 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1666 Pair<String, String> changed = (Pair<String, String>) request.argument;
1667 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1668 changed.first, changed.second, onCompleted);
1669 break;
1670 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1671 ar = (AsyncResult) msg.obj;
1672 request = (MainThreadRequest) ar.userObj;
1673 if (ar.exception == null) {
1674 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1675 } else {
1676 request.result = msg.arg1;
1677 }
1678 notifyRequester(request);
1679 break;
1680
1681 case CMD_SET_ICC_LOCK_ENABLED:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1684 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1685 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1686 enabled.first, enabled.second, onCompleted);
1687 break;
1688 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception == null) {
1692 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1693 } else {
1694 request.result = msg.arg1;
1695 }
1696 notifyRequester(request);
1697 break;
1698
Peter Wangdafb9ac2020-01-15 14:13:38 -08001699 case MSG_NOTIFY_USER_ACTIVITY:
1700 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001701 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001702 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1703 getDefaultPhone().getContext().sendBroadcastAsUser(
1704 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1705 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001706
1707 case CMD_SET_DATA_THROTTLING: {
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1710 DataThrottlingRequest dataThrottlingRequest =
1711 (DataThrottlingRequest) request.argument;
1712 Phone phone = getPhoneFromRequest(request);
1713 if (phone != null) {
1714 phone.setDataThrottling(onCompleted,
1715 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1716 dataThrottlingRequest.getCompletionDurationMillis());
1717 } else {
1718 loge("setDataThrottling: No phone object");
1719 request.result =
1720 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1721 notifyRequester(request);
1722 }
1723
1724 break;
1725 }
1726 case EVENT_SET_DATA_THROTTLING_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729
1730 if (ar.exception == null) {
1731 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1732 } else if (ar.exception instanceof CommandException) {
1733 loge("setDataThrottling: CommandException: " + ar.exception);
1734 CommandException.Error error =
1735 ((CommandException) (ar.exception)).getCommandError();
1736
1737 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1738 request.result = TelephonyManager
1739 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1740 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1741 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1742 } else {
1743 request.result =
1744 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1745 }
1746 } else {
1747 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1748 }
1749 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1750 notifyRequester(request);
1751 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001752
1753 case CMD_SET_SIM_POWER: {
1754 request = (MainThreadRequest) msg.obj;
1755 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1756 request = (MainThreadRequest) msg.obj;
1757 int stateToSet =
1758 ((Pair<Integer, IIntegerConsumer>)
1759 request.argument).first;
1760 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1761 break;
1762 }
1763 case EVENT_SET_SIM_POWER_DONE: {
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 IIntegerConsumer callback =
1767 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1768 if (ar.exception != null) {
1769 loge("setSimPower exception: " + ar.exception);
1770 int errorCode = TelephonyManager.CallForwardingInfoCallback
1771 .RESULT_ERROR_UNKNOWN;
1772 if (ar.exception instanceof CommandException) {
1773 CommandException.Error error =
1774 ((CommandException) (ar.exception)).getCommandError();
1775 if (error == CommandException.Error.SIM_ERR) {
1776 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1777 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1778 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1779 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1780 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1781 } else {
1782 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1783 }
1784 }
1785 try {
1786 callback.accept(errorCode);
1787 } catch (RemoteException e) {
1788 // Ignore if the remote process is no longer available to call back.
1789 Log.w(LOG_TAG, "setSimPower: callback not available.");
1790 }
1791 } else {
1792 try {
1793 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1794 } catch (RemoteException e) {
1795 // Ignore if the remote process is no longer available to call back.
1796 Log.w(LOG_TAG, "setSimPower: callback not available.");
1797 }
1798 }
1799 break;
1800 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001801 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1802 request = (MainThreadRequest) msg.obj;
1803
1804 final Phone phone = getPhoneFromRequest(request);
1805 if (phone == null || phone.getServiceStateTracker() == null) {
1806 request.result = new IllegalStateException("Phone or SST is null");
1807 notifyRequester(request);
1808 break;
1809 }
1810
1811 Pair<Integer, SignalStrengthUpdateRequest> pair =
1812 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1813 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1814 request);
1815 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1816 request.subId, pair.first /*callingUid*/,
1817 pair.second /*request*/, onCompleted);
1818 break;
1819 }
1820 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 // request.result will be the exception of ar if present, true otherwise.
1824 // Be cautious not to leave result null which will wait() forever
1825 request.result = ar.exception != null ? ar.exception : true;
1826 notifyRequester(request);
1827 break;
1828 }
1829 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1830 request = (MainThreadRequest) msg.obj;
1831
1832 Phone phone = getPhoneFromRequest(request);
1833 if (phone == null || phone.getServiceStateTracker() == null) {
1834 request.result = new IllegalStateException("Phone or SST is null");
1835 notifyRequester(request);
1836 break;
1837 }
1838
1839 Pair<Integer, SignalStrengthUpdateRequest> pair =
1840 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1841 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1842 request);
1843 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1844 request.subId, pair.first /*callingUid*/,
1845 pair.second /*request*/, onCompleted);
1846 break;
1847 }
1848 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1849 ar = (AsyncResult) msg.obj;
1850 request = (MainThreadRequest) ar.userObj;
1851 request.result = ar.exception != null ? ar.exception : true;
1852 notifyRequester(request);
1853 break;
1854 }
Jordan Liud5366d92020-11-24 14:50:34 -08001855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 default:
1857 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1858 break;
1859 }
1860 }
Jake Hambye994d462014-02-03 13:10:13 -08001861
Pengquan Menga1bb6272018-09-06 09:59:22 -07001862 private void notifyRequester(MainThreadRequest request) {
1863 synchronized (request) {
1864 request.notifyAll();
1865 }
1866 }
1867
Jake Hambye994d462014-02-03 13:10:13 -08001868 private void handleNullReturnEvent(Message msg, String command) {
1869 AsyncResult ar = (AsyncResult) msg.obj;
1870 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1871 if (ar.exception == null) {
1872 request.result = true;
1873 } else {
1874 request.result = false;
1875 if (ar.exception instanceof CommandException) {
1876 loge(command + ": CommandException: " + ar.exception);
1877 } else {
1878 loge(command + ": Unknown exception");
1879 }
1880 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001881 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
1885 /**
1886 * Posts the specified command to be executed on the main thread,
1887 * waits for the request to complete, and returns the result.
1888 * @see #sendRequestAsync
1889 */
1890 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001891 return sendRequest(
1892 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001893 }
1894
1895 /**
1896 * Posts the specified command to be executed on the main thread,
1897 * waits for the request to complete, and returns the result.
1898 * @see #sendRequestAsync
1899 */
1900 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1901 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001902 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001903 }
1904
1905 /**
1906 * Posts the specified command to be executed on the main thread,
1907 * waits for the request to complete, and returns the result.
1908 * @see #sendRequestAsync
1909 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001910 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001911 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001912 }
1913
1914 /**
1915 * Posts the specified command to be executed on the main thread,
1916 * waits for the request to complete, and returns the result.
1917 * @see #sendRequestAsync
1918 */
Nathan Harold92bed182018-10-12 18:16:49 -07001919 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1920 return sendRequest(command, argument, subId, null, workSource);
1921 }
1922
1923 /**
1924 * Posts the specified command to be executed on the main thread,
1925 * waits for the request to complete, and returns the result.
1926 * @see #sendRequestAsync
1927 */
1928 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1929 return sendRequest(
1930 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1931 }
1932
1933 /**
1934 * Posts the specified command to be executed on the main thread,
1935 * waits for the request to complete, and returns the result.
1936 * @see #sendRequestAsync
1937 */
1938 private Object sendRequest(
1939 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1941 throw new RuntimeException("This method will deadlock if called from the main thread.");
1942 }
1943
Nathan Harold92bed182018-10-12 18:16:49 -07001944 MainThreadRequest request = null;
1945 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1946 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1947 } else if (phone != null) {
1948 request = new MainThreadRequest(argument, phone, workSource);
1949 } else {
1950 request = new MainThreadRequest(argument, subId, workSource);
1951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 Message msg = mMainThreadHandler.obtainMessage(command, request);
1954 msg.sendToTarget();
1955
1956 // Wait for the request to complete
1957 synchronized (request) {
1958 while (request.result == null) {
1959 try {
1960 request.wait();
1961 } catch (InterruptedException e) {
1962 // Do nothing, go back and wait until the request is complete
1963 }
1964 }
1965 }
1966 return request.result;
1967 }
1968
1969 /**
1970 * Asynchronous ("fire and forget") version of sendRequest():
1971 * Posts the specified command to be executed on the main thread, and
1972 * returns immediately.
1973 * @see #sendRequest
1974 */
1975 private void sendRequestAsync(int command) {
1976 mMainThreadHandler.sendEmptyMessage(command);
1977 }
1978
1979 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001980 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001981 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001982 */
1983 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001984 sendRequestAsync(command, argument, null, null);
1985 }
1986
1987 /**
1988 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1989 * @see {@link #sendRequest(int,Object)}
1990 */
1991 private void sendRequestAsync(
1992 int command, Object argument, Phone phone, WorkSource workSource) {
1993 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001994 Message msg = mMainThreadHandler.obtainMessage(command, request);
1995 msg.sendToTarget();
1996 }
1997
1998 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 * Initialize the singleton PhoneInterfaceManager instance.
2000 * This is only done once, at startup, from PhoneApp.onCreate().
2001 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002002 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 synchronized (PhoneInterfaceManager.class) {
2004 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002005 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 } else {
2007 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2008 }
2009 return sInstance;
2010 }
2011 }
2012
2013 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002014 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002017 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002018 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2020 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002021 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002022 mTelephonySharedPreferences =
2023 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002024 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002025 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002026 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002027
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 publish();
2029 }
2030
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002031 private Phone getDefaultPhone() {
2032 Phone thePhone = getPhone(getDefaultSubscription());
2033 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2034 }
2035
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 private void publish() {
2037 if (DBG) log("publish: " + this);
2038
Peter Wangc035ce42020-01-08 21:00:22 -08002039 TelephonyFrameworkInitializer
2040 .getTelephonyServiceManager()
2041 .getTelephonyServiceRegisterer()
2042 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 }
2044
Stuart Scott584921c2015-01-15 17:10:34 -08002045 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002046 if (request.phone != null) {
2047 return request.phone;
2048 } else {
2049 return getPhoneFromSubId(request.subId);
2050 }
2051 }
2052
2053 private Phone getPhoneFromSubId(int subId) {
2054 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2055 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002056 }
2057
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002058 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2059 Phone phone = getPhoneFromRequest(request);
2060 return phone == null ? null :
2061 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2062 }
2063
Wink Saville36469e72014-06-11 15:17:00 -07002064 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002066 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002069 private void sendEraseModemConfig(Phone phone) {
2070 if (phone != null) {
2071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2072 mApp, phone.getSubId(), "eraseModemConfig");
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2076 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2077 } finally {
2078 Binder.restoreCallingIdentity(identity);
2079 }
2080 }
2081 }
2082
Peter Wang050bb052020-01-13 23:33:09 -08002083 private boolean isImsAvailableOnDevice() {
2084 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2085 if (pm == null) {
2086 // For some reason package manger is not available.. This will fail internally anyway,
2087 // so do not throw error and allow.
2088 return true;
2089 }
2090 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2091 }
2092
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Wink Savilleb564aae2014-10-23 10:18:09 -07002097 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 if (DBG) log("dial: " + number);
2099 // No permission check needed here: This is just a wrapper around the
2100 // ACTION_DIAL intent, which is available to any app since it puts up
2101 // the UI before it does anything.
2102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 String url = createTelUrl(number);
2106 if (url == null) {
2107 return;
2108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110 // PENDING: should we just silently fail if phone is offhook or ringing?
2111 PhoneConstants.State state = mCM.getState(subId);
2112 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2113 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2115 mApp.startActivity(intent);
2116 }
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120 }
2121
2122 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002123 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002124 }
2125
Wink Savilleb564aae2014-10-23 10:18:09 -07002126 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 if (DBG) log("call: " + number);
2128
2129 // This is just a wrapper around the ACTION_CALL intent, but we still
2130 // need to do a permission check since we're calling startActivity()
2131 // from the context of the phone app.
2132 enforceCallPermission();
2133
Jordan Liu1617b712019-07-10 15:06:26 -07002134 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 != AppOpsManager.MODE_ALLOWED) {
2136 return;
2137 }
2138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 String url = createTelUrl(number);
2142 if (url == null) {
2143 return;
2144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002146 boolean isValid = false;
2147 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2148 if (slist != null) {
2149 for (SubscriptionInfo subInfoRecord : slist) {
2150 if (subInfoRecord.getSubscriptionId() == subId) {
2151 isValid = true;
2152 break;
2153 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002154 }
Wink Saville08874612014-08-31 19:19:58 -07002155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 if (!isValid) {
2157 return;
2158 }
Wink Saville08874612014-08-31 19:19:58 -07002159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2161 intent.putExtra(SUBSCRIPTION_KEY, subId);
2162 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2163 mApp.startActivity(intent);
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002170 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002171 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2172 }
2173
Wink Savilleb564aae2014-10-23 10:18:09 -07002174 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002175 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002176 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2177 }
2178
Wink Savilleb564aae2014-10-23 10:18:09 -07002179 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2185 checkSimPin.start();
2186 return checkSimPin.unlockSim(null, pin);
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
Wink Savilleb564aae2014-10-23 10:18:09 -07002192 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2198 checkSimPuk.start();
2199 return checkSimPuk.unlockSim(puk, pin);
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
2205 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002206 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 * a synchronous one.
2208 */
2209 private static class UnlockSim extends Thread {
2210
2211 private final IccCard mSimCard;
2212
2213 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002214 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2215 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216
2217 // For replies from SimCard interface
2218 private Handler mHandler;
2219
2220 // For async handler to identify request type
2221 private static final int SUPPLY_PIN_COMPLETE = 100;
2222
2223 public UnlockSim(IccCard simCard) {
2224 mSimCard = simCard;
2225 }
2226
2227 @Override
2228 public void run() {
2229 Looper.prepare();
2230 synchronized (UnlockSim.this) {
2231 mHandler = new Handler() {
2232 @Override
2233 public void handleMessage(Message msg) {
2234 AsyncResult ar = (AsyncResult) msg.obj;
2235 switch (msg.what) {
2236 case SUPPLY_PIN_COMPLETE:
2237 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2238 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002239 mRetryCount = msg.arg1;
2240 if (ar.exception != null) {
2241 if (ar.exception instanceof CommandException &&
2242 ((CommandException)(ar.exception)).getCommandError()
2243 == CommandException.Error.PASSWORD_INCORRECT) {
2244 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002245 } //When UiccCardApp dispose,handle message and return exception
2246 else if (ar.exception instanceof CommandException &&
2247 ((CommandException) (ar.exception)).getCommandError()
2248 == CommandException.Error.ABORTED) {
2249 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002250 } else {
2251 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2252 }
2253 } else {
2254 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 mDone = true;
2257 UnlockSim.this.notifyAll();
2258 }
2259 break;
2260 }
2261 }
2262 };
2263 UnlockSim.this.notifyAll();
2264 }
2265 Looper.loop();
2266 }
2267
2268 /*
2269 * Use PIN or PUK to unlock SIM card
2270 *
2271 * If PUK is null, unlock SIM card with PIN
2272 *
2273 * If PUK is not null, unlock SIM card with PUK and set PIN code
2274 */
Wink Saville9de0f752013-10-22 19:04:03 -07002275 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276
2277 while (mHandler == null) {
2278 try {
2279 wait();
2280 } catch (InterruptedException e) {
2281 Thread.currentThread().interrupt();
2282 }
2283 }
2284 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2285
2286 if (puk == null) {
2287 mSimCard.supplyPin(pin, callback);
2288 } else {
2289 mSimCard.supplyPuk(puk, pin, callback);
2290 }
2291
2292 while (!mDone) {
2293 try {
2294 Log.d(LOG_TAG, "wait for done");
2295 wait();
2296 } catch (InterruptedException e) {
2297 // Restore the interrupted status
2298 Thread.currentThread().interrupt();
2299 }
2300 }
2301 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002302 int[] resultArray = new int[2];
2303 resultArray[0] = mResult;
2304 resultArray[1] = mRetryCount;
2305 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307 }
2308
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002309 /**
2310 * This method has been removed due to privacy and stability concerns.
2311 */
2312 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002314 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2315 return;
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Nathan Harold1f889d82020-06-04 17:05:26 -07002318 @Override
2319 public void updateServiceLocationWithPackageName(String callingPackage) {
2320 mApp.getSystemService(AppOpsManager.class)
2321 .checkPackage(Binder.getCallingUid(), callingPackage);
2322
Nathan Haroldf096d982020-11-18 17:18:06 -08002323 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002324 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2325 // Callers targeting S have no business invoking this method.
2326 return;
2327 }
2328
2329 LocationAccessPolicy.LocationPermissionResult locationResult =
2330 LocationAccessPolicy.checkLocationPermission(mApp,
2331 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2332 .setCallingPackage(callingPackage)
2333 .setCallingFeatureId(null)
2334 .setCallingPid(Binder.getCallingPid())
2335 .setCallingUid(Binder.getCallingUid())
2336 .setMethod("updateServiceLocation")
2337 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2338 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2339 .build());
2340 // Apps that lack location permission have no business calling this method;
2341 // however, because no permission was declared in the public API, denials must
2342 // all be "soft".
2343 switch (locationResult) {
2344 case DENIED_HARD: /* fall through */
2345 case DENIED_SOFT:
2346 return;
2347 }
2348
2349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002352 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002354 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002361 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002362 @Override
2363 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002364 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002367
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002368 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002369 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2370 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2371 callingFeatureId);
2372 }
2373
2374 @Deprecated
2375 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002377 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2378 }
2379
2380 @Override
2381 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2382 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002384 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 return false;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 return isRadioOnForSubscriber(subId);
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002394 }
2395
2396 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 if (phone != null) {
2401 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2402 } else {
2403 return false;
2404 }
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
2410 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
Wink Saville36469e72014-06-11 15:17:00 -07002413
Wink Savilleb564aae2014-10-23 10:18:09 -07002414 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 final Phone phone = getPhone(subId);
2420 if (phone != null) {
2421 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002425 }
Wink Saville36469e72014-06-11 15:17:00 -07002426 }
2427
2428 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 final Phone phone = getPhone(subId);
2438 if (phone == null) {
2439 return false;
2440 }
2441 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2442 toggleRadioOnOffForSubscriber(subId);
2443 }
2444 return true;
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
Wink Saville36469e72014-06-11 15:17:00 -07002449
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002450 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002451 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002452 /*
2453 * If any of the Radios are available, it will need to be
2454 * shutdown. So return true if any Radio is available.
2455 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2459 Phone phone = PhoneFactory.getPhone(i);
2460 if (phone != null && phone.isRadioAvailable()) return true;
2461 }
2462 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2463 return false;
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002466 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002467 }
2468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002470 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 enforceModifyPermission();
2472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2476 logv("Shutting down Phone " + i);
2477 shutdownRadioUsingPhoneId(i);
2478 }
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002481 }
2482 }
2483
2484 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002485 Phone phone = PhoneFactory.getPhone(phoneId);
2486 if (phone != null && phone.isRadioAvailable()) {
2487 phone.shutdownRadio();
2488 }
2489 }
2490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2497 if (defaultPhone != null) {
2498 defaultPhone.setRadioPower(turnOn);
2499 return true;
2500 } else {
2501 loge("There's no default phone.");
2502 return false;
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002506 }
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone != null) {
2516 phone.setRadioPower(turnOn);
2517 return true;
2518 } else {
2519 return false;
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Wink Saville36469e72014-06-11 15:17:00 -07002526 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 public boolean enableDataConnectivity() {
2529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 int subId = mSubscriptionController.getDefaultDataSubId();
2534 final Phone phone = getPhone(subId);
2535 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002536 phone.getDataEnabledSettings().setDataEnabled(
2537 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 return true;
2539 } else {
2540 return false;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
Wink Saville36469e72014-06-11 15:17:00 -07002547 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 public boolean disableDataConnectivity() {
2550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551
2552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 int subId = mSubscriptionController.getDefaultDataSubId();
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002557 phone.getDataEnabledSettings().setDataEnabled(
2558 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 return true;
2560 } else {
2561 return false;
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
Sanket Padawe356d7632015-06-22 14:03:32 -07002568 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002569 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002574 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 } else {
2576 return false;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002584 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
pkanwarae03a6b2016-11-06 20:37:09 -08002587 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 enforceCallPermission();
2589
2590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2593 return;
2594 }
2595 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2596 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
2599 }
pkanwar32d516d2016-10-14 19:37:38 -07002600 };
2601
Wink Savilleb564aae2014-10-23 10:18:09 -07002602 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2608 return false;
2609 }
2610 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002617 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002618 }
2619
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002620 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 Phone phone = PhoneFactory.getPhone(slotIndex);
2624 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2625 PhoneConstantConversions.convertCallState(phone.getState());
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
2628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002632 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002633 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2634 }
2635
2636 @Override
2637 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002640 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 if (phone != null) {
2642 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2643 } else {
2644 return PhoneConstantConversions.convertDataState(
2645 PhoneConstants.DataState.DISCONNECTED);
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002653 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002654 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2655 }
2656
2657 @Override
2658 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002661 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 if (phone != null) {
2663 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2664 } else {
2665 return TelephonyManager.DATA_ACTIVITY_NONE;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002673 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002674 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002675 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002676
2677 LocationAccessPolicy.LocationPermissionResult locationResult =
2678 LocationAccessPolicy.checkLocationPermission(mApp,
2679 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2680 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002681 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002682 .setCallingPid(Binder.getCallingPid())
2683 .setCallingUid(Binder.getCallingUid())
2684 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002685 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002686 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2687 .build());
2688 switch (locationResult) {
2689 case DENIED_HARD:
2690 throw new SecurityException("Not allowed to access cell location");
2691 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002692 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2693 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002696 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002700 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002701 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 } finally {
2703 Binder.restoreCallingIdentity(identity);
2704 }
Svetoslav64fad262015-04-14 14:35:21 -07002705 }
2706
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 @Override
Jack Yu01425032020-02-22 19:38:58 -08002708 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002709 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2710 // registered cell info, so return a NULL country instead.
2711 final long identity = Binder.clearCallingIdentity();
2712 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002713 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2714 // Get default phone in this case.
2715 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2716 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002717 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002719 if (phone == null) return "";
2720 ServiceStateTracker sst = phone.getServiceStateTracker();
2721 if (sst == null) return "";
2722 LocaleTracker lt = sst.getLocaleTracker();
2723 if (lt == null) return "";
2724 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2725 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2726 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002730 }
2731
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002732 /**
2733 * This method was removed due to potential issues caused by performing partial
2734 * updates of service state, and lack of a credible use case.
2735 *
2736 * This has the ability to break the telephony implementation by disabling notification of
2737 * changes in device connectivity. DO NOT USE THIS!
2738 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002739 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 public void enableLocationUpdates() {
2741 mApp.enforceCallingOrSelfPermission(
2742 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002745 /**
2746 * This method was removed due to potential issues caused by performing partial
2747 * updates of service state, and lack of a credible use case.
2748 *
2749 * This has the ability to break the telephony implementation by disabling notification of
2750 * changes in device connectivity. DO NOT USE THIS!
2751 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 @Override
2753 public void disableLocationUpdates() {
2754 mApp.enforceCallingOrSelfPermission(
2755 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
2758 @Override
2759 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002760 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2761 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002762 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002763 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2764 throw new SecurityException(
2765 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2766 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002767
Jordan Liu1617b712019-07-10 15:06:26 -07002768 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2770 return null;
2771 }
Svetoslav64fad262015-04-14 14:35:21 -07002772
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002773 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002775 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002776 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777
Nathan Haroldf180aac2018-06-01 18:43:55 -07002778 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2779 for (CellInfo ci : info) {
2780 if (ci instanceof CellInfoGsm) {
2781 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2782 } else if (ci instanceof CellInfoWcdma) {
2783 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002786 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002789 private List<CellInfo> getCachedCellInfo() {
2790 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2791 for (Phone phone : PhoneFactory.getPhones()) {
2792 List<CellInfo> info = phone.getAllCellInfo();
2793 if (info != null) cellInfos.addAll(info);
2794 }
2795 return cellInfos;
2796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797
2798 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002799 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002800 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002801 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002802
2803 LocationAccessPolicy.LocationPermissionResult locationResult =
2804 LocationAccessPolicy.checkLocationPermission(mApp,
2805 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2806 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002807 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002808 .setCallingPid(Binder.getCallingPid())
2809 .setCallingUid(Binder.getCallingUid())
2810 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002811 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002812 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2813 .build());
2814 switch (locationResult) {
2815 case DENIED_HARD:
2816 throw new SecurityException("Not allowed to access cell info");
2817 case DENIED_SOFT:
2818 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
Nathan Haroldf096d982020-11-18 17:18:06 -08002821 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002822 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2823 return getCachedCellInfo();
2824 }
2825
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002826 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2831 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002832 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002833 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 if (info != null) cellInfos.addAll(info);
2835 }
2836 return cellInfos;
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840 }
2841
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002842 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2844 String callingFeatureId) {
2845 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2846 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002847 }
2848
2849 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002850 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2851 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002852 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002853 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002854 }
2855
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002856 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2857 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002858 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002859 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002860
2861 LocationAccessPolicy.LocationPermissionResult locationResult =
2862 LocationAccessPolicy.checkLocationPermission(mApp,
2863 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2864 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002865 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002866 .setCallingPid(Binder.getCallingPid())
2867 .setCallingUid(Binder.getCallingUid())
2868 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002869 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2870 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002871 .build());
2872 switch (locationResult) {
2873 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002874 if (TelephonyPermissions
2875 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002876 // Safetynet logging for b/154934934
2877 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2878 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002879 throw new SecurityException("Not allowed to access cell info");
2880 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002881 if (TelephonyPermissions
2882 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002883 // Safetynet logging for b/154934934
2884 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2885 }
Nathan Harold5320c422019-05-09 10:26:08 -07002886 try {
2887 cb.onCellInfo(new ArrayList<CellInfo>());
2888 } catch (RemoteException re) {
2889 // Drop without consequences
2890 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002891 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002892 }
2893
Nathan Harolda939a962019-05-09 10:13:47 -07002894
2895 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002896 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2897
2898 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2899 }
2900
2901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002903 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002904 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Shishir Agrawala9f32182016-04-12 12:00:16 -07002914 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002915 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002916 Phone phone = PhoneFactory.getPhone(slotIndex);
2917 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 return null;
2919 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002920 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002921 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002922 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002923 return null;
2924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 return phone.getImei();
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002932 }
2933
2934 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002935 public String getTypeAllocationCodeForSlot(int slotIndex) {
2936 Phone phone = PhoneFactory.getPhone(slotIndex);
2937 String tac = null;
2938 if (phone != null) {
2939 String imei = phone.getImei();
2940 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2941 }
2942 return tac;
2943 }
2944
2945 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002947 Phone phone = PhoneFactory.getPhone(slotIndex);
2948 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002949 return null;
2950 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951
Jeff Davidson913390f2018-02-23 17:11:49 -08002952 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002953 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002954 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002955 return null;
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 return phone.getMeid();
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
Jack Yu2af8d712017-03-15 17:14:14 -07002964 }
2965
2966 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002967 public String getManufacturerCodeForSlot(int slotIndex) {
2968 Phone phone = PhoneFactory.getPhone(slotIndex);
2969 String manufacturerCode = null;
2970 if (phone != null) {
2971 String meid = phone.getMeid();
2972 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2973 }
2974 return manufacturerCode;
2975 }
2976
2977 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002978 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2979 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002980 Phone phone = PhoneFactory.getPhone(slotIndex);
2981 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002982 return null;
2983 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002984 int subId = phone.getSubId();
2985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002986 mApp, subId, callingPackage, callingFeatureId,
2987 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002988 return null;
2989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 return phone.getDeviceSvn();
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002997 }
2998
fionaxu43304da2017-11-27 22:51:16 -08002999 @Override
3000 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 final Phone phone = getPhone(subId);
3004 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
fionaxu43304da2017-11-27 22:51:16 -08003008 }
3009
3010 @Override
3011 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 final Phone phone = getPhone(subId);
3015 return phone == null ? null : phone.getCarrierName();
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
fionaxu43304da2017-11-27 22:51:16 -08003019 }
3020
calvinpanffe225e2018-11-01 19:43:06 +08003021 @Override
chen xu0026ca62019-03-06 15:28:50 -08003022 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 final Phone phone = getPhone(subId);
3026 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003027 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
chen xu0026ca62019-03-06 15:28:50 -08003034 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003038 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
chen xu651eec72018-11-11 19:03:44 -08003044 @Override
chen xu864e11c2018-12-06 22:10:03 -08003045 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3046 if (!isSubscriptionMccMnc) {
3047 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3048 }
chen xu651eec72018-11-11 19:03:44 -08003049 final Phone phone = PhoneFactory.getPhone(slotIndex);
3050 if (phone == null) {
3051 return TelephonyManager.UNKNOWN_CARRIER_ID;
3052 }
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 //
3062 // Internal helper methods.
3063 //
3064
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003065 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3067 *
3068 * @throws SecurityException if the caller does not have the required permission
3069 */
3070 private void enforceModifyPermission() {
3071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3072 }
3073
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003074 /**
3075 * Make sure the caller is system.
3076 *
3077 * @throws SecurityException if the caller is not system.
3078 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003079 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003080 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3081 throw new SecurityException("Caller must be system");
3082 }
3083 }
3084
Shuo Qianf2b2df42019-11-13 17:43:31 -08003085 private void enforceActiveEmergencySessionPermission() {
3086 mApp.enforceCallingOrSelfPermission(
3087 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3088 }
3089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 /**
3091 * Make sure the caller has the CALL_PHONE permission.
3092 *
3093 * @throws SecurityException if the caller does not have the required permission
3094 */
3095 private void enforceCallPermission() {
3096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3097 }
3098
paulhu423b5f22019-08-23 19:17:33 +08003099 private void enforceSettingsPermission() {
3100 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003101 }
3102
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 private String createTelUrl(String number) {
3104 if (TextUtils.isEmpty(number)) {
3105 return null;
3106 }
3107
Jake Hambye994d462014-02-03 13:10:13 -08003108 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Ihab Awadf9e92732013-12-05 18:02:52 -08003111 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3113 }
3114
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003115 private static void logv(String msg) {
3116 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3117 }
3118
Ihab Awadf9e92732013-12-05 18:02:52 -08003119 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3121 }
3122
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003123 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003125 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003126 }
3127
Sanket Padawe356d7632015-06-22 14:03:32 -07003128 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003129 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 final Phone phone = PhoneFactory.getPhone(slotIndex);
3133 if (phone == null) {
3134 return PhoneConstants.PHONE_TYPE_NONE;
3135 } else {
3136 return phone.getPhoneType();
3137 }
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
3143 /**
3144 * Returns the CDMA ERI icon index to display
3145 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003146 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003147 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3148 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3149 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003150 }
3151
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003153 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3154 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003156 mApp, subId, callingPackage, callingFeatureId,
3157 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003158 return -1;
3159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160
3161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 if (phone != null) {
3165 return phone.getCdmaEriIconIndex();
3166 } else {
3167 return -1;
3168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 /**
3175 * Returns the CDMA ERI icon mode,
3176 * 0 - ON
3177 * 1 - FLASHING
3178 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003179 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003180 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3181 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3182 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003183 }
3184
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003186 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3187 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003189 mApp, subId, callingPackage, callingFeatureId,
3190 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003191 return -1;
3192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
3197 if (phone != null) {
3198 return phone.getCdmaEriIconMode();
3199 } else {
3200 return -1;
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206
3207 /**
3208 * Returns the CDMA ERI text,
3209 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003210 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003211 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3212 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3213 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003214 }
3215
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003217 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3218 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003220 mApp, subId, callingPackage, callingFeatureId,
3221 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003222 return null;
3223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = getPhone(subId);
3228 if (phone != null) {
3229 return phone.getCdmaEriText();
3230 } else {
3231 return null;
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
3238 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003239 * Returns the CDMA MDN.
3240 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003242 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3244 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 return phone.getLine1Number();
3251 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 return null;
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003257 }
3258 }
3259
3260 /**
3261 * Returns the CDMA MIN.
3262 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003264 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3266 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 final Phone phone = getPhone(subId);
3271 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3272 return phone.getCdmaMin();
3273 } else {
3274 return null;
3275 }
3276 } finally {
3277 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003278 }
3279 }
3280
Hall Liud892bec2018-11-30 14:51:45 -08003281 @Override
3282 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3283 INumberVerificationCallback callback, String callingPackage) {
3284 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3285 != PERMISSION_GRANTED) {
3286 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3287 }
3288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3289
3290 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3291 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003292 throw new SecurityException("Calling package must be configured in the device config: "
3293 + "calling package: " + callingPackage
3294 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003295 }
3296
3297 if (range == null) {
3298 throw new NullPointerException("Range must be non-null");
3299 }
3300
3301 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003302 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003303
3304 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3305 }
3306
Junda Liuca05d5d2014-08-14 22:36:34 -07003307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 * Returns true if CDMA provisioning needs to run.
3309 */
3310 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
3318
3319 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003320 * Sets the voice mail number of a given subId.
3321 */
3322 @Override
3323 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003324 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3325 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3330 new Pair<String, String>(alphaTag, number), new Integer(subId));
3331 return success;
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003335 }
3336
Ta-wei Yen87c49842016-05-13 21:19:52 -07003337 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003338 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003340 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3341 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003342 if (!TextUtils.equals(callingPackage, systemDialer)) {
3343 throw new SecurityException("caller must be system dialer");
3344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3349 if (phoneAccountHandle == null) {
3350 return null;
3351 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003355 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003356 }
3357
3358 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003359 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3360 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003363 mApp, subId, callingPackage, callingFeatureId,
3364 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003365 return null;
3366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003368 final long identity = Binder.clearCallingIdentity();
3369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003370 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003374 }
3375
3376 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003377 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3378 VisualVoicemailSmsFilterSettings settings) {
3379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003384 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003388 }
3389
3390 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003391 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003401 }
3402
3403 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003404 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3405 String callingPackage, int subId) {
3406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003411 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003415 }
3416
3417 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003418 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003419 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003428 }
3429
3430 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003431 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3432 String callingAttributionTag, int subId, String number, int port, String text,
3433 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003435 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003436 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003437 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003438 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3439 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003440 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003441
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003442 /**
fionaxu0152e512016-11-14 13:36:14 -08003443 * Sets the voice activation state of a given subId.
3444 */
3445 @Override
3446 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3448 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449
3450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 final Phone phone = getPhone(subId);
3453 if (phone != null) {
3454 phone.setVoiceActivationState(activationState);
3455 } else {
3456 loge("setVoiceActivationState fails with invalid subId: " + subId);
3457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003460 }
3461 }
3462
3463 /**
3464 * Sets the data activation state of a given subId.
3465 */
3466 @Override
3467 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3469 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 final Phone phone = getPhone(subId);
3474 if (phone != null) {
3475 phone.setDataActivationState(activationState);
3476 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003477 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003481 }
3482 }
3483
3484 /**
3485 * Returns the voice activation state of a given subId.
3486 */
3487 @Override
3488 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
fionaxu0152e512016-11-14 13:36:14 -08003491 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 if (phone != null) {
3495 return phone.getVoiceActivationState();
3496 } else {
3497 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3498 }
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003501 }
3502 }
3503
3504 /**
3505 * Returns the data activation state of a given subId.
3506 */
3507 @Override
3508 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510
fionaxu0152e512016-11-14 13:36:14 -08003511 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 if (phone != null) {
3515 return phone.getDataActivationState();
3516 } else {
3517 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003521 }
3522 }
3523
3524 /**
Wink Saville36469e72014-06-11 15:17:00 -07003525 * Returns the unread count of voicemails for a subId
3526 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003527 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003528 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3529 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003531 mApp, subId, callingPackage, callingFeatureId,
3532 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003533 return 0;
3534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = getPhone(subId);
3538 if (phone != null) {
3539 return phone.getVoiceMessageCount();
3540 } else {
3541 return 0;
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003549 * returns true, if the device is in a state where both voice and data
3550 * are supported simultaneously. This can change based on location or network condition.
3551 */
3552 @Override
3553 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 final Phone phone = getPhone(subId);
3557 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003561 }
3562
3563 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003564 * Send the dialer code if called from the current default dialer or the caller has
3565 * carrier privilege.
3566 * @param inputCode The dialer code to send
3567 */
3568 @Override
3569 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003572 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3573 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003574 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
fionaxu235cc5e2017-03-06 22:25:57 -08003585 }
3586
Pengquan Menga1bb6272018-09-06 09:59:22 -07003587 @Override
3588 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003589 TelephonyPermissions
3590 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3591 mApp, subId, "getNetworkSelectionMode");
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 if (!isActiveSubscription(subId)) {
3595 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3596 }
3597 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003601 }
3602
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003604 public boolean isInEmergencySmsMode() {
3605 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 for (Phone phone : PhoneFactory.getPhones()) {
3609 if (phone.isInEmergencySmsMode()) {
3610 return true;
3611 }
3612 }
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 return false;
3617 }
3618
shilu366312e2019-12-17 09:28:10 -08003619 /**
3620 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3621 * @param subId The subscription to use to check the configuration.
3622 * @param c The callback that will be used to send the result.
3623 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003624 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003625 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3626 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003627 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3628 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003629
Brad Ebinger77b832e2019-10-17 17:03:22 -07003630 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3632 "IMS not available on device.");
3633 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 final long token = Binder.clearCallingIdentity();
3635 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (ImsException e) {
3640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 } finally {
3642 Binder.restoreCallingIdentity(token);
3643 }
3644 }
3645
shilu366312e2019-12-17 09:28:10 -08003646 /**
3647 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3648 * @param subId The subscription to use to check the configuration.
3649 * @param c The callback that will be used to send the result.
3650 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003651 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003652 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003653 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3654 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3657 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003658 final long token = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3661 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3662 .removeRegistrationCallbackForSubscription(c, subId);
3663 } catch (ImsException e) {
3664 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3665 + "is inactive, ignoring unregister.");
3666 // If the subscription is no longer active, just return, since the callback
3667 // will already have been removed internally.
3668 } finally {
3669 Binder.restoreCallingIdentity(token);
3670 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 }
3672
Brad Ebinger774ba362019-10-22 17:36:18 -07003673 /**
3674 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3675 */
3676 @Override
3677 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3678 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3679 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3681 "IMS not available on device.");
3682 }
3683 final long token = Binder.clearCallingIdentity();
3684 try {
3685 Phone phone = getPhone(subId);
3686 if (phone == null) {
3687 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3688 + subId + "'");
3689 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3690 }
3691 phone.getImsRegistrationState(regState -> {
3692 try {
3693 consumer.accept((regState == null)
3694 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3695 } catch (RemoteException e) {
3696 // Ignore if the remote process is no longer available to call back.
3697 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3698 }
3699 });
3700 } finally {
3701 Binder.restoreCallingIdentity(token);
3702 }
3703 }
3704
3705 /**
3706 * Get the transport type for the IMS service registration state.
3707 */
3708 @Override
3709 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003710 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3711 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003712 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3713 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3714 "IMS not available on device.");
3715 }
3716 final long token = Binder.clearCallingIdentity();
3717 try {
3718 Phone phone = getPhone(subId);
3719 if (phone == null) {
3720 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3721 + subId + "'");
3722 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3723 }
3724 phone.getImsRegistrationTech(regTech -> {
3725 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3726 int regTechConverted = (regTech == null)
3727 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3728 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3729 regTechConverted);
3730 try {
3731 consumer.accept(regTechConverted);
3732 } catch (RemoteException e) {
3733 // Ignore if the remote process is no longer available to call back.
3734 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3735 }
3736 });
3737 } finally {
3738 Binder.restoreCallingIdentity(token);
3739 }
3740 }
3741
shilu366312e2019-12-17 09:28:10 -08003742 /**
3743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3744 * @param subId The subscription to use to check the configuration.
3745 * @param c The callback that will be used to send the result.
3746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003748 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3749 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003750 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3751 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003752 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3753 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3754 "IMS not available on device.");
3755 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3757 final long token = Binder.clearCallingIdentity();
3758 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003759 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003761 } catch (ImsException e) {
3762 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
3766 }
3767
shilu366312e2019-12-17 09:28:10 -08003768 /**
3769 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3770 * @param subId The subscription to use to check the configuration.
3771 * @param c The callback that will be used to send the result.
3772 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003774 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003775 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3776 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3778 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3779 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003780
3781 final long token = Binder.clearCallingIdentity();
3782 try {
3783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3784 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003785 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003786 } catch (ImsException e) {
3787 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3788 + "is inactive, ignoring unregister.");
3789 // If the subscription is no longer active, just return, since the callback
3790 // will already have been removed internally.
3791 } finally {
3792 Binder.restoreCallingIdentity(token);
3793 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 }
3795
3796 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003797 public boolean isCapable(int subId, int capability, int regTech) {
3798 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3800 final long token = Binder.clearCallingIdentity();
3801 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003803 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003804 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003805 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3806 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003807 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003808 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3809 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 } finally {
3811 Binder.restoreCallingIdentity(token);
3812 }
3813 }
3814
3815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003816 public boolean isAvailable(int subId, int capability, int regTech) {
3817 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 final long token = Binder.clearCallingIdentity();
3819 try {
3820 Phone phone = getPhone(subId);
3821 if (phone == null) return false;
3822 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003823 } catch (com.android.ims.ImsException e) {
3824 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3825 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 } finally {
3827 Binder.restoreCallingIdentity(token);
3828 }
3829 }
3830
Brad Ebinger77b832e2019-10-17 17:03:22 -07003831 /**
3832 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3833 * subscription.
3834 * @param subId The subscription to use to check the configuration.
3835 * @param callback The callback that will be used to send the result.
3836 * @param capability The MmTelFeature capability that will be used to send the result.
3837 * @param transportType The transport type of the MmTelFeature capability.
3838 */
3839 @Override
3840 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3841 int transportType) {
3842 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3843 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3844 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3845 "IMS not available on device.");
3846 }
3847 final long token = Binder.clearCallingIdentity();
3848 try {
3849 int slotId = getSlotIndex(subId);
3850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3851 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3852 + subId + "'");
3853 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3854 }
3855 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3856 transportType, aBoolean -> {
3857 try {
3858 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3859 } catch (RemoteException e) {
3860 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3861 + "running. Ignore");
3862 }
3863 });
3864 } finally {
3865 Binder.restoreCallingIdentity(token);
3866 }
3867 }
3868
shilu366312e2019-12-17 09:28:10 -08003869 /**
3870 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3871 * @param subId The subscription to use to check the configuration.
3872 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 @Override
3874 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003875 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3876 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003877
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3879 final long token = Binder.clearCallingIdentity();
3880 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003881 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003883 } catch (ImsException e) {
3884 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 } finally {
3886 Binder.restoreCallingIdentity(token);
3887 }
3888 }
3889
3890 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003891 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003893 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003899 } catch (ImsException e) {
3900 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
3904 }
3905
shilu366312e2019-12-17 09:28:10 -08003906 /**
3907 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3908 * @param subId The subscription to use to check the configuration.
3909 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003911 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003912 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3913 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3918 } catch (ImsException e) {
3919 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
3923 }
3924
3925 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003926 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003928 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003932 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003933 } catch (ImsException e) {
3934 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
3938 }
3939
shilu366312e2019-12-17 09:28:10 -08003940 /**
3941 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3942 * @param subId The subscription to use to check the configuration.
3943 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 @Override
3945 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003946 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3947 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003953 } catch (ImsException e) {
3954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
3960 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003961 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003963 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003968 } catch (ImsException e) {
3969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
3973 }
3974
shilu366312e2019-12-17 09:28:10 -08003975 /**
3976 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3977 * @param subId The subscription to use to check the configuration.
3978 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 @Override
3980 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003981 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3982 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
3993 }
3994
3995 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003996 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003998 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004002 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004004 } catch (ImsException e) {
4005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
4011 @Override
4012 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4014 "setVoWiFiNonPersistent");
4015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004019 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 } catch (ImsException e) {
4021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 }
4026
shilu366312e2019-12-17 09:28:10 -08004027 /**
4028 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4029 * @param subId The subscription to use to check the configuration.
4030 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 @Override
4032 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4034 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004038 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 @Override
4048 public void setVoWiFiModeSetting(int subId, int mode) {
4049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4050 "setVoWiFiModeSetting");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
4057 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
4063 @Override
4064 public int getVoWiFiRoamingModeSetting(int subId) {
4065 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004069 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004071 } catch (ImsException e) {
4072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
4076 }
4077
4078 @Override
4079 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4081 "setVoWiFiRoamingModeSetting");
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004087 } catch (ImsException e) {
4088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
4092 }
4093
4094 @Override
4095 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4097 "setRttCapabilityEnabled");
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4102 } catch (ImsException e) {
4103 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
4107 }
4108
shilu366312e2019-12-17 09:28:10 -08004109 /**
4110 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4111 * @param subId The subscription to use to check the configuration.
4112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 @Override
4114 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004115 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4116 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004122 } catch (ImsException e) {
4123 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
4127 }
4128
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004129 @Override
4130 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4131 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4132 final long identity = Binder.clearCallingIdentity();
4133 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004134 if (!isImsAvailableOnDevice()) {
4135 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4136 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004137 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004140 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (ImsException e) {
4142 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
4146 }
4147
4148 @Override
4149 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4150 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4151 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004152 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4153 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4154 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004158 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004160 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4161 + "is inactive, ignoring unregister.");
4162 // If the subscription is no longer active, just return, since the callback will already
4163 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
allenwtsu99c623b2020-01-03 18:24:23 +08004169
4170 private void checkModifyPhoneStatePermission(int subId, String message) {
4171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4172 message);
4173 }
4174
4175 private boolean isImsProvisioningRequired(int subId, int capability,
4176 boolean isMmtelCapability) {
4177 Phone phone = getPhone(subId);
4178 if (phone == null) {
4179 loge("phone instance null for subid " + subId);
4180 return false;
4181 }
4182 if (isMmtelCapability) {
4183 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4184 return false;
4185 }
4186 } else {
4187 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4188 return false;
4189 }
4190 }
4191 return true;
4192 }
4193
4194 @Override
4195 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4196 boolean isProvisioned) {
4197 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4198
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4202 if (!isImsProvisioningRequired(subId, capability, false)) {
4203 return;
4204 }
4205
4206 // this capability requires provisioning, route to the correct API.
4207 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4208 switch (capability) {
4209 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4210 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4211 ims.setEabProvisioned(isProvisioned);
4212 break;
4213 default: {
4214 throw new IllegalArgumentException("Tried to set provisioning for "
4215 + "rcs capability '" + capability + "', which does not require "
4216 + "provisioning.");
4217 }
4218 }
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222
4223 }
4224
4225
4226 @Override
4227 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4228 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4232 if (!isImsProvisioningRequired(subId, capability, false)) {
4233 return true;
4234 }
4235
4236 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4237 switch (capability) {
4238 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4239 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4240 return ims.isEabProvisionedOnDevice();
4241
4242 default: {
4243 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4244 + "capability '" + capability + "', which does not require "
4245 + "provisioning.");
4246 }
4247 }
4248
4249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
4252 }
4253
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004254 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004255 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4256 boolean isProvisioned) {
4257 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4258 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4259 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4260 }
allenwtsu99c623b2020-01-03 18:24:23 +08004261 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004265 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004266 return;
4267 }
4268
4269 // this capability requires provisioning, route to the correct API.
4270 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4271 switch (capability) {
4272 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4273 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4274 ims.setVolteProvisioned(isProvisioned);
4275 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4276 ims.setWfcProvisioned(isProvisioned);
4277 }
4278 break;
4279 }
4280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4281 // There is currently no difference in VT provisioning type.
4282 ims.setVtProvisioned(isProvisioned);
4283 break;
4284 }
4285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4286 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4287 // change the capability of the feature instead if needed.
4288 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4289 == isProvisioned) {
4290 // No change in provisioning.
4291 return;
4292 }
4293 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4294 try {
4295 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004297 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4298 + ", Exception" + e.getMessage());
4299 }
4300 break;
4301 }
4302 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004303 throw new IllegalArgumentException("Tried to set provisioning for "
4304 + "MmTel capability '" + capability + "', which does not require "
4305 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004306 }
4307 }
4308
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
4312 }
4313
4314 @Override
4315 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4316 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4317 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4318 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4319 }
4320 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4321 final long identity = Binder.clearCallingIdentity();
4322 try {
4323 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004324 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004325 return true;
4326 }
4327
4328 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4329 switch (capability) {
4330 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4331 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4332 return ims.isVolteProvisionedOnDevice();
4333 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4334 return ims.isWfcProvisionedOnDevice();
4335 }
4336 // This should never happen, since we are checking tech above to make sure it
4337 // is either LTE or IWLAN.
4338 throw new IllegalArgumentException("Invalid radio technology for voice "
4339 + "capability.");
4340 }
4341 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4342 // There is currently no difference in VT provisioning type.
4343 return ims.isVtProvisionedOnDevice();
4344 }
4345 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4346 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4347 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4348 }
4349 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004350 throw new IllegalArgumentException(
4351 "Tried to get provisioning for MmTel capability '" + capability
4352 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 }
4354 }
4355
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
4361 @Override
4362 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4363 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4364 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4365 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4366 }
4367 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4368 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4369 return (provisionedBits & capability) > 0;
4370 }
4371
4372 @Override
4373 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4374 boolean isProvisioned) {
4375 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4376 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4377 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4378 }
4379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4380 "setProvisioningStatusForCapability");
4381 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4382 // If the current provisioning status for capability already matches isProvisioned,
4383 // do nothing.
4384 if (((provisionedBits & capability) > 0) == isProvisioned) {
4385 return;
4386 }
4387 if (isProvisioned) {
4388 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4389 } else {
4390 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4391 }
4392 }
4393
4394 /**
4395 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4396 * technology. The bitfield should mirror the bitfield defined by
4397 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4398 */
4399 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4400 String key = getMmTelProvisioningKey(subId, tech);
4401 // Default is no capabilities are provisioned.
4402 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4403 }
4404
4405 /**
4406 * Sets the MmTel capability provisioning bitfield (defined by
4407 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4408 * technology specified.
4409 *
4410 * Note: This is a synchronous command and should not be called on UI thread.
4411 */
4412 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4413 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4414 String key = getMmTelProvisioningKey(subId, tech);
4415 editor.putInt(key, newField);
4416 editor.commit();
4417 }
4418
4419 private static String getMmTelProvisioningKey(int subId, int tech) {
4420 // resulting key is provision_ims_mmtel_{subId}_{tech}
4421 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4422 }
4423
4424 /**
4425 * Query CarrierConfig to see if the specified capability requires provisioning for the
4426 * carrier associated with the subscription id.
4427 */
4428 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4429 int capability) {
4430 CarrierConfigManager configManager = new CarrierConfigManager(context);
4431 PersistableBundle c = configManager.getConfigForSubId(subId);
4432 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004433 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004434 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4435 false);
4436 boolean requireVoiceVtProvisioning = c.getBoolean(
4437 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4438
4439 // First check to make sure that the capability requires provisioning.
4440 switch (capability) {
4441 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4442 // intentional fallthrough
4443 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4444 if (requireVoiceVtProvisioning) {
4445 // Voice and Video requires provisioning
4446 return true;
4447 }
4448 break;
4449 }
4450 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4451 if (requireUtProvisioning) {
4452 // UT requires provisioning
4453 return true;
4454 }
4455 break;
4456 }
4457 }
4458 return false;
4459 }
4460
allenwtsu99c623b2020-01-03 18:24:23 +08004461 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4462 int capability) {
4463 CarrierConfigManager configManager = new CarrierConfigManager(context);
4464 PersistableBundle c = configManager.getConfigForSubId(subId);
4465
4466 boolean requireRcsProvisioning = c.getBoolean(
4467 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4468
4469 // First check to make sure that the capability requires provisioning.
4470 switch (capability) {
4471 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4472 // intentional fallthrough
4473 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4474 if (requireRcsProvisioning) {
4475 // OPTION or PRESENCE requires provisioning
4476 return true;
4477 }
4478 break;
4479 }
4480 }
4481 return false;
4482 }
4483
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004484 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004485 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004486 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4487 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4488 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004489 enforceReadPrivilegedPermission("getImsProvisioningInt");
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
4492 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004493 int slotId = getSlotIndex(subId);
4494 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4495 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4496 + subId + "' for key:" + key);
4497 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4498 }
4499 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004500 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004501 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4502 + subId + "' for key:" + key);
4503 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
4509 @Override
4510 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004511 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4512 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4513 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004514 enforceReadPrivilegedPermission("getImsProvisioningString");
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 int slotId = getSlotIndex(subId);
4519 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4520 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4521 + subId + "' for key:" + key);
4522 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4523 }
4524 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004526 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4527 + subId + "' for key:" + key);
4528 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004536 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4537 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4538 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4540 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 final long identity = Binder.clearCallingIdentity();
4542 try {
4543 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004544 int slotId = getSlotIndex(subId);
4545 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4546 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4547 + subId + "' for key:" + key);
4548 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4549 }
4550 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004551 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004552 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4553 + "' for key:" + key);
4554 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
4558 }
4559
4560 @Override
4561 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4563 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4564 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4566 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004567 final long identity = Binder.clearCallingIdentity();
4568 try {
4569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 int slotId = getSlotIndex(subId);
4571 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4572 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4573 + subId + "' for key:" + key);
4574 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4575 }
4576 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004577 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004578 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4579 + "' for key:" + key);
4580 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584 }
4585
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 int slotId = SubscriptionManager.getSlotIndex(subId);
4588 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004589 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4590 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 }
4592 return slotId;
4593 }
4594
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004595 private int getSlotIndex(int subId) {
4596 int slotId = SubscriptionManager.getSlotIndex(subId);
4597 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4598 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4599 }
4600 return slotId;
4601 }
4602
Wink Saville36469e72014-06-11 15:17:00 -07004603 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004604 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004605 */
4606 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004607 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4608 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004609 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004610 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004611 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004612 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004613 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004614 mApp, subId, callingPackage, callingFeatureId,
4615 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004616 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4617 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 final long identity = Binder.clearCallingIdentity();
4620 try {
4621 final Phone phone = getPhone(subId);
4622 if (phone != null) {
4623 return phone.getServiceState().getDataNetworkType();
4624 } else {
4625 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4626 }
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004630 }
4631
4632 /**
4633 * Returns the data network type
4634 */
4635 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004636 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4637 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4638 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004639 }
4640
4641 /**
4642 * Returns the data network type for a subId
4643 */
4644 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004645 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4646 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004648 mApp, subId, callingPackage, callingFeatureId,
4649 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004650 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4651 }
4652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 final Phone phone = getPhone(subId);
4656 if (phone != null) {
4657 return phone.getServiceState().getDataNetworkType();
4658 } else {
4659 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4660 }
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004664 }
4665
4666 /**
Wink Saville36469e72014-06-11 15:17:00 -07004667 * Returns the Voice network type for a subId
4668 */
4669 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004670 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4671 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004673 mApp, subId, callingPackage, callingFeatureId,
4674 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004675 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4676 }
4677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 final Phone phone = getPhone(subId);
4681 if (phone != null) {
4682 return phone.getServiceState().getVoiceNetworkType();
4683 } else {
4684 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4685 }
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004689 }
4690
4691 /**
4692 * @return true if a ICC card is present
4693 */
4694 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004695 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004696 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4697 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004698 }
4699
4700 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004701 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004702 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004703 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004704 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 final Phone phone = PhoneFactory.getPhone(slotIndex);
4708 if (phone != null) {
4709 return phone.getIccCard().hasIccCard();
4710 } else {
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004716 }
4717
4718 /**
4719 * Return if the current radio is LTE on CDMA. This
4720 * is a tri-state return value as for a period of time
4721 * the mode may be unknown.
4722 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004723 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004724 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004725 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004726 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004727 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004728 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4729 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4730 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004731 }
4732
Sanket Padawe356d7632015-06-22 14:03:32 -07004733 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004734 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4735 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004736 try {
4737 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4738 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004739 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4740 }
4741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 final Phone phone = getPhone(subId);
4745 if (phone == null) {
4746 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4747 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004748 return TelephonyProperties.lte_on_cdma_device()
4749 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004753 }
Wink Saville36469e72014-06-11 15:17:00 -07004754 }
4755
Wink Saville36469e72014-06-11 15:17:00 -07004756 /**
4757 * {@hide}
4758 * Returns Default subId, 0 in the case of single standby.
4759 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004760 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004761 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004762 }
4763
Shishir Agrawala9f32182016-04-12 12:00:16 -07004764 private int getSlotForDefaultSubscription() {
4765 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4766 }
4767
Wink Savilleb564aae2014-10-23 10:18:09 -07004768 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004769 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004770 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004771
Pengquan Menge92a50d2018-09-21 15:54:48 -07004772 private boolean isActiveSubscription(int subId) {
4773 return mSubscriptionController.isActiveSubId(subId);
4774 }
4775
Ihab Awadf2177b72013-11-25 13:33:23 -08004776 /**
4777 * @see android.telephony.TelephonyManager.WifiCallingChoices
4778 */
4779 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 final long identity = Binder.clearCallingIdentity();
4781 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004782 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4784 getWhenToMakeWifiCallsDefaultPreference());
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004788 }
4789
4790 /**
4791 * @see android.telephony.TelephonyManager.WifiCallingChoices
4792 */
4793 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004797 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004802 }
4803
Sailesh Nepald1e68152013-12-12 19:08:02 -08004804 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004805 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004806 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004807 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004808
Jordan Liu4c733742019-02-28 12:03:40 -08004809 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4810 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4811 if (phoneId == -1) {
4812 throw new IllegalArgumentException("Given slot index: " + slotIndex
4813 + " does not correspond to an active phone");
4814 }
4815 return PhoneFactory.getPhone(phoneId);
4816 }
4817
Shishir Agrawal566b7612013-10-28 14:41:00 -07004818 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004819 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4820 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4822 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004824 if (DBG) {
4825 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4826 }
4827 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4828 p2);
4829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004830
Jordan Liu4c733742019-02-28 12:03:40 -08004831
4832 @Override
4833 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4834 int slotIndex, String callingPackage, String aid, int p2) {
4835 enforceModifyPermission();
4836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4837 if (DBG) {
4838 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4839 }
4840 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4841 callingPackage, aid, p2);
4842 }
4843
4844 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4845 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 if (TextUtils.equals(ISDR_AID, aid)) {
4849 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004850 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4851 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 if (bestComponent == null
4853 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4854 loge("The calling package is not allowed to access ISD-R.");
4855 throw new SecurityException(
4856 "The calling package is not allowed to access ISD-R.");
4857 }
Derek Tan740e1672017-06-27 14:56:27 -07004858 }
Derek Tan740e1672017-06-27 14:56:27 -07004859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004861 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4862 null /* workSource */);
4863 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 return response;
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004868 }
4869
4870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004871 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004874 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4875 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4876 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004877
Jordan Liu4c733742019-02-28 12:03:40 -08004878 @Override
4879 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4880 enforceModifyPermission();
4881 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4882 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4883 channel);
4884 }
4885
4886 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 if (channel < 0) {
4890 return false;
4891 }
Jordan Liu4c733742019-02-28 12:03:40 -08004892 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4893 null /* workSource */);
4894 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 return success;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004898 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004899 }
4900
4901 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004902 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004903 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004906 if (DBG) {
4907 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4908 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4909 + p3 + " data=" + data);
4910 }
4911 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4912 command, p1, p2, p3, data);
4913 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004914
Jordan Liu4c733742019-02-28 12:03:40 -08004915 @Override
4916 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4917 int command, int p1, int p2, int p3, String data) {
4918 enforceModifyPermission();
4919 if (DBG) {
4920 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4921 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4922 + p3 + " data=" + data);
4923 }
4924 return iccTransmitApduLogicalChannelWithPermission(
4925 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4926 data);
4927 }
4928
4929 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4930 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004933 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 return "";
4935 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004938 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4939 null /* workSource */);
4940 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 // Append the returned status code to the end of the response payload.
4943 String s = Integer.toHexString(
4944 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4945 if (response.payload != null) {
4946 s = IccUtils.bytesToHexString(response.payload) + s;
4947 }
4948 return s;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004951 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004952 }
Jake Hambye994d462014-02-03 13:10:13 -08004953
Evan Charltonc66da362014-05-16 14:06:40 -07004954 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004955 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4956 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4958 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004960 if (DBG) {
4961 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4962 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4963 }
4964 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4965 cla, command, p1, p2, p3, data);
4966 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004967
Jordan Liu4c733742019-02-28 12:03:40 -08004968 @Override
4969 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4970 int command, int p1, int p2, int p3, String data) {
4971 enforceModifyPermission();
4972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4973 if (DBG) {
4974 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4975 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4976 + " data=" + data);
4977 }
4978
4979 return iccTransmitApduBasicChannelWithPermission(
4980 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4981 p2, p3, data);
4982 }
4983
4984 // open APDU basic channel assuming the caller has sufficient permissions
4985 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4986 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4990 && TextUtils.equals(ISDR_AID, data)) {
4991 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004992 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4993 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 if (bestComponent == null
4995 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4996 loge("The calling package is not allowed to select ISD-R.");
4997 throw new SecurityException(
4998 "The calling package is not allowed to select ISD-R.");
4999 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005000 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005003 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5004 null /* workSource */);
5005 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 // Append the returned status code to the end of the response payload.
5008 String s = Integer.toHexString(
5009 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5010 if (response.payload != null) {
5011 s = IccUtils.bytesToHexString(response.payload) + s;
5012 }
5013 return s;
5014 } finally {
5015 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005016 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005017 }
5018
5019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005020 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005021 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 if (DBG) {
5028 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5029 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5030 }
5031
5032 IccIoResult response =
5033 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5034 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5035 subId);
5036
5037 if (DBG) {
5038 log("Exchange SIM_IO [R]" + response);
5039 }
5040
5041 byte[] result = null;
5042 int length = 2;
5043 if (response.payload != null) {
5044 length = 2 + response.payload.length;
5045 result = new byte[length];
5046 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5047 } else {
5048 result = new byte[length];
5049 }
5050
5051 result[length - 1] = (byte) response.sw2;
5052 result[length - 2] = (byte) response.sw1;
5053 return result;
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005056 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005057 }
5058
Nathan Haroldb3014052017-01-25 15:57:32 -08005059 /**
5060 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5061 * on a particular subscription
5062 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005063 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5064 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005066 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005067 return null;
5068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 if (appType != TelephonyManager.APPTYPE_USIM
5073 && appType != TelephonyManager.APPTYPE_SIM) {
5074 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5075 return null;
5076 }
5077 Object response = sendRequest(
5078 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5079 if (response instanceof String[]) {
5080 return (String[]) response;
5081 }
yincheng zhaod698b842019-09-06 17:06:54 -07005082 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005084 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005087 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005088 }
5089
yincheng zhaod698b842019-09-06 17:06:54 -07005090 /**
5091 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5092 * subscription.
5093 *
5094 * @param subId the id of the subscription.
5095 * @param appType the uicc app type, must be USIM or SIM.
5096 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5097 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005098 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005099 * @return number of fplmns that is successfully written to the SIM.
5100 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005101 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5102 String callingFeatureId) {
5103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5104 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005105 if (DBG) logv("no permissions for setForbiddenplmns");
5106 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5107 }
5108 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5109 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5110 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5111 }
5112 if (fplmns == null) {
5113 throw new IllegalArgumentException("Fplmn List provided is null");
5114 }
5115 for (String fplmn : fplmns) {
5116 if (!CellIdentity.isValidPlmn(fplmn)) {
5117 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5118 }
5119 }
5120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 Object response = sendRequest(
5123 CMD_SET_FORBIDDEN_PLMNS,
5124 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5125 subId);
5126 return (int) response;
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
5130 }
5131
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005133 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5135 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
5139 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5140 if (response.payload == null) {
5141 return "";
5142 }
Evan Charltonc66da362014-05-16 14:06:40 -07005143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 // Append the returned status code to the end of the response payload.
5145 String s = Integer.toHexString(
5146 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5147 s = IccUtils.bytesToHexString(response.payload) + s;
5148 return s;
5149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
Evan Charltonc66da362014-05-16 14:06:40 -07005152 }
5153
Jake Hambye994d462014-02-03 13:10:13 -08005154 /**
5155 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5156 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5157 *
5158 * @param itemID the ID of the item to read
5159 * @return the NV item as a String, or null on error.
5160 */
5161 @Override
5162 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5165 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005170 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5172 return value;
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Jake Hambye994d462014-02-03 13:10:13 -08005176 }
5177
5178 /**
5179 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5180 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5181 *
5182 * @param itemID the ID of the item to read
5183 * @param itemValue the value to write, as a String
5184 * @return true on success; false on any failure
5185 */
5186 @Override
5187 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5195 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005196 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5198 return success;
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Jake Hambye994d462014-02-03 13:10:13 -08005202 }
5203
5204 /**
5205 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5206 * Used for device configuration by some CDMA operators.
5207 *
5208 * @param preferredRoamingList byte array containing the new PRL
5209 * @return true on success; false on any failure
5210 */
5211 @Override
5212 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5214 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215
5216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5219 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5220 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5221 return success;
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Jake Hambye994d462014-02-03 13:10:13 -08005225 }
5226
5227 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005228 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005229 * Used for device configuration by some CDMA operators.
5230 *
chen xu6dac5ab2018-10-26 17:39:23 -07005231 * @param slotIndex - device slot.
5232 *
Jake Hambye994d462014-02-03 13:10:13 -08005233 * @return true on success; false on any failure
5234 */
5235 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005236 public boolean resetModemConfig(int slotIndex) {
5237 Phone phone = PhoneFactory.getPhone(slotIndex);
5238 if (phone != null) {
5239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5240 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241
chen xu6dac5ab2018-10-26 17:39:23 -07005242 final long identity = Binder.clearCallingIdentity();
5243 try {
5244 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5245 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5246 return success;
5247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 }
chen xu6dac5ab2018-10-26 17:39:23 -07005251 return false;
5252 }
5253
5254 /**
5255 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5256 *
5257 * @param slotIndex - device slot.
5258 *
5259 * @return true on success; false on any failure
5260 */
5261 @Override
5262 public boolean rebootModem(int slotIndex) {
5263 Phone phone = PhoneFactory.getPhone(slotIndex);
5264 if (phone != null) {
5265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, phone.getSubId(), "rebootModem");
5267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5271 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5272 return success;
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005278 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005279
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005280 public String[] getPcscfAddress(String apnType, String callingPackage,
5281 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5284 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005285 return new String[0];
5286 }
5287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
5289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005290 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Wink Saville36469e72014-06-11 15:17:00 -07005294 }
5295
Brad Ebinger51f743a2017-01-23 13:50:20 -08005296 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005297 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5298 * {@link #disableIms(int)}.
5299 * @param slotIndex device slot.
5300 */
5301 public void resetIms(int slotIndex) {
5302 enforceModifyPermission();
5303
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 if (mImsResolver == null) {
5307 // may happen if the does not support IMS.
5308 return;
5309 }
5310 mImsResolver.disableIms(slotIndex);
5311 mImsResolver.enableIms(slotIndex);
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
5315 }
5316
5317 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005318 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5319 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005320 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005321 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005322 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005326 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005327 // may happen if the device does not support IMS.
5328 return;
5329 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005330 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005334 }
5335
5336 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005337 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5338 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005339 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005340 public void disableIms(int slotId) {
5341 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005345 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005346 // may happen if the device does not support IMS.
5347 return;
5348 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005349 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005353 }
5354
5355 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005356 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5357 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005358 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005359 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005360 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362
5363 final long identity = Binder.clearCallingIdentity();
5364 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005365 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5367 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005368 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005369 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005373 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005374 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005375 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5376 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005377 @Override
5378 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005379 enforceModifyPermission();
5380
5381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005384 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
5388 }
5389
5390 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005391 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005392 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005393 */
5394 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5395 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396
5397 final long identity = Binder.clearCallingIdentity();
5398 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005399 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005400 // may happen if the device does not support IMS.
5401 return null;
5402 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005403 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005407 }
5408
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005409 /**
5410 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005411 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005412 */
5413 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5414 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415
5416 final long identity = Binder.clearCallingIdentity();
5417 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005418 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005419 // may happen if the device does not support IMS.
5420 return null;
5421 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005422 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005426 }
5427
Brad Ebinger884c07b2018-02-15 16:17:40 -08005428 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005429 * Sets the ImsService Package Name that Telephony will bind to.
5430 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005431 * @param slotIndex the slot ID that the ImsService should bind for.
5432 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005433 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 * @param featureTypes An integer array of feature types associated with a packageName.
5435 * @param packageName The name of the package that the current configuration will be replaced
5436 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005437 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005438 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005439 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5440 int[] featureTypes, String packageName) {
5441 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5442 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5444 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005445 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005449 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005450 // may happen if the device does not support IMS.
5451 return false;
5452 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005453 Map<Integer, String> featureConfig = new HashMap<>();
5454 for (int featureType : featureTypes) {
5455 featureConfig.put(featureType, packageName);
5456 }
5457 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5458 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005462 }
5463
5464 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005465 * Clears any carrier ImsService overrides for the slot index specified that were previously
5466 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5467 *
5468 * This should only be used for testing.
5469 *
5470 * @param slotIndex the slot ID that the ImsService should bind for.
5471 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5472 */
5473 @Override
5474 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5475 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5476 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5477 "clearCarrierImsServiceOverride");
5478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5479 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5480 "clearCarrierImsServiceOverride");
5481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 if (mImsResolver == null) {
5485 // may happen if the device does not support IMS.
5486 return false;
5487 }
5488 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
5492 }
5493
5494 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005495 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005496 *
5497 * @param slotId The slot that the ImsService is associated with.
5498 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5499 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005500 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005501 * @return the package name of the ImsService configuration.
5502 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005503 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5504 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005505 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005506 TelephonyPermissions
5507 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5508 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5509 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 final long identity = Binder.clearCallingIdentity();
5512 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005514 // may happen if the device does not support IMS.
5515 return "";
5516 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005517 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5519 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005523 }
5524
Brad Ebinger77b832e2019-10-17 17:03:22 -07005525 /**
5526 * Get the MmTelFeature state associated with the requested subscription id.
5527 * @param subId The subscription that the MmTelFeature is associated with.
5528 * @param callback A callback with an integer containing the
5529 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5530 */
5531 @Override
5532 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5533 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5534 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5536 "IMS not available on device.");
5537 }
5538 final long token = Binder.clearCallingIdentity();
5539 try {
5540 int slotId = getSlotIndex(subId);
5541 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5542 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5543 + subId + "'");
5544 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5545 }
5546 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5547 try {
5548 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5549 } catch (RemoteException e) {
5550 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5551 + "Ignore");
5552 }
5553 });
5554 } finally {
5555 Binder.restoreCallingIdentity(token);
5556 }
5557 }
5558
Wink Saville36469e72014-06-11 15:17:00 -07005559 public void setImsRegistrationState(boolean registered) {
5560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Wink Saville36469e72014-06-11 15:17:00 -07005568 }
5569
5570 /**
Stuart Scott54788802015-03-30 13:18:01 -07005571 * Set the network selection mode to automatic.
5572 *
5573 */
5574 @Override
5575 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
shilufc958392020-01-20 11:36:01 -08005581 if (!isActiveSubscription(subId)) {
5582 return;
5583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5585 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Stuart Scott54788802015-03-30 13:18:01 -07005589 }
5590
Jack Yud10cdd42020-09-28 20:28:01 -07005591 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005592 * Ask the radio to connect to the input network and change selection mode to manual.
5593 *
5594 * @param subId the id of the subscription.
5595 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5596 * the operator to attach to.
5597 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5598 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5599 * normal network selection next time.
5600 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005601 */
5602 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005603 public boolean setNetworkSelectionModeManual(
5604 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005607
5608 if (!isActiveSubscription(subId)) {
5609 return false;
5610 }
5611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005614 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005616 if (DBG) {
5617 log("setNetworkSelectionModeManual: subId: " + subId
5618 + " operator: " + operatorInfo);
5619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005624 }
shilu84f6e8b2019-12-19 13:58:01 -08005625 /**
5626 * Get the manual network selection
5627 *
5628 * @param subId the id of the subscription.
5629 *
5630 * @return the previously saved user selected PLMN
5631 */
5632 @Override
5633 public String getManualNetworkSelectionPlmn(int subId) {
5634 TelephonyPermissions
5635 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5636 mApp, subId, "getManualNetworkSelectionPlmn");
5637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 if (!isActiveSubscription(subId)) {
5641 return "";
5642 }
5643
5644 final Phone phone = getPhone(subId);
5645 if (phone == null) {
5646 return "";
5647 }
5648 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5649 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5650 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005655
5656 /**
5657 * Scans for available networks.
5658 */
5659 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005660 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5661 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5663 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005664 LocationAccessPolicy.LocationPermissionResult locationResult =
5665 LocationAccessPolicy.checkLocationPermission(mApp,
5666 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5667 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005668 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005669 .setCallingPid(Binder.getCallingPid())
5670 .setCallingUid(Binder.getCallingUid())
5671 .setMethod("getCellNetworkScanResults")
5672 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5673 .build());
5674 switch (locationResult) {
5675 case DENIED_HARD:
5676 throw new SecurityException("Not allowed to access scan results -- location");
5677 case DENIED_SOFT:
5678 return null;
5679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680
Pengquan Menga1bb6272018-09-06 09:59:22 -07005681 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 try {
5683 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005684 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005689 }
5690
5691 /**
sqian80370722020-01-29 15:02:51 -08005692 * Get the call forwarding info, given the call forwarding reason.
5693 */
5694 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005695 public void getCallForwarding(int subId, int callForwardingReason,
5696 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005697 enforceReadPrivilegedPermission("getCallForwarding");
5698 long identity = Binder.clearCallingIdentity();
5699 try {
5700 if (DBG) {
5701 log("getCallForwarding: subId " + subId
5702 + " callForwardingReason" + callForwardingReason);
5703 }
Hall Liua1acea22020-09-18 19:04:59 -07005704
5705 Phone phone = getPhone(subId);
5706 if (phone == null) {
5707 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005708 callback.onError(
5709 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005710 } catch (RemoteException e) {
5711 // ignore
5712 }
5713 return;
5714 }
5715
5716 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5717 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5718 @Override
5719 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5720 try {
5721 callback.onCallForwardingInfoAvailable(info);
5722 } catch (RemoteException e) {
5723 // ignore
5724 }
5725 }
5726
5727 @Override
5728 public void onError(int error) {
5729 try {
5730 callback.onError(error);
5731 } catch (RemoteException e) {
5732 // ignore
5733 }
5734 }
5735 });
5736 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
5743 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5744 * reason, the number to forward, and the timeout before the forwarding is attempted.
5745 */
5746 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005747 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5748 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005749 enforceModifyPermission();
5750 long identity = Binder.clearCallingIdentity();
5751 try {
5752 if (DBG) {
5753 log("setCallForwarding: subId " + subId
5754 + " callForwardingInfo" + callForwardingInfo);
5755 }
Hall Liua1acea22020-09-18 19:04:59 -07005756
5757 Phone phone = getPhone(subId);
5758 if (phone == null) {
5759 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005760 callback.accept(
5761 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005762 } catch (RemoteException e) {
5763 // ignore
5764 }
5765 return;
5766 }
5767
5768 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5769 FunctionalUtils.ignoreRemoteException(callback::accept));
5770
5771 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
5775 }
5776
5777 /**
Hall Liua1acea22020-09-18 19:04:59 -07005778 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005779 */
5780 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005781 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005782 enforceReadPrivilegedPermission("getCallForwarding");
5783 long identity = Binder.clearCallingIdentity();
5784 try {
Hall Liua1acea22020-09-18 19:04:59 -07005785
5786 Phone phone = getPhone(subId);
5787 if (phone == null) {
5788 try {
5789 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5790 } catch (RemoteException e) {
5791 // ignore
5792 }
5793 return;
5794 }
5795
5796 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5797
sqian80370722020-01-29 15:02:51 -08005798 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005799 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
5803 }
5804
5805 /**
Hall Liua1acea22020-09-18 19:04:59 -07005806 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005807 */
5808 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005809 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005810 enforceModifyPermission();
5811 long identity = Binder.clearCallingIdentity();
5812 try {
Hall Liua1acea22020-09-18 19:04:59 -07005813 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5814
5815 Phone phone = getPhone(subId);
5816 if (phone == null) {
5817 try {
5818 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5819 } catch (RemoteException e) {
5820 // ignore
5821 }
5822 return;
5823 }
5824
5825 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5826 FunctionalUtils.ignoreRemoteException(callback::accept));
5827
5828 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
5832 }
5833
5834 /**
yinxub1bed742017-04-17 11:45:04 -07005835 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005836 *
yinxub1bed742017-04-17 11:45:04 -07005837 * @param subId id of the subscription
5838 * @param request contains the radio access networks with bands/channels to scan
5839 * @param messenger callback messenger for scan results or errors
5840 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005841 * @return the id of the requested scan which can be used to stop the scan.
5842 */
5843 @Override
5844 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005845 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5847 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005848 LocationAccessPolicy.LocationPermissionResult locationResult =
5849 LocationAccessPolicy.checkLocationPermission(mApp,
5850 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5851 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005852 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005853 .setCallingPid(Binder.getCallingPid())
5854 .setCallingUid(Binder.getCallingUid())
5855 .setMethod("requestNetworkScan")
5856 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5857 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005858 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005859 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5860 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005861 if (e != null) {
5862 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5863 throw e;
5864 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005865 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005866 return TelephonyScanManager.INVALID_SCAN_ID;
5867 }
5868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 }
Hall Liu912dfd32019-04-25 14:02:26 -07005870 int callingUid = Binder.getCallingUid();
5871 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005872 final long identity = Binder.clearCallingIdentity();
5873 try {
5874 return mNetworkScanRequestTracker.startNetworkScan(
5875 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005876 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
yinxu504e1392017-04-12 16:03:22 -07005880 }
5881
Hall Liub2ac8ef2019-02-28 15:56:23 -08005882 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005883 NetworkScanRequest request, int subId, String callingPackage) {
5884 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005885 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5886 boolean hasNetworkScanPermission =
5887 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5888 == PERMISSION_GRANTED;
5889
5890 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5891 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5892 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005893 }
5894
5895 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5896 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005897 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5898 return new SecurityException("Specific channels must not be"
5899 + " scanned without location access.");
5900 }
5901 }
5902 }
5903
Hall Liub2ac8ef2019-02-28 15:56:23 -08005904 return null;
5905 }
5906
yinxu504e1392017-04-12 16:03:22 -07005907 /**
5908 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005909 *
5910 * @param subId id of the subscription
5911 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005912 */
5913 @Override
5914 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5916 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917
Hall Liu912dfd32019-04-25 14:02:26 -07005918 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005921 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
yinxu504e1392017-04-12 16:03:22 -07005925 }
5926
5927 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005928 * Get the calculated preferred network type.
5929 * Used for debugging incorrect network type.
5930 *
5931 * @return the preferred network type, defined in RILConstants.java.
5932 */
5933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005934 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 final Phone defaultPhone = getDefaultPhone();
5936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005937 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005938 return RILConstants.PREFERRED_NETWORK_MODE;
5939 }
5940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005944 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Junda Liu84d15a22014-07-02 11:21:04 -07005948 }
5949
5950 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005951 * Get the preferred network type.
5952 * Used for device configuration by some CDMA operators.
5953 *
5954 * @return the preferred network type, defined in RILConstants.java.
5955 */
5956 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005957 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005958 TelephonyPermissions
5959 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5960 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 if (DBG) log("getPreferredNetworkType");
5965 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5966 int networkType = (result != null ? result[0] : -1);
5967 if (DBG) log("getPreferredNetworkType: " + networkType);
5968 return networkType;
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005972 }
5973
5974 /**
5975 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005976 *
5977 * @param networkType the preferred network type, defined in RILConstants.java.
5978 * @return true on success; false on any failure.
5979 */
5980 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005981 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
calvinpan089c2a62020-03-12 14:17:55 +08005987 Boolean success = (Boolean) sendRequest(
5988 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005989
5990 if (success) {
5991 Settings.Global.putInt(mApp.getContentResolver(),
5992 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5993 }
calvinpan089c2a62020-03-12 14:17:55 +08005994 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5995 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005998 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005999 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006000
6001 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006002 * Get the allowed network types that store in the telephony provider.
6003 *
6004 * @param subId the id of the subscription.
6005 * @return allowedNetworkTypes the allowed network types.
6006 */
6007 @Override
6008 public long getAllowedNetworkTypes(int subId) {
6009 TelephonyPermissions
6010 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6011 mApp, subId, "getAllowedNetworkTypes");
6012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
6015 return SubscriptionManager.getLongSubscriptionProperty(
6016 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
6020 }
6021
6022 /**
6023 * Set the allowed network types.
6024 *
6025 * @param subId the id of the subscription.
6026 * @param allowedNetworkTypes the allowed network types.
6027 * @return true on success; false on any failure.
6028 */
6029 @Override
6030 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006033
calvinpan089c2a62020-03-12 14:17:55 +08006034 SubscriptionManager.setSubscriptionProperty(subId,
6035 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6036 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006037
calvinpan089c2a62020-03-12 14:17:55 +08006038 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6039 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6040 RILConstants.PREFERRED_NETWORK_MODE);
6041 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006042 }
6043
6044 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006045 * Get the allowed network types for certain reason.
6046 *
6047 * @param subId the id of the subscription.
6048 * @param reason the reason the allowed network type change is taking place
6049 * @return the allowed network types.
6050 */
6051 @Override
6052 public long getAllowedNetworkTypesForReason(int subId,
6053 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6054 TelephonyPermissions
6055 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6056 mApp, subId, "getAllowedNetworkTypesForReason");
6057 final long identity = Binder.clearCallingIdentity();
6058 try {
6059 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
6063 }
6064
6065 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006066 * Enable/Disable E-UTRA-NR Dual Connectivity
6067 * @param subId subscription id of the sim card
6068 * @param nrDualConnectivityState expected NR dual connectivity state
6069 * This can be passed following states
6070 * <ol>
6071 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6072 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6073 * <li>Disable NR dual connectivity and force secondary cell to be released
6074 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6075 * </ol>
6076 * @return operation result.
6077 */
6078 @Override
6079 public int setNrDualConnectivityState(int subId,
6080 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6082 mApp, subId, "enableNRDualConnectivity");
6083 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
6086 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6087 nrDualConnectivityState, subId,
6088 workSource);
6089 if (DBG) log("enableNRDualConnectivity result: " + result);
6090 return result;
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
6094 }
6095
6096 /**
6097 * Is E-UTRA-NR Dual Connectivity enabled
6098 * @return true if dual connectivity is enabled else false
6099 */
6100 @Override
6101 public boolean isNrDualConnectivityEnabled(int subId) {
6102 TelephonyPermissions
6103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6104 mApp, subId, "isNRDualConnectivityEnabled");
6105 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6109 null, subId, workSource);
6110 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6111 return isEnabled;
6112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
6115 }
6116
6117 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006118 * get carrier bandwidth per primary and secondary carrier
6119 * @param subId subscription id of the sim card
6120 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6121 */
6122 @Override
6123 public CarrierBandwidth getCarrierBandwidth(int subId) {
6124 TelephonyPermissions
6125 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6126 mApp, subId, "isNRDualConnectivityEnabled");
6127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 CarrierBandwidth carrierBandwidth =
6131 getPhoneFromSubId(subId).getCarrierBandwidth();
6132 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6133 return carrierBandwidth;
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006140 * Get the effective allowed network types on the device.
6141 * This API will return an intersection of allowed network types for all reasons,
6142 * including the configuration done through setAllowedNetworkTypes
6143 *
6144 * @param subId the id of the subscription.
6145 * @return the allowed network types
6146 */
6147 @Override
6148 public long getEffectiveAllowedNetworkTypes(int subId) {
6149 TelephonyPermissions
6150 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6151 mApp, subId, "getEffectiveAllowedNetworkTypes");
6152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6155 } finally {
6156 Binder.restoreCallingIdentity(identity);
6157 }
6158 }
6159
6160 /**
6161 * Set the allowed network types of the device and
6162 * provide the reason triggering the allowed network change.
6163 *
6164 * @param subId the id of the subscription.
6165 * @param reason the reason the allowed network type change is taking place
6166 * @param allowedNetworkTypes the allowed network types.
6167 * @return true on success; false on any failure.
6168 */
6169 @Override
6170 public boolean setAllowedNetworkTypesForReason(int subId,
6171 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6173 mApp, subId, "setAllowedNetworkTypesForReason");
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6177 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6178 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6179 RILConstants.PREFERRED_NETWORK_MODE);
6180 return setPreferredNetworkType(subId, preferredNetworkMode);
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183 }
6184 }
6185
6186 /**
Miaoa84611c2019-03-15 09:21:10 +08006187 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006188 *
Miaoa84611c2019-03-15 09:21:10 +08006189 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006190 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006191 * @hide
6192 */
6193 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006194 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 try {
Miaoa84611c2019-03-15 09:21:10 +08006199 if (phone != null) {
6200 return phone.hasMatchedTetherApnSetting();
6201 } else {
6202 return false;
6203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006206 }
Junda Liu475951f2014-11-07 16:45:03 -08006207 }
6208
6209 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006210 * Enable or disable always reporting signal strength changes from radio.
6211 *
6212 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6213 */
6214 @Override
6215 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6216 enforceModifyPermission();
6217 enforceSystemCaller();
6218
6219 final long identity = Binder.clearCallingIdentity();
6220 final Phone phone = getPhone(subId);
6221 try {
6222 if (phone != null) {
6223 if (DBG) {
6224 log("setAlwaysReportSignalStrength: subId=" + subId
6225 + " isEnable=" + isEnable);
6226 }
6227 phone.setAlwaysReportSignalStrength(isEnable);
6228 } else {
6229 loge("setAlwaysReportSignalStrength: no phone found for subId="
6230 + subId);
6231 }
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006238 * Get the user enabled state of Mobile Data.
6239 *
6240 * TODO: remove and use isUserDataEnabled.
6241 * This can't be removed now because some vendor codes
6242 * calls through ITelephony directly while they should
6243 * use TelephonyManager.
6244 *
6245 * @return true on enabled
6246 */
6247 @Override
6248 public boolean getDataEnabled(int subId) {
6249 return isUserDataEnabled(subId);
6250 }
6251
6252 /**
6253 * Get whether mobile data is enabled per user setting.
6254 *
6255 * There are other factors deciding whether mobile data is actually enabled, but they are
6256 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006257 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006258 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006259 *
6260 * @return {@code true} if data is enabled else {@code false}
6261 */
6262 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006263 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006264 try {
6265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6266 null);
6267 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6269 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271
6272 final long identity = Binder.clearCallingIdentity();
6273 try {
6274 int phoneId = mSubscriptionController.getPhoneId(subId);
6275 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6276 Phone phone = PhoneFactory.getPhone(phoneId);
6277 if (phone != null) {
6278 boolean retVal = phone.isUserDataEnabled();
6279 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6280 return retVal;
6281 } else {
6282 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6283 return false;
6284 }
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006287 }
6288 }
6289
6290 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006291 * Checks if the device is capable of mobile data by considering whether whether the
6292 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6293 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006294 *
Shuo Qian985d1232020-01-08 14:30:06 -08006295 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006296 */
6297 @Override
6298 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006299 try {
6300 try {
6301 mApp.enforceCallingOrSelfPermission(
6302 android.Manifest.permission.ACCESS_NETWORK_STATE,
6303 null);
6304 } catch (Exception e) {
6305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6306 "isDataEnabled");
6307 }
6308 } catch (Exception e) {
6309 enforceReadPrivilegedPermission("isDataEnabled");
6310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311
6312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 int phoneId = mSubscriptionController.getPhoneId(subId);
6315 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6316 Phone phone = PhoneFactory.getPhone(phoneId);
6317 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006318 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6320 return retVal;
6321 } else {
6322 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6323 return false;
6324 }
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006327 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006328 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006329
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006330 /**
6331 * Check if data is enabled for a specific reason
6332 * @param subId Subscription index
6333 * @param reason the reason the data enable change is taking place
6334 * @return {@code true} if the overall data is enabled; {@code false} if not.
6335 */
6336 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006337 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006338 @TelephonyManager.DataEnabledReason int reason) {
6339 try {
6340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6341 null);
6342 } catch (Exception e) {
6343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006344 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006345 }
6346
6347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 int phoneId = mSubscriptionController.getPhoneId(subId);
6351 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006353 + " reason=" + reason);
6354 }
6355 Phone phone = PhoneFactory.getPhone(phoneId);
6356 if (phone != null) {
6357 boolean retVal;
6358 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6359 retVal = phone.isUserDataEnabled();
6360 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006361 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006362 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006363 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006364 return retVal;
6365 } else {
6366 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006367 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006368 + subId + " retVal=false");
6369 }
6370 return false;
6371 }
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
6375 }
6376
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006377 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006378 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006379 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6380 // Skip the check if it's one of these special uids
6381 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6382 }
6383
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006384 //load access rules from carrier configs, and check those as well: b/139133814
6385 SubscriptionController subController = SubscriptionController.getInstance();
6386 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6387 || subController == null) return privilegeFromSim;
6388
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006389 PackageManager pkgMgr = phone.getContext().getPackageManager();
6390 String[] packages = pkgMgr.getPackagesForUid(uid);
6391
6392 final long identity = Binder.clearCallingIdentity();
6393 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006394 int subId = phone.getSubId();
6395 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6396 // A test override is in place for the privileges for this subId, so don't try to
6397 // read the subscription privileges.
6398 return privilegeFromSim;
6399 }
6400 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006401 SubscriptionManager subManager = (SubscriptionManager)
6402 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6403 for (String pkg : packages) {
6404 if (subManager.canManageSubscription(subInfo, pkg)) {
6405 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6406 }
6407 }
6408 return privilegeFromSim;
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
6412 }
6413
6414 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6415 String pkgName) {
6416 //load access rules from carrier configs, and check those as well: b/139133814
6417 SubscriptionController subController = SubscriptionController.getInstance();
6418 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6419 || subController == null) return privilegeFromSim;
6420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006423 int subId = phone.getSubId();
6424 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6425 // A test override is in place for the privileges for this subId, so don't try to
6426 // read the subscription privileges.
6427 return privilegeFromSim;
6428 }
6429 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006430 SubscriptionManager subManager = (SubscriptionManager)
6431 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6432 return subManager.canManageSubscription(subInfo, pkgName)
6433 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
6437 }
6438
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006440 public int getCarrierPrivilegeStatus(int subId) {
6441 final Phone phone = getPhone(subId);
6442 if (phone == null) {
6443 loge("getCarrierPrivilegeStatus: Invalid subId");
6444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6445 }
6446 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006447 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006448 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6450 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006451
6452 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6453 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006454 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006455 }
Junda Liu29340342014-07-10 15:23:27 -07006456
6457 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006459 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006460 final Phone phone = getPhone(subId);
6461 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006462 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6464 }
6465 UiccProfile profile =
6466 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6467 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006468 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6470 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006471 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006472 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006473 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006474 }
6475
6476 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006477 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6478 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006479 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006480 }
6481
6482 int phoneId = SubscriptionManager.getPhoneId(subId);
6483 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006484 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006485 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006486 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6487 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006488 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6489 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6490 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006491 }
6492
6493 @Override
6494 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006495 if (TextUtils.isEmpty(pkgName))
6496 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006497 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6498 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6499 UiccCard card = UiccController.getInstance().getUiccCard(i);
6500 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006501 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006502 continue;
6503 }
6504
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006505 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6506 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6507 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006508 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6509 break;
6510 }
6511 }
6512
6513 return result;
Junda Liu29340342014-07-10 15:23:27 -07006514 }
Derek Tan89e89d42014-07-08 17:00:10 -07006515
6516 @Override
Junda Liue64de782015-04-16 17:19:16 -07006517 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6518 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6519 loge("phoneId " + phoneId + " is not valid.");
6520 return null;
6521 }
6522 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006523 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006524 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006525 return null ;
6526 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006528 }
6529
Amith Yamasani6e118872016-02-19 12:53:51 -08006530 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006531 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006532 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006533 List<String> privilegedPackages = new ArrayList<>();
6534 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006535 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6536 // has UICC in that slot.
6537 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006538 if (card.hasCarrierPrivilegeRules()) {
6539 if (packages == null) {
6540 // Only check packages in user 0 for now
6541 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006542 PackageManager.MATCH_DISABLED_COMPONENTS
6543 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006544 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006545 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006546 }
6547 for (int p = packages.size() - 1; p >= 0; p--) {
6548 PackageInfo pkgInfo = packages.get(p);
6549 if (pkgInfo != null && pkgInfo.packageName != null
6550 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006551 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006552 privilegedPackages.add(pkgInfo.packageName);
6553 }
6554 }
6555 }
6556 }
6557 return privilegedPackages;
6558 }
6559
chen xuf7e9fe82019-05-09 19:31:02 -07006560 @Override
6561 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006562 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6563
6564 final long identity = Binder.clearCallingIdentity();
6565
chen xuf7e9fe82019-05-09 19:31:02 -07006566 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006567 try {
6568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6569 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6570 }
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006573 }
6574 return privilegedPackages;
6575 }
6576
Wink Savilleb564aae2014-10-23 10:18:09 -07006577 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006578 final Phone phone = getPhone(subId);
6579 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006580 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006581 return null;
6582 }
6583 String iccId = card.getIccId();
6584 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006585 return null;
6586 }
6587 return iccId;
6588 }
6589
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006590 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006591 public void setCallComposerStatus(int subId, int status) {
6592 enforceModifyPermission();
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 Phone phone = getPhone(subId);
6597 if (phone != null) {
6598 Phone defaultPhone = phone.getImsPhone();
6599 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6600 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6601 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006602 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6603 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006604 }
6605 }
Shuo Qiand8782462020-12-22 19:10:14 -08006606 } catch (ImsException e) {
6607 throw new ServiceSpecificException(e.getCode());
6608 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 @Override
6614 public int getCallComposerStatus(int subId) {
6615 enforceReadPrivilegedPermission("getCallComposerStatus");
6616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 Phone phone = getPhone(subId);
6620 if (phone != null) {
6621 Phone defaultPhone = phone.getImsPhone();
6622 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6623 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6624 return imsPhone.getCallComposerStatus();
6625 }
6626 }
6627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
6630 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6631 }
6632
6633 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006634 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6635 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006636 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006637 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 final String iccId = getIccId(subId);
6642 final Phone phone = getPhone(subId);
6643 if (phone == null) {
6644 return false;
6645 }
6646 final String subscriberId = phone.getSubscriberId();
6647
6648 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006649 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 + subscriberId + " to " + number);
6651 }
6652
6653 if (TextUtils.isEmpty(iccId)) {
6654 return false;
6655 }
6656
6657 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6658
6659 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6660 if (alphaTag == null) {
6661 editor.remove(alphaTagPrefKey);
6662 } else {
6663 editor.putString(alphaTagPrefKey, alphaTag);
6664 }
6665
6666 // Record both the line number and IMSI for this ICCID, since we need to
6667 // track all merged IMSIs based on line number
6668 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6669 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6670 if (number == null) {
6671 editor.remove(numberPrefKey);
6672 editor.remove(subscriberPrefKey);
6673 } else {
6674 editor.putString(numberPrefKey, number);
6675 editor.putString(subscriberPrefKey, subscriberId);
6676 }
6677
6678 editor.commit();
6679 return true;
6680 } finally {
6681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006682 }
Derek Tan7226c842014-07-02 17:42:23 -07006683 }
6684
6685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006686 public String getLine1NumberForDisplay(int subId, String callingPackage,
6687 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006688 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006690 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006691 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006692 return null;
6693 }
Derek Tan97ebb422014-09-05 16:55:38 -07006694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 String iccId = getIccId(subId);
6698 if (iccId != null) {
6699 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6700 if (DBG_MERGE) {
6701 log("getLine1NumberForDisplay returning "
6702 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6703 }
6704 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6707 return null;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006710 }
Derek Tan7226c842014-07-02 17:42:23 -07006711 }
6712
6713 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006714 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006717 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006718 return null;
6719 }
Derek Tan97ebb422014-09-05 16:55:38 -07006720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 final long identity = Binder.clearCallingIdentity();
6722 try {
6723 String iccId = getIccId(subId);
6724 if (iccId != null) {
6725 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6726 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6727 }
6728 return null;
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006731 }
Derek Tan7226c842014-07-02 17:42:23 -07006732 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006733
6734 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006735 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6736 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006737 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6738 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006740 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006741 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006742 return null;
6743 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006744
Jordan Liub49b04b2019-05-06 14:45:15 -07006745 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6746 // the process, where TelephonyManager was instantiated.
6747 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006748 final long identity = Binder.clearCallingIdentity();
6749 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006750 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final TelephonyManager tele = TelephonyManager.from(context);
6752 final SubscriptionManager sub = SubscriptionManager.from(context);
6753
6754 // Figure out what subscribers are currently active
6755 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756
Jordan Liub49b04b2019-05-06 14:45:15 -07006757 // Only consider subs which match the current subId
6758 // This logic can be simplified. See b/131189269 for progress.
6759 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006760 activeSubscriberIds.add(tele.getSubscriberId(subId));
6761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
6763 // First pass, find a number override for an active subscriber
6764 String mergeNumber = null;
6765 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6766 for (String key : prefs.keySet()) {
6767 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6768 final String subscriberId = (String) prefs.get(key);
6769 if (activeSubscriberIds.contains(subscriberId)) {
6770 final String iccId = key.substring(
6771 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6772 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6773 mergeNumber = (String) prefs.get(numberKey);
6774 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006775 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 + " for active subscriber " + subscriberId);
6777 }
6778 if (!TextUtils.isEmpty(mergeNumber)) {
6779 break;
6780 }
6781 }
6782 }
6783 }
6784
6785 // Shortcut when no active merged subscribers
6786 if (TextUtils.isEmpty(mergeNumber)) {
6787 return null;
6788 }
6789
6790 // Second pass, find all subscribers under that line override
6791 final ArraySet<String> result = new ArraySet<>();
6792 for (String key : prefs.keySet()) {
6793 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6794 final String number = (String) prefs.get(key);
6795 if (mergeNumber.equals(number)) {
6796 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6797 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6798 final String subscriberId = (String) prefs.get(subscriberKey);
6799 if (!TextUtils.isEmpty(subscriberId)) {
6800 result.add(subscriberId);
6801 }
6802 }
6803 }
6804 }
6805
6806 final String[] resultArray = result.toArray(new String[result.size()]);
6807 Arrays.sort(resultArray);
6808 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006809 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6811 }
6812 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006815 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006816 }
6817
6818 @Override
zoey chen38003472019-12-13 17:16:31 +08006819 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6820 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 final TelephonyManager telephonyManager = mApp.getSystemService(
6825 TelephonyManager.class);
6826 String subscriberId = telephonyManager.getSubscriberId(subId);
6827 if (subscriberId == null) {
6828 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006829 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006830 + subId);
6831 }
6832 return null;
6833 }
6834
6835 final SubscriptionInfo info = SubscriptionController.getInstance()
6836 .getSubscriptionInfo(subId);
6837 final ParcelUuid groupUuid = info.getGroupUuid();
6838 // If it doesn't belong to any group, return just subscriberId of itself.
6839 if (groupUuid == null) {
6840 return new String[]{subscriberId};
6841 }
6842
6843 // Get all subscriberIds from the group.
6844 final List<String> mergedSubscriberIds = new ArrayList<>();
6845 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006846 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006847 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006848 for (SubscriptionInfo subInfo : groupInfos) {
6849 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6850 if (subscriberId != null) {
6851 mergedSubscriberIds.add(subscriberId);
6852 }
6853 }
6854
6855 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858
6859 }
6860 }
6861
6862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006863 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006865 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 final Phone phone = getPhone(subId);
6870 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006874 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006875
6876 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006877 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006878 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6879 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006880 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6881 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 final Phone phone = getPhone(subId);
6886 if (phone == null) {
6887 return false;
6888 }
6889 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6890 cdmaNonRoamingList);
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006893 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006894 }
6895
6896 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006897 @Deprecated
6898 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6899 enforceModifyPermission();
6900
6901 int returnValue = 0;
6902 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006903 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006904 if(result.exception == null) {
6905 if (result.result != null) {
6906 byte[] responseData = (byte[])(result.result);
6907 if(responseData.length > oemResp.length) {
6908 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6909 responseData.length + "bytes. Buffer Size is " +
6910 oemResp.length + "bytes.");
6911 }
6912 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6913 returnValue = responseData.length;
6914 }
6915 } else {
6916 CommandException ex = (CommandException) result.exception;
6917 returnValue = ex.getCommandError().ordinal();
6918 if(returnValue > 0) returnValue *= -1;
6919 }
6920 } catch (RuntimeException e) {
6921 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6922 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6923 if(returnValue > 0) returnValue *= -1;
6924 }
6925
6926 return returnValue;
6927 }
6928
6929 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006930 public void setRadioCapability(RadioAccessFamily[] rafs) {
6931 try {
6932 ProxyController.getInstance().setRadioCapability(rafs);
6933 } catch (RuntimeException e) {
6934 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6935 }
6936 }
6937
6938 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006939 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006940 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006941 try {
6942 TelephonyPermissions
6943 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6944 mApp, phone.getSubId(), "getRadioAccessFamily");
6945 } catch (SecurityException e) {
6946 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6947 throw e;
6948 }
chen xub97461a2018-10-26 14:17:57 -07006949 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006950 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006951 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 final long identity = Binder.clearCallingIdentity();
6954 try {
chen xub97461a2018-10-26 14:17:57 -07006955 TelephonyPermissions
6956 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6957 mApp, phone.getSubId(), "getRadioAccessFamily");
6958 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
chen xub97461a2018-10-26 14:17:57 -07006962 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006963 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006964
6965 @Override
6966 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006967 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006972 ImsManager.getInstance(defaultPhone.getContext(),
6973 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 } finally {
6975 Binder.restoreCallingIdentity(identity);
6976 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006977 }
6978
6979 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006980 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6983 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006984 return false;
6985 }
Svet Ganovb320e182015-04-16 12:30:10 -07006986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 // Check the user preference and the system-level IMS setting. Even if the user has
6990 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6991 // In the long run, we may instead need to check if there exists a connection service
6992 // which can support video calling.
6993 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006994 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 return imsManager.isVtEnabledByPlatform()
6996 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6997 && imsManager.isVtEnabledByUser();
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007001 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007002
Andrew Leea1239f22015-03-02 17:44:07 -08007003 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007004 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7005 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007007 mApp, subId, callingPackage, callingFeatureId,
7008 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 return false;
7010 }
7011
7012 final long identity = Binder.clearCallingIdentity();
7013 try {
7014 CarrierConfigManager configManager =
7015 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007016 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
Andrew Leea1239f22015-03-02 17:44:07 -08007021 }
7022
7023 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007024 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007026 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 return false;
7028 }
7029
7030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 CarrierConfigManager configManager =
7033 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007034 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
7038 }
Andrew Leea1239f22015-03-02 17:44:07 -08007039 }
7040
Andrew Lee9431b832015-03-09 18:46:45 -07007041 @Override
7042 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007043 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007044 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007045 }
7046
7047 @Override
7048 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 final long identity = Binder.clearCallingIdentity();
7050 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007051 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
Andrew Lee9431b832015-03-09 18:46:45 -07007055 }
7056
Hall Liuf6668912018-10-31 17:05:23 -07007057 /**
7058 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7059 * support for the feature and device firmware support.
7060 *
7061 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7062 */
7063 @Override
7064 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007066 final Phone phone = getPhone(subscriptionId);
7067 if (phone == null) {
7068 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7069 return false;
7070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007072 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7074 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007075 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 return isCarrierSupported && isDeviceSupported;
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
Hall Liu98187582018-01-22 19:15:32 -08007080 }
7081
Hall Liuf6668912018-10-31 17:05:23 -07007082 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007083 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7084 * RTT setting, will return true if the device and carrier both support RTT.
7085 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007086 */
7087 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 final long identity = Binder.clearCallingIdentity();
7089 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007090 boolean isRttSupported = isRttSupported(subscriptionId);
7091 boolean isUserRttSettingOn = Settings.Secure.getInt(
7092 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7093 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7094 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7095 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007099 }
7100
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007101 @Deprecated
7102 @Override
7103 public String getDeviceId(String callingPackage) {
7104 return getDeviceIdWithFeature(callingPackage, null);
7105 }
7106
Sanket Padawe7310cc72015-01-14 09:53:20 -08007107 /**
7108 * Returns the unique device ID of phone, for example, the IMEI for
7109 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7110 *
7111 * <p>Requires Permission:
7112 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7113 */
7114 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007115 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007116 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007117 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007118 return null;
7119 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007120 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007121 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007122 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007123 return null;
7124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 return phone.getDeviceId();
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007132 }
7133
Ping Sunc67b7c22016-03-02 19:16:45 +08007134 /**
7135 * {@hide}
7136 * Returns the IMS Registration Status on a particular subid
7137 *
7138 * @param subId
7139 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007140 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007141 Phone phone = getPhone(subId);
7142 if (phone != null) {
7143 return phone.isImsRegistered();
7144 } else {
7145 return false;
7146 }
7147 }
7148
Santos Cordon7a1885b2015-02-03 11:15:19 -08007149 @Override
7150 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007157 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007158
Tyler Gunnf70ed162019-04-03 15:28:53 -07007159 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007160 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007161 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007163 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007164 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7165 }
7166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
7172 }
7173
7174 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007175 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007176 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7177 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 Phone phone = getPhone(subscriptionId);
7181 if (phone == null) {
7182 return null;
7183 }
7184 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
7188 }
7189
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007190 /**
7191 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007192 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007193 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 Phone phone = getPhone(subId);
7197 if (phone != null) {
7198 return phone.isWifiCallingEnabled();
7199 } else {
7200 return false;
7201 }
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007204 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007205 }
7206
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007207 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007208 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007209 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007210 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 Phone phone = getPhone(subId);
7214 if (phone != null) {
7215 return phone.isVideoEnabled();
7216 } else {
7217 return false;
7218 }
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007221 }
7222 }
7223
7224 /**
7225 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7226 * defined in {@link ImsRegistrationImplBase}.
7227 */
7228 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 final long identity = Binder.clearCallingIdentity();
7230 try {
7231 Phone phone = getPhone(subId);
7232 if (phone != null) {
7233 return phone.getImsRegistrationTech();
7234 } else {
7235 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7236 }
7237 } finally {
7238 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007239 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007240 }
7241
Stuart Scott8eef64f2015-04-08 15:13:54 -07007242 @Override
7243 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007244 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007245 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7246 return;
7247 }
7248
Svet Ganovcc087f82015-05-12 20:35:54 -07007249 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007250
Svet Ganovcc087f82015-05-12 20:35:54 -07007251 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007252 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7253 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007254 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007255 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007256 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007257 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007258 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7259 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007260 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007261 // There has been issues when Sms raw table somehow stores orphan
7262 // fragments. They lead to garbled message when new fragments come
7263 // in and combined with those stale ones. In case this happens again,
7264 // user can reset all network settings which will clean up this table.
7265 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007266 // Clean up IMS settings as well here.
7267 int slotId = getSlotIndex(subId);
7268 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7269 ImsManager.getInstance(mApp, slotId).factoryReset();
7270 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007271
7272 // Erase modem config if erase modem on network setting is enabled.
7273 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7274 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7275 if (configValue != null && Boolean.parseBoolean(configValue)) {
7276 sendEraseModemConfig(getDefaultPhone());
7277 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007280 }
7281 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007282
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007283 private void cleanUpSmsRawTable(Context context) {
7284 ContentResolver resolver = context.getContentResolver();
7285 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7286 resolver.delete(uri, null, null);
7287 }
7288
Narayan Kamath1c496c22015-04-16 14:40:19 +01007289 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007290 public String getSimLocaleForSubscriber(int subId) {
7291 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7292 final Phone phone = getPhone(subId);
7293 if (phone == null) {
7294 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007295 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 final long identity = Binder.clearCallingIdentity();
7298 try {
chen xu5d3637b2019-01-21 23:31:38 -08007299 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007300 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007301 if (info == null) {
7302 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7303 return null;
7304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 // Try and fetch the locale from the carrier properties or from the SIM language
7306 // preferences (EF-PL and EF-LI)...
7307 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007309 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7310 if (localeFromDefaultSim != null) {
7311 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7312 if (DBG) log("Using locale from subId: " + subId + " locale: "
7313 + localeFromDefaultSim);
7314 return localeFromDefaultSim.toLanguageTag();
7315 } else {
7316 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 }
7318 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 // The SIM language preferences only store a language (e.g. fr = French), not an
7321 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7322 // the SIM and carrier preferences does not include a country we add the country
7323 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007324 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007326 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 return mccLocale.toLanguageTag();
7328 }
7329
7330 if (DBG) log("No locale found - returning null");
7331 return null;
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007335 }
7336
7337 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007338 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007339 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007340 }
7341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 /**
7343 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7344 */
7345 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007346 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007347 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007348 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007349
Chenjie Yu1ba97252018-01-11 18:16:20 -08007350 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007351 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007352
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007353 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007354 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7355 * representing the state of the modem.
7356 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007357 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7358 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007359 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007360 */
7361 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007362 public void requestModemActivityInfo(ResultReceiver result) {
7363 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365
7366 final long identity = Binder.clearCallingIdentity();
7367 try {
sqian1a1be542020-03-05 11:37:28 -08007368 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 } finally {
7370 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007371 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007372 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007373
Siddharth Rayb8114062018-06-17 15:02:38 -07007374 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7375 // less than total activity duration.
7376 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7377 if (info == null) {
7378 return false;
7379 }
7380 int activityDurationMs =
7381 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7382 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007383 int[] txTimeMs = info.getTransmitTimeMillis();
7384 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7385 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007386 }
7387 return (info.isValid()
7388 && (info.getSleepTimeMillis() <= activityDurationMs)
7389 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007390 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007391 && (totalTxTimeMs <= activityDurationMs));
7392 }
7393
Jack Yu85bd38a2015-11-09 11:34:32 -08007394 /**
7395 * {@hide}
7396 * Returns the service state information on specified subscription.
7397 */
7398 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007399 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7400 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007402 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007403 return null;
7404 }
7405
Hall Liuf19c44f2018-11-27 14:38:17 -08007406 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7407 LocationAccessPolicy.checkLocationPermission(mApp,
7408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7409 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007410 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007411 .setCallingPid(Binder.getCallingPid())
7412 .setCallingUid(Binder.getCallingUid())
7413 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007414 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007415 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7416 .build());
7417
7418 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7419 LocationAccessPolicy.checkLocationPermission(mApp,
7420 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7421 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007422 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007423 .setCallingPid(Binder.getCallingPid())
7424 .setCallingUid(Binder.getCallingUid())
7425 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007426 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7428 .build());
7429 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7430 boolean hasFinePermission =
7431 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7432 boolean hasCoarsePermission =
7433 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 final long identity = Binder.clearCallingIdentity();
7436 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007437 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7438 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7439 Rlog.d(LOG_TAG,
7440 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7441 return null;
7442 }
7443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final Phone phone = getPhone(subId);
7445 if (phone == null) {
7446 return null;
7447 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007448
Hall Liuf19c44f2018-11-27 14:38:17 -08007449 ServiceState ss = phone.getServiceState();
7450
7451 // Scrub out the location info in ServiceState depending on what level of access
7452 // the caller has.
7453 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007454 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7455 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007459 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007460
7461 /**
7462 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7463 *
7464 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7465 * voicemail ringtone.
7466 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7467 * PhoneAccount.
7468 */
7469 @Override
7470 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7474 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007475 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007482 }
7483
7484 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007485 * Sets the per-account voicemail ringtone.
7486 *
7487 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7488 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7489 *
7490 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7491 * voicemail ringtone.
7492 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7493 * PhoneAccount.
7494 */
7495 @Override
7496 public void setVoicemailRingtoneUri(String callingPackage,
7497 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007498 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007500 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7501 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7503 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7504 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7510 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 }
7513 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007516 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007517 }
7518
7519 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007520 * Returns whether vibration is set for voicemail notification in Phone settings.
7521 *
7522 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7523 * voicemail vibration setting.
7524 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7525 */
7526 @Override
7527 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7531 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007539 }
7540
Youhan Wange64578a2016-05-02 15:32:42 -07007541 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007542 * Sets the per-account voicemail vibration.
7543 *
7544 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7545 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7546 *
7547 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7548 * voicemail vibration setting.
7549 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7550 * specific PhoneAccount.
7551 */
7552 @Override
7553 public void setVoicemailVibrationEnabled(String callingPackage,
7554 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007555 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007557 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7558 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7560 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7561 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007562 }
7563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7567 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007568 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 }
7570 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007574 }
7575
7576 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007577 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7578 *
7579 * @throws SecurityException if the caller does not have the required permission
7580 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007581 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007582 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007583 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007584 }
7585
7586 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007587 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7588 * permission.
7589 *
7590 * @throws SecurityException if the caller does not have the required permission
7591 */
7592 private void enforceSendSmsPermission() {
7593 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7594 }
7595
7596 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007597 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007598 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007599 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007600 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007601 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007605 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 if (componentName == null) {
7607 throw new SecurityException(
7608 "Caller not current active visual voicemail package[null]");
7609 }
7610 String vvmPackage = componentName.getPackageName();
7611 if (!callingPackage.equals(vvmPackage)) {
7612 throw new SecurityException("Caller not current active visual voicemail package["
7613 + vvmPackage + "]");
7614 }
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007617 }
7618 }
7619
7620 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007621 * Return the application ID for the app type.
7622 *
7623 * @param subId the subscription ID that this request applies to.
7624 * @param appType the uicc app type.
7625 * @return Application ID for specificied app type, or null if no uicc.
7626 */
7627 @Override
7628 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007629 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007630 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631
7632 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007633 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 if (phone == null) {
7635 return null;
7636 }
7637 String aid = null;
7638 try {
7639 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7640 .getApplicationByType(appType).getAid();
7641 } catch (Exception e) {
7642 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7643 }
7644 return aid;
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007647 }
Youhan Wange64578a2016-05-02 15:32:42 -07007648 }
7649
Youhan Wang4001d252016-05-11 10:29:41 -07007650 /**
7651 * Return the Electronic Serial Number.
7652 *
7653 * @param subId the subscription ID that this request applies to.
7654 * @return ESN or null if error.
7655 */
7656 @Override
7657 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007658 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007659 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660
7661 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007662 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 if (phone == null) {
7664 return null;
7665 }
7666 String esn = null;
7667 try {
7668 esn = phone.getEsn();
7669 } catch (Exception e) {
7670 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7671 }
7672 return esn;
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007675 }
Youhan Wang4001d252016-05-11 10:29:41 -07007676 }
7677
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007678 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007679 * Return the Preferred Roaming List Version.
7680 *
7681 * @param subId the subscription ID that this request applies to.
7682 * @return PRLVersion or null if error.
7683 */
7684 @Override
7685 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007686 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007687 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688
7689 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007690 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 if (phone == null) {
7692 return null;
7693 }
7694 String cdmaPrlVersion = null;
7695 try {
7696 cdmaPrlVersion = phone.getCdmaPrlVersion();
7697 } catch (Exception e) {
7698 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7699 }
7700 return cdmaPrlVersion;
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007703 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007704 }
7705
7706 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007707 * Get snapshot of Telephony histograms
7708 * @return List of Telephony histograms
7709 * @hide
7710 */
7711 @Override
7712 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7714 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715
7716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 return RIL.getTelephonyRILTimingHistograms();
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
7721 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007722 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007723
7724 /**
7725 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007726 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7727 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007728 * Require system privileges. In the future we may add this to carrier APIs.
7729 *
Michele Berionne482f8202018-11-27 18:57:59 -08007730 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007731 */
7732 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007733 @TelephonyManager.SetCarrierRestrictionResult
7734 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007735 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007736 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007737
Michele Berionne482f8202018-11-27 18:57:59 -08007738 if (carrierRestrictionRules == null) {
7739 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007740 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007744 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007745 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007749 }
7750
7751 /**
7752 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007753 * Get the allowed carrier list and the excluded carrier list, including the priority between
7754 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007755 * Require system privileges. In the future we may add this to carrier APIs.
7756 *
Michele Berionne482f8202018-11-27 18:57:59 -08007757 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007758 */
7759 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007760 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007761 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007762 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007766 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7767 if (response instanceof CarrierRestrictionRules) {
7768 return (CarrierRestrictionRules) response;
7769 }
7770 // Response is an Exception of some kind,
7771 // which is signalled to the user as a NULL retval
7772 return null;
7773 } catch (Exception e) {
7774 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7775 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 } finally {
7777 Binder.restoreCallingIdentity(identity);
7778 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007779 }
7780
fionaxu59545b42016-05-25 15:53:37 -07007781 /**
fionaxu59545b42016-05-25 15:53:37 -07007782 * Action set from carrier signalling broadcast receivers to enable/disable radio
7783 * @param subId the subscription ID that this action applies to.
7784 * @param enabled control enable or disable radio.
7785 * {@hide}
7786 */
7787 @Override
7788 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7789 enforceModifyPermission();
7790 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791
7792 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007793 if (phone == null) {
7794 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7795 return;
7796 }
7797 try {
7798 phone.carrierActionSetRadioEnabled(enabled);
7799 } catch (Exception e) {
7800 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 } finally {
7802 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007803 }
7804 }
7805
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007806 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007807 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7808 * network status based on which carrier apps could apply actions accordingly,
7809 * enable/disable default url handler for example.
7810 *
7811 * @param subId the subscription ID that this action applies to.
7812 * @param report control start/stop reporting the default network status.
7813 * {@hide}
7814 */
7815 @Override
7816 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7817 enforceModifyPermission();
7818 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819
7820 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007821 if (phone == null) {
7822 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7823 return;
7824 }
7825 try {
7826 phone.carrierActionReportDefaultNetworkStatus(report);
7827 } catch (Exception e) {
7828 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 } finally {
7830 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007831 }
7832 }
7833
7834 /**
fionaxud9622282017-07-17 17:51:30 -07007835 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7836 * @param subId the subscription ID that this action applies to.
7837 * {@hide}
7838 */
7839 @Override
7840 public void carrierActionResetAll(int subId) {
7841 enforceModifyPermission();
7842 final Phone phone = getPhone(subId);
7843 if (phone == null) {
7844 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7845 return;
7846 }
7847 try {
7848 phone.carrierActionResetAll();
7849 } catch (Exception e) {
7850 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7851 }
7852 }
7853
7854 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007855 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7856 * bug report is being generated.
7857 */
7858 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007859 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007860 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7861 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007862 writer.println("Permission Denial: can't dump Phone from pid="
7863 + Binder.getCallingPid()
7864 + ", uid=" + Binder.getCallingUid()
7865 + "without permission "
7866 + android.Manifest.permission.DUMP);
7867 return;
7868 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007869 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007870 }
Jack Yueb89b242016-06-22 13:27:47 -07007871
Brad Ebingerdac2f002018-04-03 15:17:52 -07007872 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007873 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7874 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7875 @NonNull String[] args) {
7876 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7877 this, in.getFileDescriptor(), out.getFileDescriptor(),
7878 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007879 }
7880
Jack Yueb89b242016-06-22 13:27:47 -07007881 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007882 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007883 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007884 * @param reason the reason the data enable change is taking place
7885 * @param enabled True if enabling the data, otherwise disabling.
7886 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007887 */
7888 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007889 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007890 boolean enabled) {
7891 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7892 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7893 try {
7894 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007895 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007896 } catch (SecurityException se) {
7897 enforceModifyPermission();
7898 }
7899 } else {
7900 enforceModifyPermission();
7901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902
7903 final long identity = Binder.clearCallingIdentity();
7904 try {
7905 Phone phone = getPhone(subId);
7906 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007907 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7908 phone.carrierActionSetMeteredApnsEnabled(enabled);
7909 } else {
7910 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 }
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007915 }
7916 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007917
7918 /**
7919 * Get Client request stats
7920 * @return List of Client Request Stats
7921 * @hide
7922 */
7923 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007924 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7925 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007927 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007928 return null;
7929 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007930 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 final long identity = Binder.clearCallingIdentity();
7933 try {
7934 if (phone != null) {
7935 return phone.getClientRequestStats();
7936 }
7937
7938 return null;
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007942 }
7943
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007944 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007945 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007946 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007947 }
Jack Yueb4124c2017-02-16 15:32:43 -08007948
7949 /**
Grace Chen70990072017-03-24 17:21:30 -07007950 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007951 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007952 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007953 * @param state State of SIM (power down, power up, pass through)
7954 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7956 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007957 *
7958 **/
7959 @Override
Grace Chen70990072017-03-24 17:21:30 -07007960 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007961 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007962 Phone phone = PhoneFactory.getPhone(slotIndex);
7963
vagdeviaf9a5b92018-08-15 16:01:53 -07007964 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007969 phone.setSimPowerState(state, null, workSource);
7970 }
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
7974 }
7975
7976 /**
7977 * Set SIM card power state.
7978 *
7979 * @param slotIndex SIM slot id.
7980 * @param state State of SIM (power down, power up, pass through)
7981 * @param callback callback to trigger after success or failure
7982 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7983 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7984 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7985 *
7986 **/
7987 @Override
7988 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7989 IIntegerConsumer callback) {
7990 enforceModifyPermission();
7991 Phone phone = PhoneFactory.getPhone(slotIndex);
7992
7993 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7994
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 if (phone != null) {
7998 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7999 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 }
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008003 }
8004 }
Shuo Qiandd210312017-04-12 22:11:33 +00008005
Tyler Gunn65d45c22017-06-05 11:22:26 -07008006 private boolean isUssdApiAllowed(int subId) {
8007 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008008 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008009 if (configManager == null) {
8010 return false;
8011 }
8012 PersistableBundle pb = configManager.getConfigForSubId(subId);
8013 if (pb == null) {
8014 return false;
8015 }
8016 return pb.getBoolean(
8017 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8018 }
8019
Shuo Qiandd210312017-04-12 22:11:33 +00008020 /**
8021 * Check if phone is in emergency callback mode
8022 * @return true if phone is in emergency callback mode
8023 * @param subId sub id
8024 */
goneil9c5f4872017-12-05 14:07:56 -08008025 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008026 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008027 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 if (phone != null) {
8033 return phone.isInEcm();
8034 } else {
8035 return false;
8036 }
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008039 }
8040 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008041
8042 /**
8043 * Get the current signal strength information for the given subscription.
8044 * Because this information is not updated when the device is in a low power state
8045 * it should not be relied-upon to be current.
8046 * @param subId Subscription index
8047 * @return the most recent cached signal strength info from the modem
8048 */
8049 @Override
8050 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 Phone p = getPhone(subId);
8054 if (p == null) {
8055 return null;
8056 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 return p.getSignalStrength();
8059 } finally {
8060 Binder.restoreCallingIdentity(identity);
8061 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008062 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008063
Pengquan Meng77b7f132018-08-22 14:49:57 -07008064 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008065 * Get the current modem radio state for the given slot.
8066 * @param slotIndex slot index.
8067 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008068 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008069 * @return the current radio power state from the modem
8070 */
8071 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008072 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008073 Phone phone = PhoneFactory.getPhone(slotIndex);
8074 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8076 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008077 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8078 }
8079
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 return phone.getRadioPowerState();
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
8086 }
8087 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8088 }
8089
8090 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008091 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8092 *
8093 * <p>Requires one of the following permissions:
8094 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8095 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8096 * privileges.
8097 *
8098 * @param subId subscription id
8099 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8100 * {@code false}.
8101 */
8102 @Override
8103 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008104 try {
8105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8106 null);
8107 } catch (Exception e) {
8108 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8109 mApp, subId, "isDataRoamingEnabled");
8110 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008111
Pengquan Menga1bb6272018-09-06 09:59:22 -07008112 boolean isEnabled = false;
8113 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008114 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008115 Phone phone = getPhone(subId);
8116 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008119 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008120 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008121 }
8122
8123
8124 /**
8125 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8126 *
8127 * <p> Requires permission:
8128 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8129 * privileges.
8130 *
8131 * @param subId subscription id
8132 * @param isEnabled {@code true} means enable, {@code false} means disable.
8133 */
8134 @Override
8135 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8137 mApp, subId, "setDataRoamingEnabled");
8138
Pengquan Menga1bb6272018-09-06 09:59:22 -07008139 final long identity = Binder.clearCallingIdentity();
8140 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008141 Phone phone = getPhone(subId);
8142 if (phone != null) {
8143 phone.setDataRoamingEnabled(isEnabled);
8144 }
8145 } finally {
8146 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008147 }
8148 }
8149
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008150 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008151 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008152 TelephonyPermissions
8153 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008154 mApp, subId, "isManualNetworkSelectionAllowed");
8155
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008156 boolean isAllowed = true;
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008159 Phone phone = getPhone(subId);
8160 if (phone != null) {
8161 isAllowed = phone.isCspPlmnEnabled();
8162 }
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
8165 }
8166 return isAllowed;
8167 }
8168
8169 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008170 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008171 // Verify that tha callingPackage belongs to the calling UID
8172 mApp.getSystemService(AppOpsManager.class)
8173 .checkPackage(Binder.getCallingUid(), callingPackage);
8174
Jordan Liu1e142fc2019-04-22 15:10:43 -07008175 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008176 try {
8177 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008178 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008179 } catch (SecurityException e) {
8180 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8181 // has carrier privileges on an active UICC
8182 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8183 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008184 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008185 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008186 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008187
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008190 UiccController uiccController = UiccController.getInstance();
8191 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008192 if (hasReadPermission) {
8193 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008194 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008195
8196 // Remove private info if the caller doesn't have access
8197 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8198 for (UiccCardInfo cardInfo : cardInfos) {
8199 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8200 // is available
8201 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8202 if (card == null || card.getUiccProfile() == null) {
8203 // assume no access if the card or profile is unavailable
8204 filteredInfos.add(cardInfo.getUnprivileged());
8205 continue;
8206 }
8207 UiccProfile profile = card.getUiccProfile();
8208 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8209 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8210 filteredInfos.add(cardInfo);
8211 } else {
8212 filteredInfos.add(cardInfo.getUnprivileged());
8213 }
8214 }
8215 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008216 } finally {
8217 Binder.restoreCallingIdentity(identity);
8218 }
8219 }
8220
8221 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008222 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008223 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 final long identity = Binder.clearCallingIdentity();
8226 try {
8227 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8228 if (slots == null) {
8229 Rlog.i(LOG_TAG, "slots is null.");
8230 return null;
8231 }
8232
8233 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8234 for (int i = 0; i < slots.length; i++) {
8235 UiccSlot slot = slots[i];
8236 if (slot == null) {
8237 continue;
8238 }
8239
Jordan Liu7be7e652019-05-06 18:55:02 +00008240 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 UiccCard card = slot.getUiccCard();
8242 if (card != null) {
8243 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008244 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008245 cardId = slot.getEid();
8246 if (TextUtils.isEmpty(cardId)) {
8247 cardId = slot.getIccId();
8248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 }
8250
Jordan Liu857451f2019-05-09 16:35:35 -07008251 if (cardId != null) {
8252 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8253 // if cardId is an EID, it's all digits so this is fine
8254 cardId = IccUtils.stripTrailingFs(cardId);
8255 }
8256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 int cardState = 0;
8258 switch (slot.getCardState()) {
8259 case CARDSTATE_ABSENT:
8260 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8261 break;
8262 case CARDSTATE_PRESENT:
8263 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8264 break;
8265 case CARDSTATE_ERROR:
8266 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8267 break;
8268 case CARDSTATE_RESTRICTED:
8269 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8270 break;
8271 default:
8272 break;
8273
8274 }
8275
8276 infos[i] = new UiccSlotInfo(
8277 slot.isActive(),
8278 slot.isEuicc(),
8279 cardId,
8280 cardState,
8281 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008282 slot.isExtendedApduSupported(),
8283 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 }
8285 return infos;
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008288 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008289 }
8290
8291 @Override
8292 public boolean switchSlots(int[] physicalSlots) {
8293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008301 }
Jack Yu4c988042018-02-27 15:30:01 -08008302
8303 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008304 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008305 final long identity = Binder.clearCallingIdentity();
8306 try {
8307 return UiccController.getInstance().getCardIdForDefaultEuicc();
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
Pengquan Meng85728fb2018-03-12 16:31:21 -07008313 /**
goneil47ffb6e2018-04-06 15:40:58 -07008314 * A test API to reload the UICC profile.
8315 *
8316 * <p>Requires that the calling app has permission
8317 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8318 * @hide
8319 */
8320 @Override
8321 public void refreshUiccProfile(int subId) {
8322 enforceModifyPermission();
8323
8324 final long identity = Binder.clearCallingIdentity();
8325 try {
8326 Phone phone = getPhone(subId);
8327 if (phone == null) {
8328 return;
8329 }
8330 UiccCard uiccCard = phone.getUiccCard();
8331 if (uiccCard == null) {
8332 return;
8333 }
8334 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8335 if (uiccProfile == null) {
8336 return;
8337 }
8338 uiccProfile.refresh();
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008345 * Returns false if the mobile data is disabled by default, otherwise return true.
8346 */
8347 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008348 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008349 }
8350
8351 /**
8352 * Returns true if the data roaming is enabled by default, i.e the system property
8353 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8354 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8355 */
8356 private boolean getDefaultDataRoamingEnabled(int subId) {
8357 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008358 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008359 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008360 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8361 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8362 return isDataRoamingEnabled;
8363 }
8364
8365 /**
8366 * Returns the default network type for the given {@code subId}, if the default network type is
8367 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8368 */
8369 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008370 List<Integer> list = TelephonyProperties.default_network();
8371 int phoneId = mSubscriptionController.getPhoneId(subId);
8372 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8373 return list.get(phoneId);
8374 }
8375 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008376 }
fionaxua13278b2018-03-21 00:08:13 -07008377
8378 @Override
8379 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008380 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 final Phone phone = getPhone(subId);
8386 if (phone == null) {
8387 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8388 return;
8389 }
chen xueaba88a2019-03-15 13:15:10 -07008390 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8391 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008392 if (carrierPrivilegeRules == null) {
8393 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8394 } else {
8395 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 } finally {
8398 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008399 }
fionaxua13278b2018-03-21 00:08:13 -07008400 }
8401
8402 @Override
8403 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008404 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 final Phone phone = getPhone(subId);
8409 if (phone == null) {
8410 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8411 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8412 }
8413 return phone.getCarrierIdListVersion();
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008416 }
fionaxua13278b2018-03-21 00:08:13 -07008417 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008418
8419 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008420 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8421 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008423 mApp, subId, callingPackage, callingFeatureId,
8424 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008425 return -1;
8426 }
8427
8428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008435
8436 @Override
8437 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008438 TelephonyPermissions
8439 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008440 mApp, subId, "getCdmaRoamingMode");
8441
8442 final long identity = Binder.clearCallingIdentity();
8443 try {
8444 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
8448 }
8449
8450 @Override
8451 public boolean setCdmaRoamingMode(int subId, int mode) {
8452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8453 mApp, subId, "setCdmaRoamingMode");
8454
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
8460 }
8461 }
8462
8463 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008464 public int getCdmaSubscriptionMode(int subId) {
8465 TelephonyPermissions
8466 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8467 mApp, subId, "getCdmaSubscriptionMode");
8468
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 }
8476
8477 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008478 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8480 mApp, subId, "setCdmaSubscriptionMode");
8481
8482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
8488 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008489
sqianc5eccab2018-10-19 18:46:41 -07008490 @Override
sqian8c685422019-02-22 15:55:18 -08008491 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008492 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008494 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8495 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008496 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8497 }
8498 final long identity = Binder.clearCallingIdentity();
8499 try {
sqian854d44b2018-12-12 16:48:18 -08008500 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8501 for (Phone phone: PhoneFactory.getPhones()) {
8502 if (phone.getEmergencyNumberTracker() != null
8503 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8504 emergencyNumberListInternal.put(
8505 phone.getSubId(),
8506 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8507 }
sqian11b7a0e2018-12-05 18:48:28 -08008508 }
sqian854d44b2018-12-12 16:48:18 -08008509 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008510 } finally {
8511 Binder.restoreCallingIdentity(identity);
8512 }
sqianc5eccab2018-10-19 18:46:41 -07008513 }
8514
8515 @Override
sqian8c685422019-02-22 15:55:18 -08008516 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008517 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008518 if (!exactMatch) {
8519 TelephonyPermissions
8520 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008521 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008522 }
8523 final long identity = Binder.clearCallingIdentity();
8524 try {
sqian854d44b2018-12-12 16:48:18 -08008525 for (Phone phone: PhoneFactory.getPhones()) {
8526 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008527 && phone.getEmergencyNumberTracker()
8528 .isEmergencyNumber(number, exactMatch)) {
8529 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008530 }
sqian11b7a0e2018-12-05 18:48:28 -08008531 }
8532 return false;
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
8535 }
8536 }
8537
sqianf4ca7ed2019-01-15 18:32:07 -08008538 /**
8539 * Update emergency number list for test mode.
8540 */
8541 @Override
8542 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8544 "updateEmergencyNumberListTestMode");
8545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 for (Phone phone: PhoneFactory.getPhones()) {
8549 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8550 if (tracker != null) {
8551 tracker.executeEmergencyNumberTestModeCommand(action, num);
8552 }
8553 }
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
8557 }
8558
8559 /**
8560 * Get the full emergency number list for test mode.
8561 */
8562 @Override
8563 public List<String> getEmergencyNumberListTestMode() {
8564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8565 "getEmergencyNumberListTestMode");
8566
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 Set<String> emergencyNumbers = new HashSet<>();
8570 for (Phone phone: PhoneFactory.getPhones()) {
8571 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8572 if (tracker != null) {
8573 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8574 emergencyNumbers.add(num.getNumber());
8575 }
8576 }
8577 }
8578 return new ArrayList<>(emergencyNumbers);
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
8583
chen xud6b45bd2018-10-30 22:27:10 -07008584 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008585 public int getEmergencyNumberDbVersion(int subId) {
8586 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8587
8588 final long identity = Binder.clearCallingIdentity();
8589 try {
8590 final Phone phone = getPhone(subId);
8591 if (phone == null) {
8592 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8593 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8594 }
8595 return phone.getEmergencyNumberDbVersion();
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
8599 }
8600
8601 @Override
8602 public void notifyOtaEmergencyNumberDbInstalled() {
8603 enforceModifyPermission();
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 for (Phone phone: PhoneFactory.getPhones()) {
8608 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8609 if (tracker != null) {
8610 tracker.updateOtaEmergencyNumberDatabase();
8611 }
8612 }
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
8616 }
8617
8618 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008619 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008620 enforceActiveEmergencySessionPermission();
8621
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 for (Phone phone: PhoneFactory.getPhones()) {
8625 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8626 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008627 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8628 }
8629 }
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
8635 @Override
8636 public void resetOtaEmergencyNumberDbFilePath() {
8637 enforceActiveEmergencySessionPermission();
8638
8639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 for (Phone phone: PhoneFactory.getPhones()) {
8642 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8643 if (tracker != null) {
8644 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008645 }
8646 }
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
8650 }
8651
8652 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008653 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8654 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8655 Phone phone = getPhone(subId);
8656 if (phone == null) {
8657 return null;
8658 }
8659 final long identity = Binder.clearCallingIdentity();
8660 try {
8661 UiccProfile profile = UiccController.getInstance()
8662 .getUiccProfileForPhone(phone.getPhoneId());
8663 if (profile != null) {
8664 return profile.getCertsFromCarrierPrivilegeAccessRules();
8665 }
8666 } finally {
8667 Binder.restoreCallingIdentity(identity);
8668 }
8669 return null;
8670 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008671
8672 /**
8673 * Enable or disable a modem stack.
8674 */
8675 @Override
8676 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8677 enforceModifyPermission();
8678
8679 final long identity = Binder.clearCallingIdentity();
8680 try {
8681 Phone phone = PhoneFactory.getPhone(slotIndex);
8682 if (phone == null) {
8683 return false;
8684 } else {
8685 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8686 }
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
8690 }
Michelecea4cf22018-12-21 15:00:11 -08008691
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008692 /**
8693 * Whether a modem stack is enabled or not.
8694 */
8695 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008696 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8697 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008698 Phone phone = PhoneFactory.getPhone(slotIndex);
8699 if (phone == null) return false;
8700
8701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008702 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8703 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008704 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8705 }
8706
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008709 try {
8710 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8711 } catch (NoSuchElementException ex) {
8712 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8713 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
Michelecea4cf22018-12-21 15:00:11 -08008719 @Override
Michele0ea7d782019-03-19 14:58:42 -07008720 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008721 enforceModifyPermission();
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008726 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008727 .commit();
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
8733 @Override
Michele0ea7d782019-03-19 14:58:42 -07008734 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008735 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008737 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8738 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008739 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008740 }
Michelecea4cf22018-12-21 15:00:11 -08008741
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
Michele0ea7d782019-03-19 14:58:42 -07008744 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008745 } finally {
8746 Binder.restoreCallingIdentity(identity);
8747 }
8748 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008749
Michele0ea7d782019-03-19 14:58:42 -07008750 @TelephonyManager.IsMultiSimSupportedResult
8751 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008752 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8753 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8754 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008755 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8756 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008757 }
8758 // Check if the hardware supports multisim functionality. If usage of multisim is not
8759 // supported by the modem, indicate that it is restricted.
8760 PhoneCapability staticCapability =
8761 mPhoneConfigurationManager.getStaticPhoneCapability();
8762 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008763 loge("isMultiSimSupportedInternal: no static configuration available");
8764 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008765 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008766 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008767 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8768 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008769 }
8770 // Check if support of multiple SIMs is restricted by carrier
8771 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008772 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008773 }
8774
Michele0ea7d782019-03-19 14:58:42 -07008775 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008776 }
8777
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008778 /**
8779 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008780 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8781 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8782 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008783 * @param numOfSims number of active sims we want to switch to
8784 */
8785 @Override
8786 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008787 if (numOfSims == 1) {
8788 enforceModifyPermission();
8789 } else {
8790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8791 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8792 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008793 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008794
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008795 try {
Michele30b57b22019-03-01 12:01:14 -08008796 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008797 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008798 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8799 return;
8800 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008801 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008807 @Override
8808 public boolean isApplicationOnUicc(int subId, int appType) {
8809 enforceReadPrivilegedPermission("isApplicationOnUicc");
8810 Phone phone = getPhone(subId);
8811 if (phone == null) {
8812 return false;
8813 }
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 UiccCard uiccCard = phone.getUiccCard();
8817 if (uiccCard == null) {
8818 return false;
8819 }
8820 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8821 if (uiccProfile == null) {
8822 return false;
8823 }
8824 if (TelephonyManager.APPTYPE_SIM <= appType
8825 && appType <= TelephonyManager.APPTYPE_ISIM) {
8826 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8827 }
8828 return false;
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
8833
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008834 /**
chen xub4baa772019-04-03 10:23:41 -07008835 * Get whether making changes to modem configurations will trigger reboot.
8836 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008837 */
8838 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008839 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8840 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008842 mApp, subId, callingPackage, callingFeatureId,
8843 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008844 return false;
8845 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
8851 }
8852 }
8853
Nathan Harold29f5f052019-02-15 13:41:57 -08008854 private void updateModemStateMetrics() {
8855 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8856 // TODO: check the state for each modem if the api is ready.
8857 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8858 }
8859
Pengquan Meng3889a572019-01-23 11:16:29 -08008860 @Override
8861 public int[] getSlotsMapping() {
8862 enforceReadPrivilegedPermission("getSlotsMapping");
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8867 // All logical slots should have a mapping to a physical slot.
8868 int[] logicalSlotsMapping = new int[phoneCount];
8869 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8870 for (int i = 0; i < slotInfos.length; i++) {
8871 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8872 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8873 }
8874 }
8875 return logicalSlotsMapping;
8876 } finally {
8877 Binder.restoreCallingIdentity(identity);
8878 }
8879 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008880
8881 /**
8882 * Get the IRadio HAL Version
8883 */
8884 @Override
8885 public int getRadioHalVersion() {
8886 Phone phone = getDefaultPhone();
8887 if (phone == null) return -1;
8888 HalVersion hv = phone.getHalVersion();
8889 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8890 return hv.major * 100 + hv.minor;
8891 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008892
8893 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008894 * Get the current calling package name.
8895 * @return the current calling package name
8896 */
8897 @Override
8898 public String getCurrentPackageName() {
8899 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8900 }
8901
8902 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008903 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8904 * corresponding network requests on a subId.
8905 *
8906 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008907 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008908 * 2) APN is un-metered for this subscription, or
8909 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008910 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 *
8912 * @return whether data is allowed for a apn type.
8913 *
8914 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008915 */
8916 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008917 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008918 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8919 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008920
8921 // Now that all security checks passes, perform the operation as ourselves.
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 Phone phone = getPhone(subId);
8925 if (phone == null) return false;
8926
Jack Yu41407ee2019-05-13 16:54:09 -07008927 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008928 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
8932 }
8933
8934 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008935 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008936 enforceReadPrivilegedPermission("isApnMetered");
8937
8938 // Now that all security checks passes, perform the operation as ourselves.
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 Phone phone = getPhone(subId);
8942 if (phone == null) return true; // By default return true.
8943
Jack Yu41407ee2019-05-13 16:54:09 -07008944 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008945 } finally {
8946 Binder.restoreCallingIdentity(identity);
8947 }
8948 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008949
8950 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008951 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8952 int subscriptionId, IBooleanConsumer resultCallback) {
8953 enforceModifyPermission();
8954 long token = Binder.clearCallingIdentity();
8955 try {
8956 Phone phone = getPhone(subscriptionId);
8957 if (phone == null) {
8958 try {
8959 if (resultCallback != null) {
8960 resultCallback.accept(false);
8961 }
8962 } catch (RemoteException e) {
8963 // ignore
8964 }
8965 return;
8966 }
8967 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8968 Pair.create(specifiers, (x) -> {
8969 try {
8970 if (resultCallback != null) {
8971 resultCallback.accept(x);
8972 }
8973 } catch (RemoteException e) {
8974 // ignore
8975 }
8976 });
8977 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8978 } finally {
8979 Binder.restoreCallingIdentity(token);
8980 }
8981 }
8982
8983 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008984 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8985 TelephonyPermissions
8986 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8987 mApp, subId, "getSystemSelectionChannels");
8988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 List<RadioAccessSpecifier> specifiers =
8992 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8993 null, subId, workSource);
8994 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8995 return specifiers;
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009002 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009003 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009004 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9005 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9006 if (iccRecords == null) {
9007 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9008 return false;
9009 }
9010 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9011 }
9012
9013 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009014 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9015 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009016 if (callingPackage == null) {
9017 callingPackage = getCurrentPackageName();
9018 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009019 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9020 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009021 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9022 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009023 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9024 }
9025 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9026 Intent intent = new Intent();
9027 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9028 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9029 // Bring up choose default SMS subscription dialog right now
9030 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9031 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9032 mApp.startActivity(intent);
9033 }
chen xud5ca2d52019-05-28 15:20:57 -07009034
9035 @Override
9036 public String getMmsUAProfUrl(int subId) {
9037 //TODO investigate if this API should require proper permission check in R b/133791609
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009040 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9041 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9042 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9043 return carrierUAProfUrl;
9044 }
chen xud5ca2d52019-05-28 15:20:57 -07009045 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9046 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
9051
9052 @Override
9053 public String getMmsUserAgent(int subId) {
9054 //TODO investigate if this API should require proper permission check in R b/133791609
9055 final long identity = Binder.clearCallingIdentity();
9056 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009057 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9058 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9059 if (!TextUtils.isEmpty(carrierUserAgent)) {
9060 return carrierUserAgent;
9061 }
chen xud5ca2d52019-05-28 15:20:57 -07009062 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9063 .getString(com.android.internal.R.string.config_mms_user_agent);
9064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
9067 }
Jack Yub07d4972019-05-28 16:12:25 -07009068
9069 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009070 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9071 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 Phone phone = getPhone(subscriptionId);
9076 if (phone == null) return false;
9077
9078 switch (policy) {
9079 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9080 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9081 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9082 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9083 default:
9084 throw new IllegalArgumentException(policy + " is not a valid policy");
9085 }
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
9088 }
9089 }
9090
9091 @Override
9092 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9093 boolean enabled) {
9094 enforceModifyPermission();
9095
9096 final long identity = Binder.clearCallingIdentity();
9097 try {
9098 Phone phone = getPhone(subscriptionId);
9099 if (phone == null) return;
9100
9101 switch (policy) {
9102 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9103 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9104 break;
9105 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9106 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9107 break;
9108 default:
9109 throw new IllegalArgumentException(policy + " is not a valid policy");
9110 }
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 }
9115
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009116 /**
Hall Liub48cf452020-09-25 11:13:49 -07009117 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009118 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9119 * otherwise.
9120 */
9121 @Override
9122 public void setCepEnabled(boolean isCepEnabled) {
9123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9124
9125 final long identity = Binder.clearCallingIdentity();
9126 try {
9127 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9128 for (Phone phone : PhoneFactory.getPhones()) {
9129 Phone defaultPhone = phone.getImsPhone();
9130 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9131 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9132 ImsPhoneCallTracker imsPhoneCallTracker =
9133 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9134 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9135 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9136 + imsPhone.getMsisdn());
9137 }
9138 }
9139 } finally {
9140 Binder.restoreCallingIdentity(identity);
9141 }
9142 }
allenwtsu46dcc572020-01-08 18:24:03 +08009143
9144 /**
9145 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9146 *
9147 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9148 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9149 * before being read.
9150 */
9151 @Override
9152 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9153 isCompressed) {
9154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9155 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9157 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9158 }
9159 if (!isImsAvailableOnDevice()) {
9160 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9161 "IMS not available on device.");
9162 }
9163
9164 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009165 try {
Hui Wang068ab862020-10-31 05:12:53 +00009166 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009169 }
9170 }
zoey chenf95ca592019-12-30 16:11:23 +08009171
9172 @Override
9173 public boolean isIccLockEnabled(int subId) {
9174 enforceReadPrivilegedPermission("isIccLockEnabled");
9175
9176 // Now that all security checks passes, perform the operation as ourselves.
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 Phone phone = getPhone(subId);
9180 if (phone != null && phone.getIccCard() != null) {
9181 return phone.getIccCard().getIccLockEnabled();
9182 } else {
9183 return false;
9184 }
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
9189
9190 /**
zoey chene02881a2019-12-30 16:11:23 +08009191 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009192 *
zoey chene02881a2019-12-30 16:11:23 +08009193 * @return an integer representing the status of IccLock enabled or disabled in the following
9194 * three cases:
9195 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9196 * successfully.
9197 * - Positive number and zero for remaining password attempts.
9198 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009199 *
9200 */
9201 @Override
9202 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9203 enforceModifyPermission();
9204
9205 Phone phone = getPhone(subId);
9206 if (phone == null) {
9207 return 0;
9208 }
9209 // Now that all security checks passes, perform the operation as ourselves.
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9213 new Pair<Boolean, String>(enabled, password), phone, null);
9214 return attemptsRemaining;
9215
9216 } catch (Exception e) {
9217 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 return 0;
9222 }
9223
9224 /**
9225 * Change the ICC password used in ICC pin lock.
9226 *
zoey chene02881a2019-12-30 16:11:23 +08009227 * @return an integer representing the status of IccLock changed in the following three cases:
9228 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9229 * - Positive number and zero for remaining password attempts.
9230 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009231 *
9232 */
9233 @Override
9234 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9235 enforceModifyPermission();
9236
9237 Phone phone = getPhone(subId);
9238 if (phone == null) {
9239 return 0;
9240 }
9241 // Now that all security checks passes, perform the operation as ourselves.
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9245 new Pair<String, String>(oldPassword, newPassword), phone, null);
9246 return attemptsRemaining;
9247
9248 } catch (Exception e) {
9249 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 return 0;
9254 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009255
Peter Wangdafb9ac2020-01-15 14:13:38 -08009256 /**
9257 * Request for receiving user activity notification
9258 */
9259 @Override
9260 public void requestUserActivityNotification() {
9261 if (!mNotifyUserActivity.get()
9262 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9263 mNotifyUserActivity.set(true);
9264 }
9265 }
9266
9267 /**
9268 * Called when userActivity is signalled in the power manager.
9269 * This is safe to call from any thread, with any window manager locks held or not.
9270 */
9271 @Override
9272 public void userActivity() {
9273 // ***************************************
9274 // * Inherited from PhoneWindowManager *
9275 // ***************************************
9276 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9277 // WITH ITS LOCKS HELD.
9278 //
9279 // This code must be VERY careful about the locks
9280 // it acquires.
9281 // In fact, the current code acquires way too many,
9282 // and probably has lurking deadlocks.
9283
9284 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9285 throw new SecurityException("Only the OS may call notifyUserActivity()");
9286 }
9287
9288 if (mNotifyUserActivity.getAndSet(false)) {
9289 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9290 USER_ACTIVITY_NOTIFICATION_DELAY);
9291 }
9292 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009293
Malcolm Chen884180b2020-04-13 11:59:40 -07009294 @Override
9295 public boolean canConnectTo5GInDsdsMode() {
9296 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9297 }
Jack Yud10cdd42020-09-28 20:28:01 -07009298
9299 @Override
9300 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9301 String callingFeatureId) {
9302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9303 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9304 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9305 }
9306
9307 Phone phone = getPhone(subId);
9308 if (phone == null) {
9309 throw new RuntimeException("phone is not available");
9310 }
9311 // Now that all security checks passes, perform the operation as ourselves.
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
9314 return phone.getEquivalentHomePlmns();
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009319
Hui Wang0866fcc2020-10-12 12:14:23 -07009320 @Override
9321 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9322 UaSecurityProtocolIdentifier securityProtocol,
9323 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9324 throws RemoteException {
9325 enforceModifyPermission();
9326 if (DBG) {
9327 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9328 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9329 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9330 }
9331
9332 if (!SubscriptionManager.isValidSubscriptionId(subId)
9333 || appType < TelephonyManager.APPTYPE_UNKNOWN
9334 || appType > TelephonyManager.APPTYPE_ISIM
9335 || nafUrl == null || securityProtocol == null || callback == null) {
9336 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9337 if (callback != null) {
9338 try {
9339 callback.onAuthenticationFailure(
9340 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9341 } catch (RemoteException exception) {
9342 log("Fail to notify onAuthenticationFailure due to " + exception);
9343 }
9344 return;
9345 }
9346 }
9347
9348 final long token = Binder.clearCallingIdentity();
9349 try {
9350 getGbaManager(subId).bootstrapAuthenticationRequest(
9351 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9352 forceBootStrapping, callback));
9353 } finally {
9354 Binder.restoreCallingIdentity(token);
9355 }
9356 }
9357
Jack Nudelman24d51a52020-11-24 12:08:04 -08009358 /**
9359 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9360 * requested radio power state will actually be set. See {@link
9361 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9362 *
9363 * @param subId the subscription ID of the phone requesting to set the radio power state.
9364 * @param enable {@code true} if trying to turn radio on.
9365 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9366 * false}.
9367 */
9368 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9369 Phone phone = getPhone(subId);
9370 if (phone != null) {
9371 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9372 return true;
9373 }
9374 return false;
9375 }
9376
9377 private int handleDataThrottlingRequest(int subId,
9378 DataThrottlingRequest dataThrottlingRequest) {
9379 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9380 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9381 if (!setRadioPowerForThermal(subId, true)) {
9382 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9383 }
9384
9385 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9386
9387 int thermalMitigationResult =
9388 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9389 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9390 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9391 }
9392 return thermalMitigationResult;
9393 }
9394
9395 /**
9396 * Thermal mitigation request to control functionalities at modem.
9397 *
9398 * @param subId the id of the subscription.
9399 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9400 *
9401 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9402 */
9403 @Override
9404 @ThermalMitigationResult
9405 public int sendThermalMitigationRequest(
9406 int subId,
9407 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9408 enforceModifyPermission();
9409
9410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9411 final long identity = Binder.clearCallingIdentity();
9412
9413 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9414 try {
9415 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9416 switch (thermalMitigationAction) {
9417 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9418 thermalMitigationResult =
9419 handleDataThrottlingRequest(subId,
9420 thermalMitigationRequest.getDataThrottlingRequest());
9421 break;
9422 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9423 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9424 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9425 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9426 }
9427
9428 // Ensure that radio is on. If not able to power on due to phone being
9429 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9430 if (!setRadioPowerForThermal(subId, true)) {
9431 thermalMitigationResult =
9432 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9433 break;
9434 }
9435
9436 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9437 false);
9438 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9439 break;
9440 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9441 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9442 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9443 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9444 }
9445
9446 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9447 if (registry != null) {
9448 TelephonyConnectionService service =
9449 registry.getTelephonyConnectionService();
9450 Phone phone = getPhone(subId);
9451 if (phone == null) {
9452 thermalMitigationResult =
9453 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9454 break;
9455 }
9456
9457 if (PhoneConstantConversions.convertCallState(phone.getState())
9458 != TelephonyManager.CALL_STATE_IDLE
9459 || phone.isInEmergencySmsMode() || phone.isInEcm()
9460 || (service != null && service.isEmergencyCallPending())) {
9461 String errorMessage = "Phone state is not valid. call state = "
9462 + PhoneConstantConversions.convertCallState(phone.getState())
9463 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9464 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9465 errorMessage += service == null
9466 ? " TelephonyConnectionService is null"
9467 : " isEmergencyCallPending = "
9468 + service.isEmergencyCallPending();
9469 Log.e(LOG_TAG, errorMessage);
9470 thermalMitigationResult =
9471 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9472 break;
9473 }
9474 } else {
9475 thermalMitigationResult =
9476 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9477 break;
9478 }
9479
9480 // Turn radio off. If not able to power off due to phone being unavailable,
9481 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9482 if (!setRadioPowerForThermal(subId, false)) {
9483 thermalMitigationResult =
9484 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9485 break;
9486 }
9487 thermalMitigationResult =
9488 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9489 break;
9490 default:
9491 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9492 + "not exist. Requested action: " + thermalMitigationAction);
9493 }
9494 } catch (IllegalArgumentException e) {
9495 throw e;
9496 } catch (Exception e) {
9497 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9498 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9499 } finally {
9500 Binder.restoreCallingIdentity(identity);
9501 }
9502
9503 if (DBG) {
9504 log("thermalMitigationRequest returning with thermalMitigationResult: "
9505 + thermalMitigationResult);
9506 }
9507
9508 return thermalMitigationResult;
9509 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009510
9511 /**
9512 * Set the GbaService Package Name that Telephony will bind to.
9513 *
9514 * @param subId The sim that the GbaService is associated with.
9515 * @param packageName The name of the package to be replaced with.
9516 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9517 */
9518 @Override
9519 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9520 enforceModifyPermission();
9521
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 return getGbaManager(subId).overrideServicePackage(packageName);
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
9527 }
9528 }
9529
9530 /**
9531 * Return the package name of the currently bound GbaService.
9532 *
9533 * @param subId The sim that the GbaService is associated with.
9534 * @return the package name of the GbaService configuration, null if GBA is not supported.
9535 */
9536 @Override
9537 public String getBoundGbaService(int subId) {
9538 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9539
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
9542 return getGbaManager(subId).getServicePackage();
9543 } finally {
9544 Binder.restoreCallingIdentity(identity);
9545 }
9546 }
9547
9548 /**
9549 * Set the release time for telephony to unbind GbaService.
9550 *
9551 * @param subId The sim that the GbaService is associated with.
9552 * @param interval The release time to unbind GbaService by millisecond.
9553 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9554 */
9555 @Override
9556 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9557 enforceModifyPermission();
9558
9559 final long identity = Binder.clearCallingIdentity();
9560 try {
9561 return getGbaManager(subId).overrideReleaseTime(interval);
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 }
9566
9567 /**
9568 * Return the release time for telephony to unbind GbaService.
9569 *
9570 * @param subId The sim that the GbaService is associated with.
9571 * @return The release time to unbind GbaService by millisecond.
9572 */
9573 @Override
9574 public int getGbaReleaseTime(int subId) {
9575 enforceReadPrivilegedPermission("getGbaReleaseTime");
9576
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
9579 return getGbaManager(subId).getReleaseTime();
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
9585 private GbaManager getGbaManager(int subId) {
9586 GbaManager instance = GbaManager.getInstance(subId);
9587 if (instance == null) {
9588 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9589 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9590 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9591 }
9592 return instance;
9593 }
Hui Wang068ab862020-10-31 05:12:53 +00009594
9595 /**
9596 * indicate whether the device and the carrier can support
9597 * RCS VoLTE single registration.
9598 */
9599 @Override
9600 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9601 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9602
9603 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9604 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9605 }
9606
9607 final long identity = Binder.clearCallingIdentity();
9608 try {
9609 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9610 if (rpm != null) {
9611 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9612 }
9613 return false;
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 /**
9620 * Register RCS provisioning callback.
9621 */
9622 @Override
9623 public void registerRcsProvisioningChangedCallback(int subId,
9624 IRcsConfigCallback callback) {
9625 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9626
9627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9628 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9629 }
9630 if (!isImsAvailableOnDevice()) {
9631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9632 "IMS not available on device.");
9633 }
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009637 if (!RcsProvisioningMonitor.getInstance()
9638 .registerRcsProvisioningChangedCallback(subId, callback)) {
9639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9640 "Service not available for the subscription.");
9641 }
Hui Wang068ab862020-10-31 05:12:53 +00009642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 /**
9648 * Unregister RCS provisioning callback.
9649 */
9650 @Override
9651 public void unregisterRcsProvisioningChangedCallback(int subId,
9652 IRcsConfigCallback callback) {
9653 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9654
9655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9657 }
9658 if (!isImsAvailableOnDevice()) {
9659 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9660 "IMS not available on device.");
9661 }
9662
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009665 RcsProvisioningMonitor.getInstance()
9666 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671
9672 /**
9673 * trigger RCS reconfiguration.
9674 */
9675 public void triggerRcsReconfiguration(int subId) {
9676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9677 mApp, subId, "triggerRcsReconfiguration");
9678
9679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9680 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9681 }
9682 if (!isImsAvailableOnDevice()) {
9683 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9684 "IMS not available on device.");
9685 }
9686
9687 final long identity = Binder.clearCallingIdentity();
9688 try {
9689 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9690 } finally {
9691 Binder.restoreCallingIdentity(identity);
9692 }
9693 }
9694
9695 /**
9696 * Provide the client configuration parameters of the RCS application.
9697 */
9698 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9700 mApp, subId, "setRcsClientConfiguration");
9701
9702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9703 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9704 }
9705 if (!isImsAvailableOnDevice()) {
9706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9707 "IMS not available on device.");
9708 }
9709
9710 final long identity = Binder.clearCallingIdentity();
9711
9712 try {
9713 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9714 if (configBinder == null) {
9715 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9716 } else {
9717 configBinder.setRcsClientConfiguration(rcc);
9718 }
9719 } catch (RemoteException e) {
9720 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
9726 /**
9727 * Overrides the config of RCS VoLTE single registration enabled for the device.
9728 */
9729 @Override
9730 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9732 "setDeviceSingleRegistrationEnabledOverride");
9733 enforceModifyPermission();
9734
9735 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9736 : Boolean.parseBoolean(enabledStr);
9737 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9738 }
9739
9740 /**
9741 * Gets the config of RCS VoLTE single registration enabled for the device.
9742 */
9743 @Override
9744 public boolean getDeviceSingleRegistrationEnabled() {
9745 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9746 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9747 }
9748
9749 /**
9750 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9751 */
9752 @Override
9753 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9755 "setCarrierSingleRegistrationEnabledOverride");
9756 enforceModifyPermission();
9757
9758 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9759 : Boolean.parseBoolean(enabledStr);
9760 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9761 subId, enabled);
9762 }
9763
9764 /**
9765 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9766 */
9767 @Override
9768 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9769 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9770 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9771 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009772
9773 /**
9774 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9775 * their mobile plan.
9776 */
9777 @Override
9778 public String getMobileProvisioningUrl() {
9779 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 return getDefaultPhone().getMobileProvisioningUrl();
9783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009787
9788 @Override
9789 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9790 String callingPackage) {
9791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9792 mApp, subId, "setSignalStrengthUpdateRequest");
9793
9794 final int callingUid = Binder.getCallingUid();
9795 // Verify that tha callingPackage belongs to the calling UID
9796 mApp.getSystemService(AppOpsManager.class)
9797 .checkPackage(callingUid, callingPackage);
9798
9799 validateSignalStrengthUpdateRequest(request, callingUid);
9800
9801 final long identity = Binder.clearCallingIdentity();
9802 try {
9803 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9804 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9805
9806 if (result instanceof IllegalStateException) {
9807 throw (IllegalStateException) result;
9808 }
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 @Override
9815 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9816 String callingPackage) {
9817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9818 mApp, subId, "clearSignalStrengthUpdateRequest");
9819
9820 final int callingUid = Binder.getCallingUid();
9821 // Verify that tha callingPackage belongs to the calling UID
9822 mApp.getSystemService(AppOpsManager.class)
9823 .checkPackage(callingUid, callingPackage);
9824
9825 final long identity = Binder.clearCallingIdentity();
9826 try {
9827 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9828 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9829
9830 if (result instanceof IllegalStateException) {
9831 throw (IllegalStateException) result;
9832 }
9833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 }
9837
9838 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9839 int callingUid) {
9840 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9841 // phone/system process do not have further restriction on request
9842 return;
9843 }
9844
9845 // Applications has restrictions on how to use the request:
9846 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9847 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9848 // This is not system caller which has been checked above
9849 throw new IllegalArgumentException(
9850 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9851 }
9852
9853 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9854 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9855 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9856 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9857 || info.isEnabled()) {
9858 throw new IllegalArgumentException(
9859 "Only system can set hide fields in SignalThresholdInfo");
9860 }
9861
9862 // Thresholds length for each RAN need in range. This has been validated in
9863 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9864 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9865 final int[] thresholds = info.getThresholds();
9866 Objects.requireNonNull(thresholds);
9867 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9868 || thresholds.length
9869 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9870 throw new IllegalArgumentException(
9871 "thresholds length is out of range: " + thresholds.length);
9872 }
9873 }
9874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009875}