blob: d80efdd5876bd874bcadfdaca964add6692de8bb [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
Daniel Brightbb5840b2021-01-12 15:48:18 -08005559 /**
5560 * Sets the ims registration state on all valid {@link Phone}s.
5561 */
5562 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005567 // NOTE: Before S, this method only set the default phone.
5568 for (final Phone phone : PhoneFactory.getPhones()) {
5569 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5570 phone.setImsRegistrationState(registered);
5571 }
5572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Wink Saville36469e72014-06-11 15:17:00 -07005576 }
5577
5578 /**
Stuart Scott54788802015-03-30 13:18:01 -07005579 * Set the network selection mode to automatic.
5580 *
5581 */
5582 @Override
5583 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
5588 try {
shilufc958392020-01-20 11:36:01 -08005589 if (!isActiveSubscription(subId)) {
5590 return;
5591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5593 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Stuart Scott54788802015-03-30 13:18:01 -07005597 }
5598
Jack Yud10cdd42020-09-28 20:28:01 -07005599 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005600 * Ask the radio to connect to the input network and change selection mode to manual.
5601 *
5602 * @param subId the id of the subscription.
5603 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5604 * the operator to attach to.
5605 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5606 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5607 * normal network selection next time.
5608 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005609 */
5610 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005611 public boolean setNetworkSelectionModeManual(
5612 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005615
5616 if (!isActiveSubscription(subId)) {
5617 return false;
5618 }
5619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005622 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005624 if (DBG) {
5625 log("setNetworkSelectionModeManual: subId: " + subId
5626 + " operator: " + operatorInfo);
5627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005632 }
shilu84f6e8b2019-12-19 13:58:01 -08005633 /**
5634 * Get the manual network selection
5635 *
5636 * @param subId the id of the subscription.
5637 *
5638 * @return the previously saved user selected PLMN
5639 */
5640 @Override
5641 public String getManualNetworkSelectionPlmn(int subId) {
5642 TelephonyPermissions
5643 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5644 mApp, subId, "getManualNetworkSelectionPlmn");
5645
5646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 if (!isActiveSubscription(subId)) {
5649 return "";
5650 }
5651
5652 final Phone phone = getPhone(subId);
5653 if (phone == null) {
5654 return "";
5655 }
5656 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5657 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5658 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005663
5664 /**
5665 * Scans for available networks.
5666 */
5667 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005668 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5669 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5671 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005672 LocationAccessPolicy.LocationPermissionResult locationResult =
5673 LocationAccessPolicy.checkLocationPermission(mApp,
5674 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5675 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005676 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005677 .setCallingPid(Binder.getCallingPid())
5678 .setCallingUid(Binder.getCallingUid())
5679 .setMethod("getCellNetworkScanResults")
5680 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5681 .build());
5682 switch (locationResult) {
5683 case DENIED_HARD:
5684 throw new SecurityException("Not allowed to access scan results -- location");
5685 case DENIED_SOFT:
5686 return null;
5687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688
Pengquan Menga1bb6272018-09-06 09:59:22 -07005689 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 try {
5691 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005692 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005697 }
5698
5699 /**
sqian80370722020-01-29 15:02:51 -08005700 * Get the call forwarding info, given the call forwarding reason.
5701 */
5702 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005703 public void getCallForwarding(int subId, int callForwardingReason,
5704 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005705 enforceReadPrivilegedPermission("getCallForwarding");
5706 long identity = Binder.clearCallingIdentity();
5707 try {
5708 if (DBG) {
5709 log("getCallForwarding: subId " + subId
5710 + " callForwardingReason" + callForwardingReason);
5711 }
Hall Liua1acea22020-09-18 19:04:59 -07005712
5713 Phone phone = getPhone(subId);
5714 if (phone == null) {
5715 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005716 callback.onError(
5717 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005718 } catch (RemoteException e) {
5719 // ignore
5720 }
5721 return;
5722 }
5723
5724 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5725 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5726 @Override
5727 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5728 try {
5729 callback.onCallForwardingInfoAvailable(info);
5730 } catch (RemoteException e) {
5731 // ignore
5732 }
5733 }
5734
5735 @Override
5736 public void onError(int error) {
5737 try {
5738 callback.onError(error);
5739 } catch (RemoteException e) {
5740 // ignore
5741 }
5742 }
5743 });
5744 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
5748 }
5749
5750 /**
5751 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5752 * reason, the number to forward, and the timeout before the forwarding is attempted.
5753 */
5754 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005755 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5756 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005757 enforceModifyPermission();
5758 long identity = Binder.clearCallingIdentity();
5759 try {
5760 if (DBG) {
5761 log("setCallForwarding: subId " + subId
5762 + " callForwardingInfo" + callForwardingInfo);
5763 }
Hall Liua1acea22020-09-18 19:04:59 -07005764
5765 Phone phone = getPhone(subId);
5766 if (phone == null) {
5767 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005768 callback.accept(
5769 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005770 } catch (RemoteException e) {
5771 // ignore
5772 }
5773 return;
5774 }
5775
5776 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5777 FunctionalUtils.ignoreRemoteException(callback::accept));
5778
5779 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
5785 /**
Hall Liua1acea22020-09-18 19:04:59 -07005786 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005787 */
5788 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005789 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005790 enforceReadPrivilegedPermission("getCallForwarding");
5791 long identity = Binder.clearCallingIdentity();
5792 try {
Hall Liua1acea22020-09-18 19:04:59 -07005793
5794 Phone phone = getPhone(subId);
5795 if (phone == null) {
5796 try {
5797 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5798 } catch (RemoteException e) {
5799 // ignore
5800 }
5801 return;
5802 }
5803
5804 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5805
sqian80370722020-01-29 15:02:51 -08005806 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005807 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
5812
5813 /**
Hall Liua1acea22020-09-18 19:04:59 -07005814 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005815 */
5816 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005817 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005818 enforceModifyPermission();
5819 long identity = Binder.clearCallingIdentity();
5820 try {
Hall Liua1acea22020-09-18 19:04:59 -07005821 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5822
5823 Phone phone = getPhone(subId);
5824 if (phone == null) {
5825 try {
5826 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5827 } catch (RemoteException e) {
5828 // ignore
5829 }
5830 return;
5831 }
5832
5833 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5834 FunctionalUtils.ignoreRemoteException(callback::accept));
5835
5836 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
5840 }
5841
5842 /**
yinxub1bed742017-04-17 11:45:04 -07005843 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005844 *
yinxub1bed742017-04-17 11:45:04 -07005845 * @param subId id of the subscription
5846 * @param request contains the radio access networks with bands/channels to scan
5847 * @param messenger callback messenger for scan results or errors
5848 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005849 * @return the id of the requested scan which can be used to stop the scan.
5850 */
5851 @Override
5852 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005853 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5855 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005856 LocationAccessPolicy.LocationPermissionResult locationResult =
5857 LocationAccessPolicy.checkLocationPermission(mApp,
5858 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5859 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005860 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005861 .setCallingPid(Binder.getCallingPid())
5862 .setCallingUid(Binder.getCallingUid())
5863 .setMethod("requestNetworkScan")
5864 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5865 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005866 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005867 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5868 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005869 if (e != null) {
5870 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5871 throw e;
5872 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005873 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005874 return TelephonyScanManager.INVALID_SCAN_ID;
5875 }
5876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 }
Hall Liu912dfd32019-04-25 14:02:26 -07005878 int callingUid = Binder.getCallingUid();
5879 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 return mNetworkScanRequestTracker.startNetworkScan(
5883 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005884 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
yinxu504e1392017-04-12 16:03:22 -07005888 }
5889
Hall Liub2ac8ef2019-02-28 15:56:23 -08005890 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005891 NetworkScanRequest request, int subId, String callingPackage) {
5892 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005893 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5894 boolean hasNetworkScanPermission =
5895 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5896 == PERMISSION_GRANTED;
5897
5898 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5899 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5900 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005901 }
5902
5903 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5904 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005905 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5906 return new SecurityException("Specific channels must not be"
5907 + " scanned without location access.");
5908 }
5909 }
5910 }
5911
Hall Liub2ac8ef2019-02-28 15:56:23 -08005912 return null;
5913 }
5914
yinxu504e1392017-04-12 16:03:22 -07005915 /**
5916 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005917 *
5918 * @param subId id of the subscription
5919 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005920 */
5921 @Override
5922 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5924 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925
Hall Liu912dfd32019-04-25 14:02:26 -07005926 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 final long identity = Binder.clearCallingIdentity();
5928 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005929 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 } finally {
5931 Binder.restoreCallingIdentity(identity);
5932 }
yinxu504e1392017-04-12 16:03:22 -07005933 }
5934
5935 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005936 * Get the calculated preferred network type.
5937 * Used for debugging incorrect network type.
5938 *
5939 * @return the preferred network type, defined in RILConstants.java.
5940 */
5941 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005942 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005943 final Phone defaultPhone = getDefaultPhone();
5944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005945 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005946 return RILConstants.PREFERRED_NETWORK_MODE;
5947 }
5948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
5951 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005952 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Junda Liu84d15a22014-07-02 11:21:04 -07005956 }
5957
5958 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005959 * Get the preferred network type.
5960 * Used for device configuration by some CDMA operators.
5961 *
5962 * @return the preferred network type, defined in RILConstants.java.
5963 */
5964 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005965 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005966 TelephonyPermissions
5967 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5968 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969
5970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 if (DBG) log("getPreferredNetworkType");
5973 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5974 int networkType = (result != null ? result[0] : -1);
5975 if (DBG) log("getPreferredNetworkType: " + networkType);
5976 return networkType;
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005980 }
5981
5982 /**
5983 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005984 *
5985 * @param networkType the preferred network type, defined in RILConstants.java.
5986 * @return true on success; false on any failure.
5987 */
5988 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005989 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5991 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992
5993 final long identity = Binder.clearCallingIdentity();
5994 try {
calvinpan089c2a62020-03-12 14:17:55 +08005995 Boolean success = (Boolean) sendRequest(
5996 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005997
5998 if (success) {
5999 Settings.Global.putInt(mApp.getContentResolver(),
6000 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6001 }
calvinpan089c2a62020-03-12 14:17:55 +08006002 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6003 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 } finally {
6005 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006006 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006007 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006008
6009 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006010 * Get the allowed network types that store in the telephony provider.
6011 *
6012 * @param subId the id of the subscription.
6013 * @return allowedNetworkTypes the allowed network types.
6014 */
6015 @Override
6016 public long getAllowedNetworkTypes(int subId) {
6017 TelephonyPermissions
6018 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6019 mApp, subId, "getAllowedNetworkTypes");
6020
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 return SubscriptionManager.getLongSubscriptionProperty(
6024 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
6028 }
6029
6030 /**
6031 * Set the allowed network types.
6032 *
6033 * @param subId the id of the subscription.
6034 * @param allowedNetworkTypes the allowed network types.
6035 * @return true on success; false on any failure.
6036 */
6037 @Override
6038 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6040 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006041
calvinpan089c2a62020-03-12 14:17:55 +08006042 SubscriptionManager.setSubscriptionProperty(subId,
6043 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6044 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006045
calvinpan089c2a62020-03-12 14:17:55 +08006046 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6047 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6048 RILConstants.PREFERRED_NETWORK_MODE);
6049 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006050 }
6051
6052 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006053 * Get the allowed network types for certain reason.
6054 *
6055 * @param subId the id of the subscription.
6056 * @param reason the reason the allowed network type change is taking place
6057 * @return the allowed network types.
6058 */
6059 @Override
6060 public long getAllowedNetworkTypesForReason(int subId,
6061 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6062 TelephonyPermissions
6063 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6064 mApp, subId, "getAllowedNetworkTypesForReason");
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
6071 }
6072
6073 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006074 * Enable/Disable E-UTRA-NR Dual Connectivity
6075 * @param subId subscription id of the sim card
6076 * @param nrDualConnectivityState expected NR dual connectivity state
6077 * This can be passed following states
6078 * <ol>
6079 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6080 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6081 * <li>Disable NR dual connectivity and force secondary cell to be released
6082 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6083 * </ol>
6084 * @return operation result.
6085 */
6086 @Override
6087 public int setNrDualConnectivityState(int subId,
6088 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6090 mApp, subId, "enableNRDualConnectivity");
6091 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6095 nrDualConnectivityState, subId,
6096 workSource);
6097 if (DBG) log("enableNRDualConnectivity result: " + result);
6098 return result;
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
6103
6104 /**
6105 * Is E-UTRA-NR Dual Connectivity enabled
6106 * @return true if dual connectivity is enabled else false
6107 */
6108 @Override
6109 public boolean isNrDualConnectivityEnabled(int subId) {
6110 TelephonyPermissions
6111 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6112 mApp, subId, "isNRDualConnectivityEnabled");
6113 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6114 final long identity = Binder.clearCallingIdentity();
6115 try {
6116 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6117 null, subId, workSource);
6118 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6119 return isEnabled;
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
6123 }
6124
6125 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006126 * get carrier bandwidth per primary and secondary carrier
6127 * @param subId subscription id of the sim card
6128 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6129 */
6130 @Override
6131 public CarrierBandwidth getCarrierBandwidth(int subId) {
6132 TelephonyPermissions
6133 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6134 mApp, subId, "isNRDualConnectivityEnabled");
6135 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
6138 CarrierBandwidth carrierBandwidth =
6139 getPhoneFromSubId(subId).getCarrierBandwidth();
6140 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6141 return carrierBandwidth;
6142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
6145 }
6146
6147 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006148 * Get the effective allowed network types on the device.
6149 * This API will return an intersection of allowed network types for all reasons,
6150 * including the configuration done through setAllowedNetworkTypes
6151 *
6152 * @param subId the id of the subscription.
6153 * @return the allowed network types
6154 */
6155 @Override
6156 public long getEffectiveAllowedNetworkTypes(int subId) {
6157 TelephonyPermissions
6158 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6159 mApp, subId, "getEffectiveAllowedNetworkTypes");
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
6166 }
6167
6168 /**
6169 * Set the allowed network types of the device and
6170 * provide the reason triggering the allowed network change.
6171 *
6172 * @param subId the id of the subscription.
6173 * @param reason the reason the allowed network type change is taking place
6174 * @param allowedNetworkTypes the allowed network types.
6175 * @return true on success; false on any failure.
6176 */
6177 @Override
6178 public boolean setAllowedNetworkTypesForReason(int subId,
6179 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6181 mApp, subId, "setAllowedNetworkTypesForReason");
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6185 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6186 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6187 RILConstants.PREFERRED_NETWORK_MODE);
6188 return setPreferredNetworkType(subId, preferredNetworkMode);
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
Miaoa84611c2019-03-15 09:21:10 +08006195 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006196 *
Miaoa84611c2019-03-15 09:21:10 +08006197 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006198 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006199 * @hide
6200 */
6201 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006202 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006205 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 try {
Miaoa84611c2019-03-15 09:21:10 +08006207 if (phone != null) {
6208 return phone.hasMatchedTetherApnSetting();
6209 } else {
6210 return false;
6211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 } finally {
6213 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006214 }
Junda Liu475951f2014-11-07 16:45:03 -08006215 }
6216
6217 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006218 * Enable or disable always reporting signal strength changes from radio.
6219 *
6220 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6221 */
6222 @Override
6223 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6224 enforceModifyPermission();
6225 enforceSystemCaller();
6226
6227 final long identity = Binder.clearCallingIdentity();
6228 final Phone phone = getPhone(subId);
6229 try {
6230 if (phone != null) {
6231 if (DBG) {
6232 log("setAlwaysReportSignalStrength: subId=" + subId
6233 + " isEnable=" + isEnable);
6234 }
6235 phone.setAlwaysReportSignalStrength(isEnable);
6236 } else {
6237 loge("setAlwaysReportSignalStrength: no phone found for subId="
6238 + subId);
6239 }
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
6243 }
6244
6245 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006246 * Get the user enabled state of Mobile Data.
6247 *
6248 * TODO: remove and use isUserDataEnabled.
6249 * This can't be removed now because some vendor codes
6250 * calls through ITelephony directly while they should
6251 * use TelephonyManager.
6252 *
6253 * @return true on enabled
6254 */
6255 @Override
6256 public boolean getDataEnabled(int subId) {
6257 return isUserDataEnabled(subId);
6258 }
6259
6260 /**
6261 * Get whether mobile data is enabled per user setting.
6262 *
6263 * There are other factors deciding whether mobile data is actually enabled, but they are
6264 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006265 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006266 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006267 *
6268 * @return {@code true} if data is enabled else {@code false}
6269 */
6270 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006271 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006272 try {
6273 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6274 null);
6275 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6277 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279
6280 final long identity = Binder.clearCallingIdentity();
6281 try {
6282 int phoneId = mSubscriptionController.getPhoneId(subId);
6283 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6284 Phone phone = PhoneFactory.getPhone(phoneId);
6285 if (phone != null) {
6286 boolean retVal = phone.isUserDataEnabled();
6287 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6288 return retVal;
6289 } else {
6290 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6291 return false;
6292 }
6293 } finally {
6294 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006295 }
6296 }
6297
6298 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006299 * Checks if the device is capable of mobile data by considering whether whether the
6300 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6301 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006302 *
Shuo Qian985d1232020-01-08 14:30:06 -08006303 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006304 */
6305 @Override
6306 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006307 try {
6308 try {
6309 mApp.enforceCallingOrSelfPermission(
6310 android.Manifest.permission.ACCESS_NETWORK_STATE,
6311 null);
6312 } catch (Exception e) {
6313 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6314 "isDataEnabled");
6315 }
6316 } catch (Exception e) {
6317 enforceReadPrivilegedPermission("isDataEnabled");
6318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
6320 final long identity = Binder.clearCallingIdentity();
6321 try {
6322 int phoneId = mSubscriptionController.getPhoneId(subId);
6323 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6324 Phone phone = PhoneFactory.getPhone(phoneId);
6325 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006326 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6328 return retVal;
6329 } else {
6330 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6331 return false;
6332 }
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006335 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006336 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006337
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006338 /**
6339 * Check if data is enabled for a specific reason
6340 * @param subId Subscription index
6341 * @param reason the reason the data enable change is taking place
6342 * @return {@code true} if the overall data is enabled; {@code false} if not.
6343 */
6344 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006345 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006346 @TelephonyManager.DataEnabledReason int reason) {
6347 try {
6348 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6349 null);
6350 } catch (Exception e) {
6351 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006353 }
6354
6355
6356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 int phoneId = mSubscriptionController.getPhoneId(subId);
6359 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006360 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006361 + " reason=" + reason);
6362 }
6363 Phone phone = PhoneFactory.getPhone(phoneId);
6364 if (phone != null) {
6365 boolean retVal;
6366 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6367 retVal = phone.isUserDataEnabled();
6368 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006369 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006370 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006371 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006372 return retVal;
6373 } else {
6374 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006375 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006376 + subId + " retVal=false");
6377 }
6378 return false;
6379 }
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006385 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006386 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006387 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6388 // Skip the check if it's one of these special uids
6389 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6390 }
6391
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006392 //load access rules from carrier configs, and check those as well: b/139133814
6393 SubscriptionController subController = SubscriptionController.getInstance();
6394 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6395 || subController == null) return privilegeFromSim;
6396
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006397 PackageManager pkgMgr = phone.getContext().getPackageManager();
6398 String[] packages = pkgMgr.getPackagesForUid(uid);
6399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006402 int subId = phone.getSubId();
6403 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6404 // A test override is in place for the privileges for this subId, so don't try to
6405 // read the subscription privileges.
6406 return privilegeFromSim;
6407 }
6408 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006409 SubscriptionManager subManager = (SubscriptionManager)
6410 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6411 for (String pkg : packages) {
6412 if (subManager.canManageSubscription(subInfo, pkg)) {
6413 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6414 }
6415 }
6416 return privilegeFromSim;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
6420 }
6421
6422 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6423 String pkgName) {
6424 //load access rules from carrier configs, and check those as well: b/139133814
6425 SubscriptionController subController = SubscriptionController.getInstance();
6426 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6427 || subController == null) return privilegeFromSim;
6428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006431 int subId = phone.getSubId();
6432 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6433 // A test override is in place for the privileges for this subId, so don't try to
6434 // read the subscription privileges.
6435 return privilegeFromSim;
6436 }
6437 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006438 SubscriptionManager subManager = (SubscriptionManager)
6439 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6440 return subManager.canManageSubscription(subInfo, pkgName)
6441 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
6445 }
6446
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006448 public int getCarrierPrivilegeStatus(int subId) {
6449 final Phone phone = getPhone(subId);
6450 if (phone == null) {
6451 loge("getCarrierPrivilegeStatus: Invalid subId");
6452 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6453 }
6454 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006455 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006456 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006457 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6458 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006459
6460 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6461 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006462 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006463 }
Junda Liu29340342014-07-10 15:23:27 -07006464
6465 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006466 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006467 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006468 final Phone phone = getPhone(subId);
6469 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006470 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006471 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6472 }
6473 UiccProfile profile =
6474 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6475 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006476 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006477 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6478 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006479 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006480 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006481 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006482 }
6483
6484 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006485 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6486 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006487 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006488 }
6489
6490 int phoneId = SubscriptionManager.getPhoneId(subId);
6491 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006492 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006493 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006494 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6495 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006496 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6497 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6498 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006499 }
6500
6501 @Override
6502 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006503 if (TextUtils.isEmpty(pkgName))
6504 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006505 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6506 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6507 UiccCard card = UiccController.getInstance().getUiccCard(i);
6508 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006509 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006510 continue;
6511 }
6512
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006513 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6514 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6515 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006516 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6517 break;
6518 }
6519 }
6520
6521 return result;
Junda Liu29340342014-07-10 15:23:27 -07006522 }
Derek Tan89e89d42014-07-08 17:00:10 -07006523
6524 @Override
Junda Liue64de782015-04-16 17:19:16 -07006525 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6526 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6527 loge("phoneId " + phoneId + " is not valid.");
6528 return null;
6529 }
6530 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006531 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006532 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006533 return null ;
6534 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006535 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006536 }
6537
Amith Yamasani6e118872016-02-19 12:53:51 -08006538 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006539 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006540 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006541 List<String> privilegedPackages = new ArrayList<>();
6542 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006543 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6544 // has UICC in that slot.
6545 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006546 if (card.hasCarrierPrivilegeRules()) {
6547 if (packages == null) {
6548 // Only check packages in user 0 for now
6549 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006550 PackageManager.MATCH_DISABLED_COMPONENTS
6551 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006552 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006553 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006554 }
6555 for (int p = packages.size() - 1; p >= 0; p--) {
6556 PackageInfo pkgInfo = packages.get(p);
6557 if (pkgInfo != null && pkgInfo.packageName != null
6558 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006559 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006560 privilegedPackages.add(pkgInfo.packageName);
6561 }
6562 }
6563 }
6564 }
6565 return privilegedPackages;
6566 }
6567
chen xuf7e9fe82019-05-09 19:31:02 -07006568 @Override
6569 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006570 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6571
6572 final long identity = Binder.clearCallingIdentity();
6573
chen xuf7e9fe82019-05-09 19:31:02 -07006574 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006575 try {
6576 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6577 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6578 }
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006581 }
6582 return privilegedPackages;
6583 }
6584
Wink Savilleb564aae2014-10-23 10:18:09 -07006585 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006586 final Phone phone = getPhone(subId);
6587 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006588 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006589 return null;
6590 }
6591 String iccId = card.getIccId();
6592 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006593 return null;
6594 }
6595 return iccId;
6596 }
6597
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006598 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006599 public void setCallComposerStatus(int subId, int status) {
6600 enforceModifyPermission();
6601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 Phone phone = getPhone(subId);
6605 if (phone != null) {
6606 Phone defaultPhone = phone.getImsPhone();
6607 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6608 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6609 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006610 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6611 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006612 }
6613 }
Shuo Qiand8782462020-12-22 19:10:14 -08006614 } catch (ImsException e) {
6615 throw new ServiceSpecificException(e.getCode());
6616 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006617 Binder.restoreCallingIdentity(identity);
6618 }
6619 }
6620
6621 @Override
6622 public int getCallComposerStatus(int subId) {
6623 enforceReadPrivilegedPermission("getCallComposerStatus");
6624
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 Phone phone = getPhone(subId);
6628 if (phone != null) {
6629 Phone defaultPhone = phone.getImsPhone();
6630 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6631 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6632 return imsPhone.getCallComposerStatus();
6633 }
6634 }
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
6638 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6639 }
6640
6641 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006642 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6643 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006644 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006645 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 final String iccId = getIccId(subId);
6650 final Phone phone = getPhone(subId);
6651 if (phone == null) {
6652 return false;
6653 }
6654 final String subscriberId = phone.getSubscriberId();
6655
6656 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006657 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 + subscriberId + " to " + number);
6659 }
6660
6661 if (TextUtils.isEmpty(iccId)) {
6662 return false;
6663 }
6664
6665 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6666
6667 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6668 if (alphaTag == null) {
6669 editor.remove(alphaTagPrefKey);
6670 } else {
6671 editor.putString(alphaTagPrefKey, alphaTag);
6672 }
6673
6674 // Record both the line number and IMSI for this ICCID, since we need to
6675 // track all merged IMSIs based on line number
6676 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6677 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6678 if (number == null) {
6679 editor.remove(numberPrefKey);
6680 editor.remove(subscriberPrefKey);
6681 } else {
6682 editor.putString(numberPrefKey, number);
6683 editor.putString(subscriberPrefKey, subscriberId);
6684 }
6685
6686 editor.commit();
6687 return true;
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006690 }
Derek Tan7226c842014-07-02 17:42:23 -07006691 }
6692
6693 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006694 public String getLine1NumberForDisplay(int subId, String callingPackage,
6695 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006696 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006698 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006699 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006700 return null;
6701 }
Derek Tan97ebb422014-09-05 16:55:38 -07006702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 String iccId = getIccId(subId);
6706 if (iccId != null) {
6707 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6708 if (DBG_MERGE) {
6709 log("getLine1NumberForDisplay returning "
6710 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6711 }
6712 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6715 return null;
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006718 }
Derek Tan7226c842014-07-02 17:42:23 -07006719 }
6720
6721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006722 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006725 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006726 return null;
6727 }
Derek Tan97ebb422014-09-05 16:55:38 -07006728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 final long identity = Binder.clearCallingIdentity();
6730 try {
6731 String iccId = getIccId(subId);
6732 if (iccId != null) {
6733 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6734 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6735 }
6736 return null;
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006739 }
Derek Tan7226c842014-07-02 17:42:23 -07006740 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006741
6742 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006743 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6744 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006745 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6746 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006748 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006749 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006750 return null;
6751 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006752
Jordan Liub49b04b2019-05-06 14:45:15 -07006753 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6754 // the process, where TelephonyManager was instantiated.
6755 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006756 final long identity = Binder.clearCallingIdentity();
6757 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006758 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 final TelephonyManager tele = TelephonyManager.from(context);
6760 final SubscriptionManager sub = SubscriptionManager.from(context);
6761
6762 // Figure out what subscribers are currently active
6763 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764
Jordan Liub49b04b2019-05-06 14:45:15 -07006765 // Only consider subs which match the current subId
6766 // This logic can be simplified. See b/131189269 for progress.
6767 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006768 activeSubscriberIds.add(tele.getSubscriberId(subId));
6769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770
6771 // First pass, find a number override for an active subscriber
6772 String mergeNumber = null;
6773 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6774 for (String key : prefs.keySet()) {
6775 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6776 final String subscriberId = (String) prefs.get(key);
6777 if (activeSubscriberIds.contains(subscriberId)) {
6778 final String iccId = key.substring(
6779 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6780 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6781 mergeNumber = (String) prefs.get(numberKey);
6782 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006783 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 + " for active subscriber " + subscriberId);
6785 }
6786 if (!TextUtils.isEmpty(mergeNumber)) {
6787 break;
6788 }
6789 }
6790 }
6791 }
6792
6793 // Shortcut when no active merged subscribers
6794 if (TextUtils.isEmpty(mergeNumber)) {
6795 return null;
6796 }
6797
6798 // Second pass, find all subscribers under that line override
6799 final ArraySet<String> result = new ArraySet<>();
6800 for (String key : prefs.keySet()) {
6801 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6802 final String number = (String) prefs.get(key);
6803 if (mergeNumber.equals(number)) {
6804 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6805 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6806 final String subscriberId = (String) prefs.get(subscriberKey);
6807 if (!TextUtils.isEmpty(subscriberId)) {
6808 result.add(subscriberId);
6809 }
6810 }
6811 }
6812 }
6813
6814 final String[] resultArray = result.toArray(new String[result.size()]);
6815 Arrays.sort(resultArray);
6816 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006817 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6819 }
6820 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006821 } finally {
6822 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006823 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006824 }
6825
6826 @Override
zoey chen38003472019-12-13 17:16:31 +08006827 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6828 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006829
6830 final long identity = Binder.clearCallingIdentity();
6831 try {
6832 final TelephonyManager telephonyManager = mApp.getSystemService(
6833 TelephonyManager.class);
6834 String subscriberId = telephonyManager.getSubscriberId(subId);
6835 if (subscriberId == null) {
6836 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006837 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006838 + subId);
6839 }
6840 return null;
6841 }
6842
6843 final SubscriptionInfo info = SubscriptionController.getInstance()
6844 .getSubscriptionInfo(subId);
6845 final ParcelUuid groupUuid = info.getGroupUuid();
6846 // If it doesn't belong to any group, return just subscriberId of itself.
6847 if (groupUuid == null) {
6848 return new String[]{subscriberId};
6849 }
6850
6851 // Get all subscriberIds from the group.
6852 final List<String> mergedSubscriberIds = new ArrayList<>();
6853 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006854 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006855 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006856 for (SubscriptionInfo subInfo : groupInfos) {
6857 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6858 if (subscriberId != null) {
6859 mergedSubscriberIds.add(subscriberId);
6860 }
6861 }
6862
6863 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866
6867 }
6868 }
6869
6870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006871 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006872 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006873 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874
6875 final long identity = Binder.clearCallingIdentity();
6876 try {
6877 final Phone phone = getPhone(subId);
6878 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006882 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006883
6884 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006885 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006886 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6887 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006888 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6889 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890
6891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 final Phone phone = getPhone(subId);
6894 if (phone == null) {
6895 return false;
6896 }
6897 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6898 cdmaNonRoamingList);
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006901 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006902 }
6903
6904 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006905 @Deprecated
6906 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6907 enforceModifyPermission();
6908
6909 int returnValue = 0;
6910 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006911 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006912 if(result.exception == null) {
6913 if (result.result != null) {
6914 byte[] responseData = (byte[])(result.result);
6915 if(responseData.length > oemResp.length) {
6916 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6917 responseData.length + "bytes. Buffer Size is " +
6918 oemResp.length + "bytes.");
6919 }
6920 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6921 returnValue = responseData.length;
6922 }
6923 } else {
6924 CommandException ex = (CommandException) result.exception;
6925 returnValue = ex.getCommandError().ordinal();
6926 if(returnValue > 0) returnValue *= -1;
6927 }
6928 } catch (RuntimeException e) {
6929 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6930 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6931 if(returnValue > 0) returnValue *= -1;
6932 }
6933
6934 return returnValue;
6935 }
6936
6937 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006938 public void setRadioCapability(RadioAccessFamily[] rafs) {
6939 try {
6940 ProxyController.getInstance().setRadioCapability(rafs);
6941 } catch (RuntimeException e) {
6942 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6943 }
6944 }
6945
6946 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006947 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006948 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006949 try {
6950 TelephonyPermissions
6951 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6952 mApp, phone.getSubId(), "getRadioAccessFamily");
6953 } catch (SecurityException e) {
6954 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6955 throw e;
6956 }
chen xub97461a2018-10-26 14:17:57 -07006957 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006958 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006959 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 final long identity = Binder.clearCallingIdentity();
6962 try {
chen xub97461a2018-10-26 14:17:57 -07006963 TelephonyPermissions
6964 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6965 mApp, phone.getSubId(), "getRadioAccessFamily");
6966 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
chen xub97461a2018-10-26 14:17:57 -07006970 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006971 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006972
6973 @Override
6974 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006975 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977
6978 final long identity = Binder.clearCallingIdentity();
6979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006980 ImsManager.getInstance(defaultPhone.getContext(),
6981 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 } finally {
6983 Binder.restoreCallingIdentity(identity);
6984 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006985 }
6986
6987 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006988 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006989 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6991 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006992 return false;
6993 }
Svet Ganovb320e182015-04-16 12:30:10 -07006994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 // Check the user preference and the system-level IMS setting. Even if the user has
6998 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6999 // In the long run, we may instead need to check if there exists a connection service
7000 // which can support video calling.
7001 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007002 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 return imsManager.isVtEnabledByPlatform()
7004 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7005 && imsManager.isVtEnabledByUser();
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007009 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007010
Andrew Leea1239f22015-03-02 17:44:07 -08007011 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007012 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7013 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007015 mApp, subId, callingPackage, callingFeatureId,
7016 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 return false;
7018 }
7019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 CarrierConfigManager configManager =
7023 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007024 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Andrew Leea1239f22015-03-02 17:44:07 -08007029 }
7030
7031 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007032 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007034 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 return false;
7036 }
7037
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
7040 CarrierConfigManager configManager =
7041 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007042 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
Andrew Leea1239f22015-03-02 17:44:07 -08007047 }
7048
Andrew Lee9431b832015-03-09 18:46:45 -07007049 @Override
7050 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007051 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007052 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007053 }
7054
7055 @Override
7056 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 final long identity = Binder.clearCallingIdentity();
7058 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007059 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
Andrew Lee9431b832015-03-09 18:46:45 -07007063 }
7064
Hall Liuf6668912018-10-31 17:05:23 -07007065 /**
7066 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7067 * support for the feature and device firmware support.
7068 *
7069 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7070 */
7071 @Override
7072 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007074 final Phone phone = getPhone(subscriptionId);
7075 if (phone == null) {
7076 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7077 return false;
7078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007080 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7082 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007083 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 return isCarrierSupported && isDeviceSupported;
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Hall Liu98187582018-01-22 19:15:32 -08007088 }
7089
Hall Liuf6668912018-10-31 17:05:23 -07007090 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007091 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7092 * RTT setting, will return true if the device and carrier both support RTT.
7093 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007094 */
7095 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 final long identity = Binder.clearCallingIdentity();
7097 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007098 boolean isRttSupported = isRttSupported(subscriptionId);
7099 boolean isUserRttSettingOn = Settings.Secure.getInt(
7100 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7101 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7102 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7103 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007107 }
7108
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 @Deprecated
7110 @Override
7111 public String getDeviceId(String callingPackage) {
7112 return getDeviceIdWithFeature(callingPackage, null);
7113 }
7114
Sanket Padawe7310cc72015-01-14 09:53:20 -08007115 /**
7116 * Returns the unique device ID of phone, for example, the IMEI for
7117 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7118 *
7119 * <p>Requires Permission:
7120 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7121 */
7122 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007123 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007124 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007125 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007126 return null;
7127 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007128 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007129 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007130 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007131 return null;
7132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
7134 final long identity = Binder.clearCallingIdentity();
7135 try {
7136 return phone.getDeviceId();
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007140 }
7141
Ping Sunc67b7c22016-03-02 19:16:45 +08007142 /**
7143 * {@hide}
7144 * Returns the IMS Registration Status on a particular subid
7145 *
7146 * @param subId
7147 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007148 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007149 Phone phone = getPhone(subId);
7150 if (phone != null) {
7151 return phone.isImsRegistered();
7152 } else {
7153 return false;
7154 }
7155 }
7156
Santos Cordon7a1885b2015-02-03 11:15:19 -08007157 @Override
7158 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 final long identity = Binder.clearCallingIdentity();
7160 try {
7161 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007165 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007166
Tyler Gunnf70ed162019-04-03 15:28:53 -07007167 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007168 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007169 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007171 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007172 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7173 }
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007183 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007184 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7185 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 Phone phone = getPhone(subscriptionId);
7189 if (phone == null) {
7190 return null;
7191 }
7192 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7193 } finally {
7194 Binder.restoreCallingIdentity(identity);
7195 }
7196 }
7197
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007198 /**
7199 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007200 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007201 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 Phone phone = getPhone(subId);
7205 if (phone != null) {
7206 return phone.isWifiCallingEnabled();
7207 } else {
7208 return false;
7209 }
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007212 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007213 }
7214
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007215 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007216 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007217 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007218 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 Phone phone = getPhone(subId);
7222 if (phone != null) {
7223 return phone.isVideoEnabled();
7224 } else {
7225 return false;
7226 }
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007229 }
7230 }
7231
7232 /**
7233 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7234 * defined in {@link ImsRegistrationImplBase}.
7235 */
7236 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 Phone phone = getPhone(subId);
7240 if (phone != null) {
7241 return phone.getImsRegistrationTech();
7242 } else {
7243 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7244 }
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007247 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007248 }
7249
Stuart Scott8eef64f2015-04-08 15:13:54 -07007250 @Override
7251 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007252 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007253 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7254 return;
7255 }
7256
Svet Ganovcc087f82015-05-12 20:35:54 -07007257 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007258
Svet Ganovcc087f82015-05-12 20:35:54 -07007259 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007260 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7261 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007262 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007263 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007264 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007265 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007266 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7267 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007268 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007269 // There has been issues when Sms raw table somehow stores orphan
7270 // fragments. They lead to garbled message when new fragments come
7271 // in and combined with those stale ones. In case this happens again,
7272 // user can reset all network settings which will clean up this table.
7273 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007274 // Clean up IMS settings as well here.
7275 int slotId = getSlotIndex(subId);
7276 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7277 ImsManager.getInstance(mApp, slotId).factoryReset();
7278 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007279
7280 // Erase modem config if erase modem on network setting is enabled.
7281 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7282 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7283 if (configValue != null && Boolean.parseBoolean(configValue)) {
7284 sendEraseModemConfig(getDefaultPhone());
7285 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007288 }
7289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007290
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007291 private void cleanUpSmsRawTable(Context context) {
7292 ContentResolver resolver = context.getContentResolver();
7293 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7294 resolver.delete(uri, null, null);
7295 }
7296
Narayan Kamath1c496c22015-04-16 14:40:19 +01007297 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007298 public String getSimLocaleForSubscriber(int subId) {
7299 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7300 final Phone phone = getPhone(subId);
7301 if (phone == null) {
7302 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007303 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
chen xu5d3637b2019-01-21 23:31:38 -08007307 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007308 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007309 if (info == null) {
7310 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7311 return null;
7312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 // Try and fetch the locale from the carrier properties or from the SIM language
7314 // preferences (EF-PL and EF-LI)...
7315 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007317 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7318 if (localeFromDefaultSim != null) {
7319 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7320 if (DBG) log("Using locale from subId: " + subId + " locale: "
7321 + localeFromDefaultSim);
7322 return localeFromDefaultSim.toLanguageTag();
7323 } else {
7324 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 }
7326 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 // The SIM language preferences only store a language (e.g. fr = French), not an
7329 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7330 // the SIM and carrier preferences does not include a country we add the country
7331 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007332 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007334 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 return mccLocale.toLanguageTag();
7336 }
7337
7338 if (DBG) log("No locale found - returning null");
7339 return null;
7340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007343 }
7344
7345 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007346 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007347 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007348 }
7349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 /**
7351 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7352 */
7353 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007354 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007355 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007356 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007357
Chenjie Yu1ba97252018-01-11 18:16:20 -08007358 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007359 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007360
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007361 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007362 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7363 * representing the state of the modem.
7364 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007365 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7366 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007367 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007368 */
7369 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007370 public void requestModemActivityInfo(ResultReceiver result) {
7371 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
sqian1a1be542020-03-05 11:37:28 -08007376 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 } finally {
7378 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007379 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007380 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007381
Siddharth Rayb8114062018-06-17 15:02:38 -07007382 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7383 // less than total activity duration.
7384 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7385 if (info == null) {
7386 return false;
7387 }
7388 int activityDurationMs =
7389 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7390 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007391 int[] txTimeMs = info.getTransmitTimeMillis();
7392 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7393 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007394 }
7395 return (info.isValid()
7396 && (info.getSleepTimeMillis() <= activityDurationMs)
7397 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007398 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007399 && (totalTxTimeMs <= activityDurationMs));
7400 }
7401
Jack Yu85bd38a2015-11-09 11:34:32 -08007402 /**
7403 * {@hide}
7404 * Returns the service state information on specified subscription.
7405 */
7406 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007407 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7408 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007410 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007411 return null;
7412 }
7413
Hall Liuf19c44f2018-11-27 14:38:17 -08007414 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7415 LocationAccessPolicy.checkLocationPermission(mApp,
7416 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7417 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007418 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007419 .setCallingPid(Binder.getCallingPid())
7420 .setCallingUid(Binder.getCallingUid())
7421 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007422 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007423 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7424 .build());
7425
7426 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7427 LocationAccessPolicy.checkLocationPermission(mApp,
7428 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7429 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007430 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007431 .setCallingPid(Binder.getCallingPid())
7432 .setCallingUid(Binder.getCallingUid())
7433 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007434 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007435 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7436 .build());
7437 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7438 boolean hasFinePermission =
7439 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7440 boolean hasCoarsePermission =
7441 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007445 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7446 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7447 Rlog.d(LOG_TAG,
7448 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7449 return null;
7450 }
7451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 final Phone phone = getPhone(subId);
7453 if (phone == null) {
7454 return null;
7455 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007456
Hall Liuf19c44f2018-11-27 14:38:17 -08007457 ServiceState ss = phone.getServiceState();
7458
7459 // Scrub out the location info in ServiceState depending on what level of access
7460 // the caller has.
7461 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007462 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7463 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007467 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007468
7469 /**
7470 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7471 *
7472 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7473 * voicemail ringtone.
7474 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7475 * PhoneAccount.
7476 */
7477 @Override
7478 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 final long identity = Binder.clearCallingIdentity();
7480 try {
7481 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7482 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007490 }
7491
7492 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007493 * Sets the per-account voicemail ringtone.
7494 *
7495 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7496 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7497 *
7498 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7499 * voicemail ringtone.
7500 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7501 * PhoneAccount.
7502 */
7503 @Override
7504 public void setVoicemailRingtoneUri(String callingPackage,
7505 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007506 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007507 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007508 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7509 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7511 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7512 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514
7515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7518 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007519 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 }
7521 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7522 } finally {
7523 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007524 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007525 }
7526
7527 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007528 * Returns whether vibration is set for voicemail notification in Phone settings.
7529 *
7530 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7531 * voicemail vibration setting.
7532 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7533 */
7534 @Override
7535 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7539 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007547 }
7548
Youhan Wange64578a2016-05-02 15:32:42 -07007549 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007550 * Sets the per-account voicemail vibration.
7551 *
7552 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7553 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7554 *
7555 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7556 * voicemail vibration setting.
7557 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7558 * specific PhoneAccount.
7559 */
7560 @Override
7561 public void setVoicemailVibrationEnabled(String callingPackage,
7562 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007564 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007565 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7566 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7568 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7569 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007570 }
7571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 final long identity = Binder.clearCallingIdentity();
7573 try {
7574 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7575 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007576 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 }
7578 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7579 } finally {
7580 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007581 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007582 }
7583
7584 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007585 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7586 *
7587 * @throws SecurityException if the caller does not have the required permission
7588 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007589 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007590 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007591 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007592 }
7593
7594 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007595 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7596 * permission.
7597 *
7598 * @throws SecurityException if the caller does not have the required permission
7599 */
7600 private void enforceSendSmsPermission() {
7601 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7602 }
7603
7604 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007605 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007606 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007607 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007608 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007609 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007613 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 if (componentName == null) {
7615 throw new SecurityException(
7616 "Caller not current active visual voicemail package[null]");
7617 }
7618 String vvmPackage = componentName.getPackageName();
7619 if (!callingPackage.equals(vvmPackage)) {
7620 throw new SecurityException("Caller not current active visual voicemail package["
7621 + vvmPackage + "]");
7622 }
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007625 }
7626 }
7627
7628 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007629 * Return the application ID for the app type.
7630 *
7631 * @param subId the subscription ID that this request applies to.
7632 * @param appType the uicc app type.
7633 * @return Application ID for specificied app type, or null if no uicc.
7634 */
7635 @Override
7636 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007637 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007638 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639
7640 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007641 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 if (phone == null) {
7643 return null;
7644 }
7645 String aid = null;
7646 try {
7647 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7648 .getApplicationByType(appType).getAid();
7649 } catch (Exception e) {
7650 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7651 }
7652 return aid;
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007655 }
Youhan Wange64578a2016-05-02 15:32:42 -07007656 }
7657
Youhan Wang4001d252016-05-11 10:29:41 -07007658 /**
7659 * Return the Electronic Serial Number.
7660 *
7661 * @param subId the subscription ID that this request applies to.
7662 * @return ESN or null if error.
7663 */
7664 @Override
7665 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007666 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007667 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668
7669 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007670 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 if (phone == null) {
7672 return null;
7673 }
7674 String esn = null;
7675 try {
7676 esn = phone.getEsn();
7677 } catch (Exception e) {
7678 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7679 }
7680 return esn;
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007683 }
Youhan Wang4001d252016-05-11 10:29:41 -07007684 }
7685
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007686 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007687 * Return the Preferred Roaming List Version.
7688 *
7689 * @param subId the subscription ID that this request applies to.
7690 * @return PRLVersion or null if error.
7691 */
7692 @Override
7693 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007694 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007695 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696
7697 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007698 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 if (phone == null) {
7700 return null;
7701 }
7702 String cdmaPrlVersion = null;
7703 try {
7704 cdmaPrlVersion = phone.getCdmaPrlVersion();
7705 } catch (Exception e) {
7706 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7707 }
7708 return cdmaPrlVersion;
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007711 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007712 }
7713
7714 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007715 * Get snapshot of Telephony histograms
7716 * @return List of Telephony histograms
7717 * @hide
7718 */
7719 @Override
7720 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7722 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723
7724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 return RIL.getTelephonyRILTimingHistograms();
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007730 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007731
7732 /**
7733 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007734 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7735 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007736 * Require system privileges. In the future we may add this to carrier APIs.
7737 *
Michele Berionne482f8202018-11-27 18:57:59 -08007738 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007739 */
7740 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007741 @TelephonyManager.SetCarrierRestrictionResult
7742 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007743 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007745
Michele Berionne482f8202018-11-27 18:57:59 -08007746 if (carrierRestrictionRules == null) {
7747 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007748 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 final long identity = Binder.clearCallingIdentity();
7751 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007752 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007753 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007757 }
7758
7759 /**
7760 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007761 * Get the allowed carrier list and the excluded carrier list, including the priority between
7762 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007763 * Require system privileges. In the future we may add this to carrier APIs.
7764 *
Michele Berionne482f8202018-11-27 18:57:59 -08007765 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007766 */
7767 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007768 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007769 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771
7772 final long identity = Binder.clearCallingIdentity();
7773 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007774 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7775 if (response instanceof CarrierRestrictionRules) {
7776 return (CarrierRestrictionRules) response;
7777 }
7778 // Response is an Exception of some kind,
7779 // which is signalled to the user as a NULL retval
7780 return null;
7781 } catch (Exception e) {
7782 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7783 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007787 }
7788
fionaxu59545b42016-05-25 15:53:37 -07007789 /**
fionaxu59545b42016-05-25 15:53:37 -07007790 * Action set from carrier signalling broadcast receivers to enable/disable radio
7791 * @param subId the subscription ID that this action applies to.
7792 * @param enabled control enable or disable radio.
7793 * {@hide}
7794 */
7795 @Override
7796 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7797 enforceModifyPermission();
7798 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799
7800 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007801 if (phone == null) {
7802 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7803 return;
7804 }
7805 try {
7806 phone.carrierActionSetRadioEnabled(enabled);
7807 } catch (Exception e) {
7808 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 } finally {
7810 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007811 }
7812 }
7813
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007814 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007815 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7816 * network status based on which carrier apps could apply actions accordingly,
7817 * enable/disable default url handler for example.
7818 *
7819 * @param subId the subscription ID that this action applies to.
7820 * @param report control start/stop reporting the default network status.
7821 * {@hide}
7822 */
7823 @Override
7824 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7825 enforceModifyPermission();
7826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827
7828 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007829 if (phone == null) {
7830 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7831 return;
7832 }
7833 try {
7834 phone.carrierActionReportDefaultNetworkStatus(report);
7835 } catch (Exception e) {
7836 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 } finally {
7838 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007839 }
7840 }
7841
7842 /**
fionaxud9622282017-07-17 17:51:30 -07007843 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7844 * @param subId the subscription ID that this action applies to.
7845 * {@hide}
7846 */
7847 @Override
7848 public void carrierActionResetAll(int subId) {
7849 enforceModifyPermission();
7850 final Phone phone = getPhone(subId);
7851 if (phone == null) {
7852 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7853 return;
7854 }
7855 try {
7856 phone.carrierActionResetAll();
7857 } catch (Exception e) {
7858 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7859 }
7860 }
7861
7862 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007863 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7864 * bug report is being generated.
7865 */
7866 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007867 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007868 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7869 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007870 writer.println("Permission Denial: can't dump Phone from pid="
7871 + Binder.getCallingPid()
7872 + ", uid=" + Binder.getCallingUid()
7873 + "without permission "
7874 + android.Manifest.permission.DUMP);
7875 return;
7876 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007877 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007878 }
Jack Yueb89b242016-06-22 13:27:47 -07007879
Brad Ebingerdac2f002018-04-03 15:17:52 -07007880 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007881 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7882 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7883 @NonNull String[] args) {
7884 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7885 this, in.getFileDescriptor(), out.getFileDescriptor(),
7886 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007887 }
7888
Jack Yueb89b242016-06-22 13:27:47 -07007889 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007890 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007891 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007892 * @param reason the reason the data enable change is taking place
7893 * @param enabled True if enabling the data, otherwise disabling.
7894 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007895 */
7896 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007897 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007898 boolean enabled) {
7899 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7900 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7901 try {
7902 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007903 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007904 } catch (SecurityException se) {
7905 enforceModifyPermission();
7906 }
7907 } else {
7908 enforceModifyPermission();
7909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910
7911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 Phone phone = getPhone(subId);
7914 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007915 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7916 phone.carrierActionSetMeteredApnsEnabled(enabled);
7917 } else {
7918 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 }
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007923 }
7924 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007925
7926 /**
7927 * Get Client request stats
7928 * @return List of Client Request Stats
7929 * @hide
7930 */
7931 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007932 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7933 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007935 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007936 return null;
7937 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007938 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 if (phone != null) {
7943 return phone.getClientRequestStats();
7944 }
7945
7946 return null;
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007950 }
7951
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007952 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007954 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007955 }
Jack Yueb4124c2017-02-16 15:32:43 -08007956
7957 /**
Grace Chen70990072017-03-24 17:21:30 -07007958 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007959 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007960 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007961 * @param state State of SIM (power down, power up, pass through)
7962 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7963 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7964 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007965 *
7966 **/
7967 @Override
Grace Chen70990072017-03-24 17:21:30 -07007968 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007969 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007970 Phone phone = PhoneFactory.getPhone(slotIndex);
7971
vagdeviaf9a5b92018-08-15 16:01:53 -07007972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007977 phone.setSimPowerState(state, null, workSource);
7978 }
7979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
7982 }
7983
7984 /**
7985 * Set SIM card power state.
7986 *
7987 * @param slotIndex SIM slot id.
7988 * @param state State of SIM (power down, power up, pass through)
7989 * @param callback callback to trigger after success or failure
7990 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7991 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7992 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7993 *
7994 **/
7995 @Override
7996 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7997 IIntegerConsumer callback) {
7998 enforceModifyPermission();
7999 Phone phone = PhoneFactory.getPhone(slotIndex);
8000
8001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8002
8003 final long identity = Binder.clearCallingIdentity();
8004 try {
8005 if (phone != null) {
8006 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8007 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 }
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008011 }
8012 }
Shuo Qiandd210312017-04-12 22:11:33 +00008013
Tyler Gunn65d45c22017-06-05 11:22:26 -07008014 private boolean isUssdApiAllowed(int subId) {
8015 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008016 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008017 if (configManager == null) {
8018 return false;
8019 }
8020 PersistableBundle pb = configManager.getConfigForSubId(subId);
8021 if (pb == null) {
8022 return false;
8023 }
8024 return pb.getBoolean(
8025 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8026 }
8027
Shuo Qiandd210312017-04-12 22:11:33 +00008028 /**
8029 * Check if phone is in emergency callback mode
8030 * @return true if phone is in emergency callback mode
8031 * @param subId sub id
8032 */
goneil9c5f4872017-12-05 14:07:56 -08008033 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008034 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008035 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008036 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 if (phone != null) {
8041 return phone.isInEcm();
8042 } else {
8043 return false;
8044 }
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008047 }
8048 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008049
8050 /**
8051 * Get the current signal strength information for the given subscription.
8052 * Because this information is not updated when the device is in a low power state
8053 * it should not be relied-upon to be current.
8054 * @param subId Subscription index
8055 * @return the most recent cached signal strength info from the modem
8056 */
8057 @Override
8058 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 Phone p = getPhone(subId);
8062 if (p == null) {
8063 return null;
8064 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 return p.getSignalStrength();
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008070 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008071
Pengquan Meng77b7f132018-08-22 14:49:57 -07008072 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008073 * Get the current modem radio state for the given slot.
8074 * @param slotIndex slot index.
8075 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008076 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008077 * @return the current radio power state from the modem
8078 */
8079 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008080 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008081 Phone phone = PhoneFactory.getPhone(slotIndex);
8082 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8084 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008085 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8086 }
8087
8088 final long identity = Binder.clearCallingIdentity();
8089 try {
8090 return phone.getRadioPowerState();
8091 } finally {
8092 Binder.restoreCallingIdentity(identity);
8093 }
8094 }
8095 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8096 }
8097
8098 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008099 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8100 *
8101 * <p>Requires one of the following permissions:
8102 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8103 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8104 * privileges.
8105 *
8106 * @param subId subscription id
8107 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8108 * {@code false}.
8109 */
8110 @Override
8111 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008112 try {
8113 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8114 null);
8115 } catch (Exception e) {
8116 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8117 mApp, subId, "isDataRoamingEnabled");
8118 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008119
Pengquan Menga1bb6272018-09-06 09:59:22 -07008120 boolean isEnabled = false;
8121 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008122 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008123 Phone phone = getPhone(subId);
8124 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008127 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008128 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008129 }
8130
8131
8132 /**
8133 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8134 *
8135 * <p> Requires permission:
8136 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8137 * privileges.
8138 *
8139 * @param subId subscription id
8140 * @param isEnabled {@code true} means enable, {@code false} means disable.
8141 */
8142 @Override
8143 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8145 mApp, subId, "setDataRoamingEnabled");
8146
Pengquan Menga1bb6272018-09-06 09:59:22 -07008147 final long identity = Binder.clearCallingIdentity();
8148 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008149 Phone phone = getPhone(subId);
8150 if (phone != null) {
8151 phone.setDataRoamingEnabled(isEnabled);
8152 }
8153 } finally {
8154 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008155 }
8156 }
8157
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008158 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008159 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008160 TelephonyPermissions
8161 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008162 mApp, subId, "isManualNetworkSelectionAllowed");
8163
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008164 boolean isAllowed = true;
8165 final long identity = Binder.clearCallingIdentity();
8166 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008167 Phone phone = getPhone(subId);
8168 if (phone != null) {
8169 isAllowed = phone.isCspPlmnEnabled();
8170 }
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
8174 return isAllowed;
8175 }
8176
8177 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008178 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008179 // Verify that tha callingPackage belongs to the calling UID
8180 mApp.getSystemService(AppOpsManager.class)
8181 .checkPackage(Binder.getCallingUid(), callingPackage);
8182
Jordan Liu1e142fc2019-04-22 15:10:43 -07008183 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008184 try {
8185 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008186 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008187 } catch (SecurityException e) {
8188 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8189 // has carrier privileges on an active UICC
8190 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8191 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008192 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008193 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008194 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008195
8196 final long identity = Binder.clearCallingIdentity();
8197 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008198 UiccController uiccController = UiccController.getInstance();
8199 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008200 if (hasReadPermission) {
8201 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008202 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008203
8204 // Remove private info if the caller doesn't have access
8205 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8206 for (UiccCardInfo cardInfo : cardInfos) {
8207 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8208 // is available
8209 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8210 if (card == null || card.getUiccProfile() == null) {
8211 // assume no access if the card or profile is unavailable
8212 filteredInfos.add(cardInfo.getUnprivileged());
8213 continue;
8214 }
8215 UiccProfile profile = card.getUiccProfile();
8216 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8217 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8218 filteredInfos.add(cardInfo);
8219 } else {
8220 filteredInfos.add(cardInfo.getUnprivileged());
8221 }
8222 }
8223 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
8227 }
8228
8229 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008230 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008231 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8236 if (slots == null) {
8237 Rlog.i(LOG_TAG, "slots is null.");
8238 return null;
8239 }
8240
8241 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8242 for (int i = 0; i < slots.length; i++) {
8243 UiccSlot slot = slots[i];
8244 if (slot == null) {
8245 continue;
8246 }
8247
Jordan Liu7be7e652019-05-06 18:55:02 +00008248 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 UiccCard card = slot.getUiccCard();
8250 if (card != null) {
8251 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008252 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008253 cardId = slot.getEid();
8254 if (TextUtils.isEmpty(cardId)) {
8255 cardId = slot.getIccId();
8256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 }
8258
Jordan Liu857451f2019-05-09 16:35:35 -07008259 if (cardId != null) {
8260 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8261 // if cardId is an EID, it's all digits so this is fine
8262 cardId = IccUtils.stripTrailingFs(cardId);
8263 }
8264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 int cardState = 0;
8266 switch (slot.getCardState()) {
8267 case CARDSTATE_ABSENT:
8268 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8269 break;
8270 case CARDSTATE_PRESENT:
8271 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8272 break;
8273 case CARDSTATE_ERROR:
8274 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8275 break;
8276 case CARDSTATE_RESTRICTED:
8277 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8278 break;
8279 default:
8280 break;
8281
8282 }
8283
8284 infos[i] = new UiccSlotInfo(
8285 slot.isActive(),
8286 slot.isEuicc(),
8287 cardId,
8288 cardState,
8289 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008290 slot.isExtendedApduSupported(),
8291 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 }
8293 return infos;
8294 } finally {
8295 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008296 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008297 }
8298
8299 @Override
8300 public boolean switchSlots(int[] physicalSlots) {
8301 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302
8303 final long identity = Binder.clearCallingIdentity();
8304 try {
8305 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008309 }
Jack Yu4c988042018-02-27 15:30:01 -08008310
8311 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008312 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 return UiccController.getInstance().getCardIdForDefaultEuicc();
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
8319 }
8320
Pengquan Meng85728fb2018-03-12 16:31:21 -07008321 /**
goneil47ffb6e2018-04-06 15:40:58 -07008322 * A test API to reload the UICC profile.
8323 *
8324 * <p>Requires that the calling app has permission
8325 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8326 * @hide
8327 */
8328 @Override
8329 public void refreshUiccProfile(int subId) {
8330 enforceModifyPermission();
8331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 Phone phone = getPhone(subId);
8335 if (phone == null) {
8336 return;
8337 }
8338 UiccCard uiccCard = phone.getUiccCard();
8339 if (uiccCard == null) {
8340 return;
8341 }
8342 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8343 if (uiccProfile == null) {
8344 return;
8345 }
8346 uiccProfile.refresh();
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
8351
8352 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008353 * Returns false if the mobile data is disabled by default, otherwise return true.
8354 */
8355 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008356 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008357 }
8358
8359 /**
8360 * Returns true if the data roaming is enabled by default, i.e the system property
8361 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8362 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8363 */
8364 private boolean getDefaultDataRoamingEnabled(int subId) {
8365 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008366 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008367 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008368 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8369 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8370 return isDataRoamingEnabled;
8371 }
8372
8373 /**
8374 * Returns the default network type for the given {@code subId}, if the default network type is
8375 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8376 */
8377 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008378 List<Integer> list = TelephonyProperties.default_network();
8379 int phoneId = mSubscriptionController.getPhoneId(subId);
8380 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8381 return list.get(phoneId);
8382 }
8383 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008384 }
fionaxua13278b2018-03-21 00:08:13 -07008385
8386 @Override
8387 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008388 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008389 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 final Phone phone = getPhone(subId);
8394 if (phone == null) {
8395 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8396 return;
8397 }
chen xueaba88a2019-03-15 13:15:10 -07008398 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8399 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008400 if (carrierPrivilegeRules == null) {
8401 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8402 } else {
8403 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405 } finally {
8406 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008407 }
fionaxua13278b2018-03-21 00:08:13 -07008408 }
8409
8410 @Override
8411 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008412 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413
8414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 final Phone phone = getPhone(subId);
8417 if (phone == null) {
8418 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8419 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8420 }
8421 return phone.getCarrierIdListVersion();
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008424 }
fionaxua13278b2018-03-21 00:08:13 -07008425 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008426
8427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008428 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8429 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008431 mApp, subId, callingPackage, callingFeatureId,
8432 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008433 return -1;
8434 }
8435
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008443
8444 @Override
8445 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008446 TelephonyPermissions
8447 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008448 mApp, subId, "getCdmaRoamingMode");
8449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
8457
8458 @Override
8459 public boolean setCdmaRoamingMode(int subId, int mode) {
8460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8461 mApp, subId, "setCdmaRoamingMode");
8462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
8471 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008472 public int getCdmaSubscriptionMode(int subId) {
8473 TelephonyPermissions
8474 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8475 mApp, subId, "getCdmaSubscriptionMode");
8476
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
8484
8485 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008486 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8488 mApp, subId, "setCdmaSubscriptionMode");
8489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
8496 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008497
sqianc5eccab2018-10-19 18:46:41 -07008498 @Override
sqian8c685422019-02-22 15:55:18 -08008499 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008500 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008502 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8503 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008504 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8505 }
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
sqian854d44b2018-12-12 16:48:18 -08008508 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8509 for (Phone phone: PhoneFactory.getPhones()) {
8510 if (phone.getEmergencyNumberTracker() != null
8511 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8512 emergencyNumberListInternal.put(
8513 phone.getSubId(),
8514 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8515 }
sqian11b7a0e2018-12-05 18:48:28 -08008516 }
sqian854d44b2018-12-12 16:48:18 -08008517 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
sqianc5eccab2018-10-19 18:46:41 -07008521 }
8522
8523 @Override
sqian8c685422019-02-22 15:55:18 -08008524 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008525 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008526 if (!exactMatch) {
8527 TelephonyPermissions
8528 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008529 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008530 }
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
sqian854d44b2018-12-12 16:48:18 -08008533 for (Phone phone: PhoneFactory.getPhones()) {
8534 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008535 && phone.getEmergencyNumberTracker()
8536 .isEmergencyNumber(number, exactMatch)) {
8537 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008538 }
sqian11b7a0e2018-12-05 18:48:28 -08008539 }
8540 return false;
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
8543 }
8544 }
8545
sqianf4ca7ed2019-01-15 18:32:07 -08008546 /**
8547 * Update emergency number list for test mode.
8548 */
8549 @Override
8550 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8552 "updateEmergencyNumberListTestMode");
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 for (Phone phone: PhoneFactory.getPhones()) {
8557 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8558 if (tracker != null) {
8559 tracker.executeEmergencyNumberTestModeCommand(action, num);
8560 }
8561 }
8562 } finally {
8563 Binder.restoreCallingIdentity(identity);
8564 }
8565 }
8566
8567 /**
8568 * Get the full emergency number list for test mode.
8569 */
8570 @Override
8571 public List<String> getEmergencyNumberListTestMode() {
8572 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8573 "getEmergencyNumberListTestMode");
8574
8575 final long identity = Binder.clearCallingIdentity();
8576 try {
8577 Set<String> emergencyNumbers = new HashSet<>();
8578 for (Phone phone: PhoneFactory.getPhones()) {
8579 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8580 if (tracker != null) {
8581 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8582 emergencyNumbers.add(num.getNumber());
8583 }
8584 }
8585 }
8586 return new ArrayList<>(emergencyNumbers);
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
8589 }
8590 }
8591
chen xud6b45bd2018-10-30 22:27:10 -07008592 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008593 public int getEmergencyNumberDbVersion(int subId) {
8594 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8595
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 final Phone phone = getPhone(subId);
8599 if (phone == null) {
8600 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8601 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8602 }
8603 return phone.getEmergencyNumberDbVersion();
8604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
8607 }
8608
8609 @Override
8610 public void notifyOtaEmergencyNumberDbInstalled() {
8611 enforceModifyPermission();
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 for (Phone phone: PhoneFactory.getPhones()) {
8616 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8617 if (tracker != null) {
8618 tracker.updateOtaEmergencyNumberDatabase();
8619 }
8620 }
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
8626 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008627 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008628 enforceActiveEmergencySessionPermission();
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 for (Phone phone: PhoneFactory.getPhones()) {
8633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8634 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008635 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8636 }
8637 }
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 @Override
8644 public void resetOtaEmergencyNumberDbFilePath() {
8645 enforceActiveEmergencySessionPermission();
8646
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
8649 for (Phone phone: PhoneFactory.getPhones()) {
8650 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8651 if (tracker != null) {
8652 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008653 }
8654 }
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 }
8659
8660 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008661 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8662 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8663 Phone phone = getPhone(subId);
8664 if (phone == null) {
8665 return null;
8666 }
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 UiccProfile profile = UiccController.getInstance()
8670 .getUiccProfileForPhone(phone.getPhoneId());
8671 if (profile != null) {
8672 return profile.getCertsFromCarrierPrivilegeAccessRules();
8673 }
8674 } finally {
8675 Binder.restoreCallingIdentity(identity);
8676 }
8677 return null;
8678 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008679
8680 /**
8681 * Enable or disable a modem stack.
8682 */
8683 @Override
8684 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8685 enforceModifyPermission();
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
8689 Phone phone = PhoneFactory.getPhone(slotIndex);
8690 if (phone == null) {
8691 return false;
8692 } else {
8693 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8694 }
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 }
Michelecea4cf22018-12-21 15:00:11 -08008699
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008700 /**
8701 * Whether a modem stack is enabled or not.
8702 */
8703 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008704 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8705 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008706 Phone phone = PhoneFactory.getPhone(slotIndex);
8707 if (phone == null) return false;
8708
8709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008710 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8711 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008712 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8713 }
8714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008717 try {
8718 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8719 } catch (NoSuchElementException ex) {
8720 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8721 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 }
8726
Michelecea4cf22018-12-21 15:00:11 -08008727 @Override
Michele0ea7d782019-03-19 14:58:42 -07008728 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008729 enforceModifyPermission();
8730
8731 final long identity = Binder.clearCallingIdentity();
8732 try {
8733 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008734 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008735 .commit();
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
8741 @Override
Michele0ea7d782019-03-19 14:58:42 -07008742 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008743 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008745 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8746 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008747 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008748 }
Michelecea4cf22018-12-21 15:00:11 -08008749
8750 final long identity = Binder.clearCallingIdentity();
8751 try {
Michele0ea7d782019-03-19 14:58:42 -07008752 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008753 } finally {
8754 Binder.restoreCallingIdentity(identity);
8755 }
8756 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008757
Michele0ea7d782019-03-19 14:58:42 -07008758 @TelephonyManager.IsMultiSimSupportedResult
8759 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008760 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8761 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8762 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008763 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8764 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008765 }
8766 // Check if the hardware supports multisim functionality. If usage of multisim is not
8767 // supported by the modem, indicate that it is restricted.
8768 PhoneCapability staticCapability =
8769 mPhoneConfigurationManager.getStaticPhoneCapability();
8770 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008771 loge("isMultiSimSupportedInternal: no static configuration available");
8772 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008773 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008774 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008775 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8776 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008777 }
8778 // Check if support of multiple SIMs is restricted by carrier
8779 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008780 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008781 }
8782
Michele0ea7d782019-03-19 14:58:42 -07008783 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008784 }
8785
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 /**
8787 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008788 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8789 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8790 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008791 * @param numOfSims number of active sims we want to switch to
8792 */
8793 @Override
8794 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008795 if (numOfSims == 1) {
8796 enforceModifyPermission();
8797 } else {
8798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8799 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8800 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008801 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008802
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008803 try {
Michele30b57b22019-03-01 12:01:14 -08008804 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008805 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008806 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8807 return;
8808 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008809 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008815 @Override
8816 public boolean isApplicationOnUicc(int subId, int appType) {
8817 enforceReadPrivilegedPermission("isApplicationOnUicc");
8818 Phone phone = getPhone(subId);
8819 if (phone == null) {
8820 return false;
8821 }
8822 final long identity = Binder.clearCallingIdentity();
8823 try {
8824 UiccCard uiccCard = phone.getUiccCard();
8825 if (uiccCard == null) {
8826 return false;
8827 }
8828 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8829 if (uiccProfile == null) {
8830 return false;
8831 }
8832 if (TelephonyManager.APPTYPE_SIM <= appType
8833 && appType <= TelephonyManager.APPTYPE_ISIM) {
8834 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8835 }
8836 return false;
8837 } finally {
8838 Binder.restoreCallingIdentity(identity);
8839 }
8840 }
8841
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008842 /**
chen xub4baa772019-04-03 10:23:41 -07008843 * Get whether making changes to modem configurations will trigger reboot.
8844 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008845 */
8846 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008847 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8848 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008850 mApp, subId, callingPackage, callingFeatureId,
8851 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008852 return false;
8853 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
8861
Nathan Harold29f5f052019-02-15 13:41:57 -08008862 private void updateModemStateMetrics() {
8863 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8864 // TODO: check the state for each modem if the api is ready.
8865 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8866 }
8867
Pengquan Meng3889a572019-01-23 11:16:29 -08008868 @Override
8869 public int[] getSlotsMapping() {
8870 enforceReadPrivilegedPermission("getSlotsMapping");
8871
8872 final long identity = Binder.clearCallingIdentity();
8873 try {
8874 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8875 // All logical slots should have a mapping to a physical slot.
8876 int[] logicalSlotsMapping = new int[phoneCount];
8877 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8878 for (int i = 0; i < slotInfos.length; i++) {
8879 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8880 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8881 }
8882 }
8883 return logicalSlotsMapping;
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008888
8889 /**
8890 * Get the IRadio HAL Version
8891 */
8892 @Override
8893 public int getRadioHalVersion() {
8894 Phone phone = getDefaultPhone();
8895 if (phone == null) return -1;
8896 HalVersion hv = phone.getHalVersion();
8897 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8898 return hv.major * 100 + hv.minor;
8899 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008900
8901 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008902 * Get the current calling package name.
8903 * @return the current calling package name
8904 */
8905 @Override
8906 public String getCurrentPackageName() {
8907 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8908 }
8909
8910 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8912 * corresponding network requests on a subId.
8913 *
8914 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008915 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008916 * 2) APN is un-metered for this subscription, or
8917 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008918 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008919 *
8920 * @return whether data is allowed for a apn type.
8921 *
8922 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008923 */
8924 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008925 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008926 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8927 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008928
8929 // Now that all security checks passes, perform the operation as ourselves.
8930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 Phone phone = getPhone(subId);
8933 if (phone == null) return false;
8934
Jack Yu41407ee2019-05-13 16:54:09 -07008935 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008936 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
8939 }
8940 }
8941
8942 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008943 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008944 enforceReadPrivilegedPermission("isApnMetered");
8945
8946 // Now that all security checks passes, perform the operation as ourselves.
8947 final long identity = Binder.clearCallingIdentity();
8948 try {
8949 Phone phone = getPhone(subId);
8950 if (phone == null) return true; // By default return true.
8951
Jack Yu41407ee2019-05-13 16:54:09 -07008952 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008957
8958 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008959 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8960 int subscriptionId, IBooleanConsumer resultCallback) {
8961 enforceModifyPermission();
8962 long token = Binder.clearCallingIdentity();
8963 try {
8964 Phone phone = getPhone(subscriptionId);
8965 if (phone == null) {
8966 try {
8967 if (resultCallback != null) {
8968 resultCallback.accept(false);
8969 }
8970 } catch (RemoteException e) {
8971 // ignore
8972 }
8973 return;
8974 }
8975 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8976 Pair.create(specifiers, (x) -> {
8977 try {
8978 if (resultCallback != null) {
8979 resultCallback.accept(x);
8980 }
8981 } catch (RemoteException e) {
8982 // ignore
8983 }
8984 });
8985 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8986 } finally {
8987 Binder.restoreCallingIdentity(token);
8988 }
8989 }
8990
8991 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008992 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8993 TelephonyPermissions
8994 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8995 mApp, subId, "getSystemSelectionChannels");
8996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8997 final long identity = Binder.clearCallingIdentity();
8998 try {
8999 List<RadioAccessSpecifier> specifiers =
9000 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9001 null, subId, workSource);
9002 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9003 return specifiers;
9004 } finally {
9005 Binder.restoreCallingIdentity(identity);
9006 }
9007 }
9008
9009 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009010 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009011 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009012 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9013 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9014 if (iccRecords == null) {
9015 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9016 return false;
9017 }
9018 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9019 }
9020
9021 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009022 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9023 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009024 if (callingPackage == null) {
9025 callingPackage = getCurrentPackageName();
9026 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009027 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9028 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009029 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9030 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009031 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9032 }
9033 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9034 Intent intent = new Intent();
9035 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9036 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9037 // Bring up choose default SMS subscription dialog right now
9038 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9039 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9040 mApp.startActivity(intent);
9041 }
chen xud5ca2d52019-05-28 15:20:57 -07009042
9043 @Override
9044 public String getMmsUAProfUrl(int subId) {
9045 //TODO investigate if this API should require proper permission check in R b/133791609
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009048 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9049 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9050 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9051 return carrierUAProfUrl;
9052 }
chen xud5ca2d52019-05-28 15:20:57 -07009053 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9054 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9055 } finally {
9056 Binder.restoreCallingIdentity(identity);
9057 }
9058 }
9059
9060 @Override
9061 public String getMmsUserAgent(int subId) {
9062 //TODO investigate if this API should require proper permission check in R b/133791609
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009065 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9066 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9067 if (!TextUtils.isEmpty(carrierUserAgent)) {
9068 return carrierUserAgent;
9069 }
chen xud5ca2d52019-05-28 15:20:57 -07009070 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9071 .getString(com.android.internal.R.string.config_mms_user_agent);
9072 } finally {
9073 Binder.restoreCallingIdentity(identity);
9074 }
9075 }
Jack Yub07d4972019-05-28 16:12:25 -07009076
9077 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009078 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9079 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9080
9081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 Phone phone = getPhone(subscriptionId);
9084 if (phone == null) return false;
9085
9086 switch (policy) {
9087 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9088 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9089 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9090 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9091 default:
9092 throw new IllegalArgumentException(policy + " is not a valid policy");
9093 }
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098
9099 @Override
9100 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9101 boolean enabled) {
9102 enforceModifyPermission();
9103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 Phone phone = getPhone(subscriptionId);
9107 if (phone == null) return;
9108
9109 switch (policy) {
9110 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9111 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9112 break;
9113 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9114 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9115 break;
9116 default:
9117 throw new IllegalArgumentException(policy + " is not a valid policy");
9118 }
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
9123
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009124 /**
Hall Liub48cf452020-09-25 11:13:49 -07009125 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009126 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9127 * otherwise.
9128 */
9129 @Override
9130 public void setCepEnabled(boolean isCepEnabled) {
9131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9132
9133 final long identity = Binder.clearCallingIdentity();
9134 try {
9135 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9136 for (Phone phone : PhoneFactory.getPhones()) {
9137 Phone defaultPhone = phone.getImsPhone();
9138 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9139 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9140 ImsPhoneCallTracker imsPhoneCallTracker =
9141 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9142 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9143 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9144 + imsPhone.getMsisdn());
9145 }
9146 }
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 }
allenwtsu46dcc572020-01-08 18:24:03 +08009151
9152 /**
9153 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9154 *
9155 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9156 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9157 * before being read.
9158 */
9159 @Override
9160 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9161 isCompressed) {
9162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9163 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009164 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9165 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9166 }
9167 if (!isImsAvailableOnDevice()) {
9168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9169 "IMS not available on device.");
9170 }
9171
9172 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009173 try {
Hui Wang068ab862020-10-31 05:12:53 +00009174 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009177 }
9178 }
zoey chenf95ca592019-12-30 16:11:23 +08009179
9180 @Override
9181 public boolean isIccLockEnabled(int subId) {
9182 enforceReadPrivilegedPermission("isIccLockEnabled");
9183
9184 // Now that all security checks passes, perform the operation as ourselves.
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 Phone phone = getPhone(subId);
9188 if (phone != null && phone.getIccCard() != null) {
9189 return phone.getIccCard().getIccLockEnabled();
9190 } else {
9191 return false;
9192 }
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
9196 }
9197
9198 /**
zoey chene02881a2019-12-30 16:11:23 +08009199 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009200 *
zoey chene02881a2019-12-30 16:11:23 +08009201 * @return an integer representing the status of IccLock enabled or disabled in the following
9202 * three cases:
9203 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9204 * successfully.
9205 * - Positive number and zero for remaining password attempts.
9206 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009207 *
9208 */
9209 @Override
9210 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9211 enforceModifyPermission();
9212
9213 Phone phone = getPhone(subId);
9214 if (phone == null) {
9215 return 0;
9216 }
9217 // Now that all security checks passes, perform the operation as ourselves.
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9221 new Pair<Boolean, String>(enabled, password), phone, null);
9222 return attemptsRemaining;
9223
9224 } catch (Exception e) {
9225 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 return 0;
9230 }
9231
9232 /**
9233 * Change the ICC password used in ICC pin lock.
9234 *
zoey chene02881a2019-12-30 16:11:23 +08009235 * @return an integer representing the status of IccLock changed in the following three cases:
9236 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9237 * - Positive number and zero for remaining password attempts.
9238 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009239 *
9240 */
9241 @Override
9242 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9243 enforceModifyPermission();
9244
9245 Phone phone = getPhone(subId);
9246 if (phone == null) {
9247 return 0;
9248 }
9249 // Now that all security checks passes, perform the operation as ourselves.
9250 final long identity = Binder.clearCallingIdentity();
9251 try {
9252 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9253 new Pair<String, String>(oldPassword, newPassword), phone, null);
9254 return attemptsRemaining;
9255
9256 } catch (Exception e) {
9257 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 return 0;
9262 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009263
Peter Wangdafb9ac2020-01-15 14:13:38 -08009264 /**
9265 * Request for receiving user activity notification
9266 */
9267 @Override
9268 public void requestUserActivityNotification() {
9269 if (!mNotifyUserActivity.get()
9270 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9271 mNotifyUserActivity.set(true);
9272 }
9273 }
9274
9275 /**
9276 * Called when userActivity is signalled in the power manager.
9277 * This is safe to call from any thread, with any window manager locks held or not.
9278 */
9279 @Override
9280 public void userActivity() {
9281 // ***************************************
9282 // * Inherited from PhoneWindowManager *
9283 // ***************************************
9284 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9285 // WITH ITS LOCKS HELD.
9286 //
9287 // This code must be VERY careful about the locks
9288 // it acquires.
9289 // In fact, the current code acquires way too many,
9290 // and probably has lurking deadlocks.
9291
9292 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9293 throw new SecurityException("Only the OS may call notifyUserActivity()");
9294 }
9295
9296 if (mNotifyUserActivity.getAndSet(false)) {
9297 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9298 USER_ACTIVITY_NOTIFICATION_DELAY);
9299 }
9300 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009301
Malcolm Chen884180b2020-04-13 11:59:40 -07009302 @Override
9303 public boolean canConnectTo5GInDsdsMode() {
9304 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9305 }
Jack Yud10cdd42020-09-28 20:28:01 -07009306
9307 @Override
9308 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9309 String callingFeatureId) {
9310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9311 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9312 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9313 }
9314
9315 Phone phone = getPhone(subId);
9316 if (phone == null) {
9317 throw new RuntimeException("phone is not available");
9318 }
9319 // Now that all security checks passes, perform the operation as ourselves.
9320 final long identity = Binder.clearCallingIdentity();
9321 try {
9322 return phone.getEquivalentHomePlmns();
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009327
Hui Wang0866fcc2020-10-12 12:14:23 -07009328 @Override
9329 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9330 UaSecurityProtocolIdentifier securityProtocol,
9331 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9332 throws RemoteException {
9333 enforceModifyPermission();
9334 if (DBG) {
9335 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9336 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9337 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9338 }
9339
9340 if (!SubscriptionManager.isValidSubscriptionId(subId)
9341 || appType < TelephonyManager.APPTYPE_UNKNOWN
9342 || appType > TelephonyManager.APPTYPE_ISIM
9343 || nafUrl == null || securityProtocol == null || callback == null) {
9344 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9345 if (callback != null) {
9346 try {
9347 callback.onAuthenticationFailure(
9348 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9349 } catch (RemoteException exception) {
9350 log("Fail to notify onAuthenticationFailure due to " + exception);
9351 }
9352 return;
9353 }
9354 }
9355
9356 final long token = Binder.clearCallingIdentity();
9357 try {
9358 getGbaManager(subId).bootstrapAuthenticationRequest(
9359 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9360 forceBootStrapping, callback));
9361 } finally {
9362 Binder.restoreCallingIdentity(token);
9363 }
9364 }
9365
Jack Nudelman24d51a52020-11-24 12:08:04 -08009366 /**
9367 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9368 * requested radio power state will actually be set. See {@link
9369 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9370 *
9371 * @param subId the subscription ID of the phone requesting to set the radio power state.
9372 * @param enable {@code true} if trying to turn radio on.
9373 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9374 * false}.
9375 */
9376 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9377 Phone phone = getPhone(subId);
9378 if (phone != null) {
9379 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9380 return true;
9381 }
9382 return false;
9383 }
9384
9385 private int handleDataThrottlingRequest(int subId,
9386 DataThrottlingRequest dataThrottlingRequest) {
9387 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9388 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9389 if (!setRadioPowerForThermal(subId, true)) {
9390 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9391 }
9392
9393 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9394
9395 int thermalMitigationResult =
9396 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9397 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9398 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9399 }
9400 return thermalMitigationResult;
9401 }
9402
9403 /**
9404 * Thermal mitigation request to control functionalities at modem.
9405 *
9406 * @param subId the id of the subscription.
9407 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9408 *
9409 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9410 */
9411 @Override
9412 @ThermalMitigationResult
9413 public int sendThermalMitigationRequest(
9414 int subId,
9415 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9416 enforceModifyPermission();
9417
9418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9419 final long identity = Binder.clearCallingIdentity();
9420
9421 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9422 try {
9423 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9424 switch (thermalMitigationAction) {
9425 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9426 thermalMitigationResult =
9427 handleDataThrottlingRequest(subId,
9428 thermalMitigationRequest.getDataThrottlingRequest());
9429 break;
9430 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9431 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9432 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9433 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9434 }
9435
9436 // Ensure that radio is on. If not able to power on due to phone being
9437 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9438 if (!setRadioPowerForThermal(subId, true)) {
9439 thermalMitigationResult =
9440 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9441 break;
9442 }
9443
9444 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9445 false);
9446 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9447 break;
9448 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9449 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9450 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9451 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9452 }
9453
9454 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9455 if (registry != null) {
9456 TelephonyConnectionService service =
9457 registry.getTelephonyConnectionService();
9458 Phone phone = getPhone(subId);
9459 if (phone == null) {
9460 thermalMitigationResult =
9461 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9462 break;
9463 }
9464
9465 if (PhoneConstantConversions.convertCallState(phone.getState())
9466 != TelephonyManager.CALL_STATE_IDLE
9467 || phone.isInEmergencySmsMode() || phone.isInEcm()
9468 || (service != null && service.isEmergencyCallPending())) {
9469 String errorMessage = "Phone state is not valid. call state = "
9470 + PhoneConstantConversions.convertCallState(phone.getState())
9471 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9472 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9473 errorMessage += service == null
9474 ? " TelephonyConnectionService is null"
9475 : " isEmergencyCallPending = "
9476 + service.isEmergencyCallPending();
9477 Log.e(LOG_TAG, errorMessage);
9478 thermalMitigationResult =
9479 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9480 break;
9481 }
9482 } else {
9483 thermalMitigationResult =
9484 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9485 break;
9486 }
9487
9488 // Turn radio off. If not able to power off due to phone being unavailable,
9489 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9490 if (!setRadioPowerForThermal(subId, false)) {
9491 thermalMitigationResult =
9492 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9493 break;
9494 }
9495 thermalMitigationResult =
9496 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9497 break;
9498 default:
9499 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9500 + "not exist. Requested action: " + thermalMitigationAction);
9501 }
9502 } catch (IllegalArgumentException e) {
9503 throw e;
9504 } catch (Exception e) {
9505 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9506 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510
9511 if (DBG) {
9512 log("thermalMitigationRequest returning with thermalMitigationResult: "
9513 + thermalMitigationResult);
9514 }
9515
9516 return thermalMitigationResult;
9517 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009518
9519 /**
9520 * Set the GbaService Package Name that Telephony will bind to.
9521 *
9522 * @param subId The sim that the GbaService is associated with.
9523 * @param packageName The name of the package to be replaced with.
9524 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9525 */
9526 @Override
9527 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9528 enforceModifyPermission();
9529
9530 final long identity = Binder.clearCallingIdentity();
9531 try {
9532 return getGbaManager(subId).overrideServicePackage(packageName);
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
9539 * Return the package name of the currently bound GbaService.
9540 *
9541 * @param subId The sim that the GbaService is associated with.
9542 * @return the package name of the GbaService configuration, null if GBA is not supported.
9543 */
9544 @Override
9545 public String getBoundGbaService(int subId) {
9546 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return getGbaManager(subId).getServicePackage();
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
9556 /**
9557 * Set the release time for telephony to unbind GbaService.
9558 *
9559 * @param subId The sim that the GbaService is associated with.
9560 * @param interval The release time to unbind GbaService by millisecond.
9561 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9562 */
9563 @Override
9564 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9565 enforceModifyPermission();
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 return getGbaManager(subId).overrideReleaseTime(interval);
9570 } finally {
9571 Binder.restoreCallingIdentity(identity);
9572 }
9573 }
9574
9575 /**
9576 * Return the release time for telephony to unbind GbaService.
9577 *
9578 * @param subId The sim that the GbaService is associated with.
9579 * @return The release time to unbind GbaService by millisecond.
9580 */
9581 @Override
9582 public int getGbaReleaseTime(int subId) {
9583 enforceReadPrivilegedPermission("getGbaReleaseTime");
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 return getGbaManager(subId).getReleaseTime();
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
9593 private GbaManager getGbaManager(int subId) {
9594 GbaManager instance = GbaManager.getInstance(subId);
9595 if (instance == null) {
9596 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9597 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9598 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9599 }
9600 return instance;
9601 }
Hui Wang068ab862020-10-31 05:12:53 +00009602
9603 /**
9604 * indicate whether the device and the carrier can support
9605 * RCS VoLTE single registration.
9606 */
9607 @Override
9608 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9609 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9610
9611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9612 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9613 }
9614
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9618 if (rpm != null) {
9619 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9620 }
9621 return false;
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 /**
9628 * Register RCS provisioning callback.
9629 */
9630 @Override
9631 public void registerRcsProvisioningChangedCallback(int subId,
9632 IRcsConfigCallback callback) {
9633 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9634
9635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9636 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9637 }
9638 if (!isImsAvailableOnDevice()) {
9639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9640 "IMS not available on device.");
9641 }
9642
9643 final long identity = Binder.clearCallingIdentity();
9644 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009645 if (!RcsProvisioningMonitor.getInstance()
9646 .registerRcsProvisioningChangedCallback(subId, callback)) {
9647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9648 "Service not available for the subscription.");
9649 }
Hui Wang068ab862020-10-31 05:12:53 +00009650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 /**
9656 * Unregister RCS provisioning callback.
9657 */
9658 @Override
9659 public void unregisterRcsProvisioningChangedCallback(int subId,
9660 IRcsConfigCallback callback) {
9661 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9662
9663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9664 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9665 }
9666 if (!isImsAvailableOnDevice()) {
9667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9668 "IMS not available on device.");
9669 }
9670
9671 final long identity = Binder.clearCallingIdentity();
9672 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009673 RcsProvisioningMonitor.getInstance()
9674 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
9680 /**
9681 * trigger RCS reconfiguration.
9682 */
9683 public void triggerRcsReconfiguration(int subId) {
9684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9685 mApp, subId, "triggerRcsReconfiguration");
9686
9687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9688 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9689 }
9690 if (!isImsAvailableOnDevice()) {
9691 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9692 "IMS not available on device.");
9693 }
9694
9695 final long identity = Binder.clearCallingIdentity();
9696 try {
9697 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
9701 }
9702
9703 /**
9704 * Provide the client configuration parameters of the RCS application.
9705 */
9706 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9708 mApp, subId, "setRcsClientConfiguration");
9709
9710 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9711 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9712 }
9713 if (!isImsAvailableOnDevice()) {
9714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9715 "IMS not available on device.");
9716 }
9717
9718 final long identity = Binder.clearCallingIdentity();
9719
9720 try {
9721 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9722 if (configBinder == null) {
9723 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9724 } else {
9725 configBinder.setRcsClientConfiguration(rcc);
9726 }
9727 } catch (RemoteException e) {
9728 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * Overrides the config of RCS VoLTE single registration enabled for the device.
9736 */
9737 @Override
9738 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9740 "setDeviceSingleRegistrationEnabledOverride");
9741 enforceModifyPermission();
9742
9743 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9744 : Boolean.parseBoolean(enabledStr);
9745 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9746 }
9747
9748 /**
9749 * Gets the config of RCS VoLTE single registration enabled for the device.
9750 */
9751 @Override
9752 public boolean getDeviceSingleRegistrationEnabled() {
9753 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9754 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9755 }
9756
9757 /**
9758 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9759 */
9760 @Override
9761 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9763 "setCarrierSingleRegistrationEnabledOverride");
9764 enforceModifyPermission();
9765
9766 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9767 : Boolean.parseBoolean(enabledStr);
9768 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9769 subId, enabled);
9770 }
9771
9772 /**
9773 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9774 */
9775 @Override
9776 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9777 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9778 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9779 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009780
9781 /**
9782 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9783 * their mobile plan.
9784 */
9785 @Override
9786 public String getMobileProvisioningUrl() {
9787 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9788 final long identity = Binder.clearCallingIdentity();
9789 try {
9790 return getDefaultPhone().getMobileProvisioningUrl();
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
9793 }
9794 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009795
9796 @Override
9797 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9798 String callingPackage) {
9799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9800 mApp, subId, "setSignalStrengthUpdateRequest");
9801
9802 final int callingUid = Binder.getCallingUid();
9803 // Verify that tha callingPackage belongs to the calling UID
9804 mApp.getSystemService(AppOpsManager.class)
9805 .checkPackage(callingUid, callingPackage);
9806
9807 validateSignalStrengthUpdateRequest(request, callingUid);
9808
9809 final long identity = Binder.clearCallingIdentity();
9810 try {
9811 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9812 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9813
9814 if (result instanceof IllegalStateException) {
9815 throw (IllegalStateException) result;
9816 }
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 }
9821
9822 @Override
9823 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9824 String callingPackage) {
9825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9826 mApp, subId, "clearSignalStrengthUpdateRequest");
9827
9828 final int callingUid = Binder.getCallingUid();
9829 // Verify that tha callingPackage belongs to the calling UID
9830 mApp.getSystemService(AppOpsManager.class)
9831 .checkPackage(callingUid, callingPackage);
9832
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
9835 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9836 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9837
9838 if (result instanceof IllegalStateException) {
9839 throw (IllegalStateException) result;
9840 }
9841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 }
9845
9846 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9847 int callingUid) {
9848 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9849 // phone/system process do not have further restriction on request
9850 return;
9851 }
9852
9853 // Applications has restrictions on how to use the request:
9854 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9855 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9856 // This is not system caller which has been checked above
9857 throw new IllegalArgumentException(
9858 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9859 }
9860
9861 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9862 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9863 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9864 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9865 || info.isEnabled()) {
9866 throw new IllegalArgumentException(
9867 "Only system can set hide fields in SignalThresholdInfo");
9868 }
9869
9870 // Thresholds length for each RAN need in range. This has been validated in
9871 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9872 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9873 final int[] thresholds = info.getThresholds();
9874 Objects.requireNonNull(thresholds);
9875 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9876 || thresholds.length
9877 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9878 throw new IllegalArgumentException(
9879 "thresholds length is out of range: " + thresholds.length);
9880 }
9881 }
9882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009883}