blob: a831e946b5f2becca360090b004c9896062ad37d [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;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080092import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080094import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070095import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -080098import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -080099import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000100import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700101import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800103import android.telephony.data.ApnSetting;
104import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700105import android.telephony.gba.GbaAuthRequest;
106import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700107import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800108import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000109import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700110import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800112import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700113import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800114import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000116import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700117import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800118import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800119import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800120import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800121import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700124import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800126import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Andrew Lee312e8172014-10-23 17:01:36 -0700128import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800129import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700132import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700133import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800134import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700135import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800137import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700139import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800140import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800141import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700142import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700143import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800144import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800146import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700148import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700149import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700151import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800152import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700153import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700154import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700155import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700156import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700157import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700158import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700159import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700160import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800161import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800162import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800163import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700164import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800165import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700166import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800167import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700168import com.android.internal.telephony.imsphone.ImsPhone;
169import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800170import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900171import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800173import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800175import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700176import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800179import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000180import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800181import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700182import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700183import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800184import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700186import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800187import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700188import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700189import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800190import com.android.services.telephony.TelecomAccountRegistry;
191import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800192import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800193
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700194import java.io.FileDescriptor;
195import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800198import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800199import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800200import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100201import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700203import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800205import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800206import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
208/**
209 * Implementation of the ITelephony interface.
210 */
Santos Cordon117fee72014-05-16 17:56:12 -0700211public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212 private static final String LOG_TAG = "PhoneInterfaceManager";
213 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
214 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217 // Message codes used with mMainThreadHandler
218 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700219 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
220 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221 private static final int CMD_OPEN_CHANNEL = 9;
222 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
223 private static final int CMD_CLOSE_CHANNEL = 11;
224 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800225 private static final int CMD_NV_READ_ITEM = 13;
226 private static final int EVENT_NV_READ_ITEM_DONE = 14;
227 private static final int CMD_NV_WRITE_ITEM = 15;
228 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
229 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
230 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700231 private static final int CMD_RESET_MODEM_CONFIG = 19;
232 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800233 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
234 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
235 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
236 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800237 private static final int CMD_SEND_ENVELOPE = 25;
238 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000239 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
240 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700241 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
242 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
243 private static final int CMD_EXCHANGE_SIM_IO = 31;
244 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800245 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
246 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700247 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
248 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700249 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
250 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700251 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
252 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
253 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700255 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
256 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
257 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
258 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700259 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800260 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
261 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000262 private static final int CMD_SWITCH_SLOTS = 50;
263 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700264 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
265 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
266 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
267 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
268 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
269 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
270 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
271 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700272 private static final int CMD_GET_ALL_CELL_INFO = 60;
273 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
274 private static final int CMD_GET_CELL_LOCATION = 62;
275 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700276 private static final int CMD_MODEM_REBOOT = 64;
277 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700278 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
279 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800280 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
281 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700282 private static final int CMD_GET_MODEM_STATUS = 70;
283 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700284 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
285 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700286 private static final int CMD_ERASE_MODEM_CONFIG = 74;
287 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800288 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
289 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
290 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
291 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800292 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
293 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800294 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800295 private static final int CMD_GET_CALL_FORWARDING = 83;
296 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
297 private static final int CMD_SET_CALL_FORWARDING = 85;
298 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
299 private static final int CMD_GET_CALL_WAITING = 87;
300 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
301 private static final int CMD_SET_CALL_WAITING = 89;
302 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700303 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
304 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
305 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
306 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700307 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
308 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800309 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
310 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800311 private static final int CMD_SET_DATA_THROTTLING = 99;
312 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800313 private static final int CMD_SET_SIM_POWER = 101;
314 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800316 // Parameters of select command.
317 private static final int SELECT_COMMAND = 0xA4;
318 private static final int SELECT_P1 = 0x04;
319 private static final int SELECT_P2 = 0;
320 private static final int SELECT_P3 = 0x10;
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /** The singleton instance. */
323 private static PhoneInterfaceManager sInstance;
324
Wink Saville3ab207e2014-11-20 13:07:20 -0800325 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800327 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700328 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800329 private AppOpsManager mAppOps;
330 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800331 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800332 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700333 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334
Peter Wangdafb9ac2020-01-15 14:13:38 -0800335 /** User Activity */
336 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
338
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700339 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
340
Derek Tan97ebb422014-09-05 16:55:38 -0700341 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
342 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800343 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800344 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700345
Michelecea4cf22018-12-21 15:00:11 -0800346 // String to store multi SIM allowed
347 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
348
Derek Tan740e1672017-06-27 14:56:27 -0700349 // The AID of ISD-R.
350 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
351
yinxub1bed742017-04-17 11:45:04 -0700352 private NetworkScanRequestTracker mNetworkScanRequestTracker;
353
David Kelly5e06a7f2018-03-12 14:10:59 +0000354 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
355 private static final int MANUFACTURER_CODE_LENGTH = 8;
356
Jack Nudelman24d51a52020-11-24 12:08:04 -0800357 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
358
Derek Tan89e89d42014-07-08 17:00:10 -0700359 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700360 * Experiment flag to enable erase modem config on reset network, default value is false
361 */
362 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
363 "reset_network_erase_modem_config_enabled";
364
365 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700366 * A request object to use for transmitting data to an ICC.
367 */
368 private static final class IccAPDUArgument {
369 public int channel, cla, command, p1, p2, p3;
370 public String data;
371
372 public IccAPDUArgument(int channel, int cla, int command,
373 int p1, int p2, int p3, String data) {
374 this.channel = channel;
375 this.cla = cla;
376 this.command = command;
377 this.p1 = p1;
378 this.p2 = p2;
379 this.p3 = p3;
380 this.data = data;
381 }
382 }
383
384 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700385 * A request object to use for transmitting data to an ICC.
386 */
387 private static final class ManualNetworkSelectionArgument {
388 public OperatorInfo operatorInfo;
389 public boolean persistSelection;
390
391 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
392 this.operatorInfo = operatorInfo;
393 this.persistSelection = persistSelection;
394 }
395 }
396
397 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
399 * request after sending. The main thread will notify the request when it is complete.
400 */
401 private static final class MainThreadRequest {
402 /** The argument to use for the request */
403 public Object argument;
404 /** The result of the request that is run on the main thread */
405 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800406 // The subscriber id that this request applies to. Defaults to
407 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
408 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Nathan Harold92bed182018-10-12 18:16:49 -0700410 // In cases where subId is unavailable, the caller needs to specify the phone.
411 public Phone phone;
412
vagdeviaf9a5b92018-08-15 16:01:53 -0700413 public WorkSource workSource;
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 public MainThreadRequest(Object argument) {
416 this.argument = argument;
417 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800418
Nathan Harold92bed182018-10-12 18:16:49 -0700419 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
420 this.argument = argument;
421 if (phone != null) {
422 this.phone = phone;
423 }
424 this.workSource = workSource;
425 }
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800428 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800429 if (subId != null) {
430 this.subId = subId;
431 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700432 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 }
435
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800436 private static final class IncomingThirdPartyCallArgs {
437 public final ComponentName component;
438 public final String callId;
439 public final String callerDisplayName;
440
441 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
442 String callerDisplayName) {
443 this.component = component;
444 this.callId = callId;
445 this.callerDisplayName = callerDisplayName;
446 }
447 }
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 /**
450 * A handler that processes messages on the main thread in the phone process. Since many
451 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
452 * inbound binder threads to the main thread in the phone process. The Binder thread
453 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
454 * on, which will be notified when the operation completes and will contain the result of the
455 * request.
456 *
457 * <p>If a MainThreadRequest object is provided in the msg.obj field,
458 * note that request.result must be set to something non-null for the calling thread to
459 * unblock.
460 */
461 private final class MainThreadHandler extends Handler {
462 @Override
463 public void handleMessage(Message msg) {
464 MainThreadRequest request;
465 Message onCompleted;
466 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800469 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470
471 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 case CMD_HANDLE_USSD_REQUEST: {
473 request = (MainThreadRequest) msg.obj;
474 final Phone phone = getPhoneFromRequest(request);
475 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
476 String ussdRequest = ussdObject.first;
477 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700478
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 if (!isUssdApiAllowed(request.subId)) {
480 // Carrier does not support use of this API, return failure.
481 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
482 UssdResponse response = new UssdResponse(ussdRequest, null);
483 Bundle returnData = new Bundle();
484 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
485 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 request.result = true;
488 notifyRequester(request);
489 return;
490 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700491
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 try {
493 request.result = phone != null
494 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
495 } catch (CallStateException cse) {
496 request.result = false;
497 }
498 // Wake up the requesting thread
499 notifyRequester(request);
500 break;
pkanwar32d516d2016-10-14 19:37:38 -0700501 }
502
Yorke Lee716f67e2015-06-17 15:39:16 -0700503 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700505 final Phone phone = getPhoneFromRequest(request);
506 request.result = phone != null ?
507 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
508 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("iccTransmitApduLogicalChannel: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
524 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 iccArgument.channel, iccArgument.cla, iccArgument.command,
527 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800541 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800543 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 } else {
545 loge("iccTransmitApduLogicalChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 break;
550
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccTransmitApduBasicChannel: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
561 request);
562 uiccCard.iccTransmitApduBasicChannel(
563 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
564 iccArgument.p3, iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
575 if (ar.result == null) {
576 loge("iccTransmitApduBasicChannel: Empty response");
577 } else if (ar.exception instanceof CommandException) {
578 loge("iccTransmitApduBasicChannel: CommandException: " +
579 ar.exception);
580 } else {
581 loge("iccTransmitApduBasicChannel: Unknown exception");
582 }
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
587 case CMD_EXCHANGE_SIM_IO:
588 request = (MainThreadRequest) msg.obj;
589 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (uiccCard == null) {
592 loge("iccExchangeSimIO: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
597 request);
598 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
599 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
600 iccArgument.data, onCompleted);
601 }
602 break;
603
604 case EVENT_EXCHANGE_SIM_IO_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6f, 0, (byte[])null);
611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 break;
614
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 case CMD_SEND_ENVELOPE:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("sendEnvelopeWithStatus: No UICC");
620 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
624 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
625 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 break;
627
628 case EVENT_SEND_ENVELOPE_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800633 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("sendEnvelopeWithStatus: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("sendEnvelopeWithStatus: CommandException: " +
639 ar.exception);
640 } else {
641 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
642 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 break;
646
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 case CMD_OPEN_CHANNEL:
648 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800649 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800650 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800653 request.result = new IccOpenLogicalChannelResponse(-1,
654 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
659 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_OPEN_CHANNEL_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 int[] result = (int[]) ar.result;
669 int channelId = result[0];
670 byte[] selectResponse = null;
671 if (result.length > 1) {
672 selectResponse = new byte[result.length - 1];
673 for (int i = 1; i < result.length; ++i) {
674 selectResponse[i - 1] = (byte) result[i];
675 }
676 }
677 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700678 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.result == null) {
681 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 if (ar.exception != null) {
684 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
685 }
686
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700687 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700688 if (ar.exception instanceof CommandException) {
689 CommandException.Error error =
690 ((CommandException) (ar.exception)).getCommandError();
691 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700693 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 }
696 }
697 openChannelResp = new IccOpenLogicalChannelResponse(
698 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700700 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case CMD_CLOSE_CHANNEL:
705 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800706 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700707 if (uiccCard == null) {
708 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900709 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 } else {
712 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
713 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
714 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 break;
716
717 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800718 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
719 break;
720
721 case CMD_NV_READ_ITEM:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800731 if (ar.exception == null && ar.result != null) {
732 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800734 request.result = "";
735 if (ar.result == null) {
736 loge("nvReadItem: Empty response");
737 } else if (ar.exception instanceof CommandException) {
738 loge("nvReadItem: CommandException: " +
739 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800741 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 break;
746
Jake Hambye994d462014-02-03 13:10:13 -0800747 case CMD_NV_WRITE_ITEM:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
750 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700752 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
755 case EVENT_NV_WRITE_ITEM_DONE:
756 handleNullReturnEvent(msg, "nvWriteItem");
757 break;
758
759 case CMD_NV_WRITE_CDMA_PRL:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800763 break;
764
765 case EVENT_NV_WRITE_CDMA_PRL_DONE:
766 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
767 break;
768
chen xu6dac5ab2018-10-26 17:39:23 -0700769 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800770 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700771 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800772 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800773 break;
774
chen xu6dac5ab2018-10-26 17:39:23 -0700775 case EVENT_RESET_MODEM_CONFIG_DONE:
776 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700779 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
782 request);
783 Phone phone = getPhoneFromRequest(request);
784 if (phone != null) {
785 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
786 } else {
787 loge("isNRDualConnectivityEnabled: No phone object");
788 request.result = false;
789 notifyRequester(request);
790 }
791 break;
792 }
793
794 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 if (ar.exception == null && ar.result != null) {
798 request.result = ar.result;
799 } else {
800 // request.result must be set to something non-null
801 // for the calling thread to unblock
802 if (request.result != null) {
803 request.result = ar.result;
804 } else {
805 request.result = false;
806 }
807 if (ar.result == null) {
808 loge("isNRDualConnectivityEnabled: Empty response");
809 } else if (ar.exception instanceof CommandException) {
810 loge("isNRDualConnectivityEnabled: CommandException: "
811 + ar.exception);
812 } else {
813 loge("isNRDualConnectivityEnabled: Unknown exception");
814 }
815 }
816 notifyRequester(request);
817 break;
818
819 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
825 request.workSource);
826 } else {
827 loge("enableNrDualConnectivity: No phone object");
828 request.result =
829 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result =
840 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
841 } else {
842 request.result =
843 TelephonyManager
844 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
845 if (ar.exception instanceof CommandException) {
846 CommandException.Error error =
847 ((CommandException) (ar.exception)).getCommandError();
848 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
849 request.result =
850 TelephonyManager
851 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
852 }
853 loge("enableNrDualConnectivity" + ": CommandException: "
854 + ar.exception);
855 } else {
856 loge("enableNrDualConnectivity" + ": Unknown exception");
857 }
858 }
859 notifyRequester(request);
860 break;
861 }
862
Jake Hamby7c27be32014-03-03 13:25:59 -0800863 case CMD_GET_PREFERRED_NETWORK_TYPE:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700866 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800867 break;
868
869 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result; // Integer
874 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530875 // request.result must be set to something non-null
876 // for the calling thread to unblock
877 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 if (ar.result == null) {
879 loge("getPreferredNetworkType: Empty response");
880 } else if (ar.exception instanceof CommandException) {
881 loge("getPreferredNetworkType: CommandException: " +
882 ar.exception);
883 } else {
884 loge("getPreferredNetworkType: Unknown exception");
885 }
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 break;
889
890 case CMD_SET_PREFERRED_NETWORK_TYPE:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
893 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700894 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 break;
896
897 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
898 handleNullReturnEvent(msg, "setPreferredNetworkType");
899 break;
900
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000901 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
902 request = (MainThreadRequest)msg.obj;
903 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800904 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000905 break;
906
907 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
908 ar = (AsyncResult)msg.obj;
909 request = (MainThreadRequest)ar.userObj;
910 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000912 break;
913
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800914 case CMD_SET_VOICEMAIL_NUMBER:
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
917 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800918 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
919 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800920 break;
921
922 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
923 handleNullReturnEvent(msg, "setVoicemailNumber");
924 break;
925
Stuart Scott54788802015-03-30 13:18:01 -0700926 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
929 request);
930 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
931 break;
932
933 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
934 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
935 break;
936
Shishir Agrawal302c8692015-06-19 13:49:39 -0700937 case CMD_PERFORM_NETWORK_SCAN:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
940 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
941 break;
942
Hall Liua1acea22020-09-18 19:04:59 -0700943 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700946 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
947 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
948 request.argument;
949 int callForwardingReason = args.first;
950 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800951 break;
Hall Liua1acea22020-09-18 19:04:59 -0700952 }
953 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700956 TelephonyManager.CallForwardingInfoCallback callback =
957 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
958 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800959 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700960 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800961 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
962 for (CallForwardInfo callForwardInfo : callForwardInfos) {
963 // Service Class is a bit mask per 3gpp 27.007. Search for
964 // any service for voice call.
965 if ((callForwardInfo.serviceClass
966 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700967 callForwardingInfo = new CallForwardingInfo(true,
968 callForwardInfo.reason,
969 callForwardInfo.number,
970 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800971 break;
972 }
973 }
974 // Didn't find a call forward info for voice call.
975 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700976 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
977 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800978 }
Hall Liua1acea22020-09-18 19:04:59 -0700979 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800980 } else {
981 if (ar.result == null) {
982 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
986 }
Hall Liuae527aa2020-09-29 17:10:18 -0700987 int errorCode = TelephonyManager
988 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700993 errorCode = TelephonyManager
994 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700996 errorCode = TelephonyManager
997 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800998 }
999 }
Hall Liua1acea22020-09-18 19:04:59 -07001000 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001001 }
sqian80370722020-01-29 15:02:51 -08001002 break;
Hall Liua1acea22020-09-18 19:04:59 -07001003 }
sqian80370722020-01-29 15:02:51 -08001004
Hall Liua1acea22020-09-18 19:04:59 -07001005 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001008 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001009 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001010 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1011 request.argument).first;
1012 request.phone.setCallForwardingOption(
1013 callForwardingInfoToSet.isEnabled()
1014 ? CommandsInterface.CF_ACTION_ENABLE
1015 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001016 callForwardingInfoToSet.getReason(),
1017 callForwardingInfoToSet.getNumber(),
1018 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1019 break;
Hall Liua1acea22020-09-18 19:04:59 -07001020 }
sqian80370722020-01-29 15:02:51 -08001021
Hall Liua1acea22020-09-18 19:04:59 -07001022 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001025 Consumer<Integer> callback =
1026 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1027 request.argument).second;
1028 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001029 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001030 int errorCode = TelephonyManager.CallForwardingInfoCallback
1031 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager.CallForwardingInfoCallback
1037 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001038 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager.CallForwardingInfoCallback
1040 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001041 }
1042 }
1043 callback.accept(errorCode);
1044 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001045 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001046 }
sqian80370722020-01-29 15:02:51 -08001047 break;
Hall Liua1acea22020-09-18 19:04:59 -07001048 }
sqian80370722020-01-29 15:02:51 -08001049
Hall Liua1acea22020-09-18 19:04:59 -07001050 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1053 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1054 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 EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001060 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001061 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1062 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001063 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001064 // Service Class is a bit mask per 3gpp 27.007.
1065 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001066 if (callForwardResults.length > 1
1067 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001068 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001069 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001070 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1071 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001072 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001073 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001074 }
1075 } else {
1076 if (ar.result == null) {
1077 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1078 }
1079 if (ar.exception != null) {
1080 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1081 }
1082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
1084 ((CommandException) (ar.exception)).getCommandError();
1085 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 callForwardingStatus =
1087 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1088 }
1089 }
1090 }
Hall Liua1acea22020-09-18 19:04:59 -07001091 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001092 break;
Hall Liua1acea22020-09-18 19:04:59 -07001093 }
sqian80370722020-01-29 15:02:51 -08001094
Hall Liua1acea22020-09-18 19:04:59 -07001095 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001098 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1099 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001100 break;
Hall Liua1acea22020-09-18 19:04:59 -07001101 }
sqian80370722020-01-29 15:02:51 -08001102
Hall Liua1acea22020-09-18 19:04:59 -07001103 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 Consumer<Integer> callback =
1108 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1109 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001110 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001111 if (ar.exception instanceof CommandException) {
1112 CommandException.Error error =
1113 ((CommandException) (ar.exception)).getCommandError();
1114 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1115 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1116 } else {
1117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1118 }
1119 } else {
1120 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1121 }
1122 } else {
1123 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1124 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001125 }
sqian80370722020-01-29 15:02:51 -08001126 break;
Hall Liua1acea22020-09-18 19:04:59 -07001127 }
sqian80370722020-01-29 15:02:51 -08001128
Shishir Agrawal302c8692015-06-19 13:49:39 -07001129 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
1132 CellNetworkScanResult cellScanResult;
1133 if (ar.exception == null && ar.result != null) {
1134 cellScanResult = new CellNetworkScanResult(
1135 CellNetworkScanResult.STATUS_SUCCESS,
1136 (List<OperatorInfo>) ar.result);
1137 } else {
1138 if (ar.result == null) {
1139 loge("getCellNetworkScanResults: Empty response");
1140 }
1141 if (ar.exception != null) {
1142 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1143 }
1144 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1145 if (ar.exception instanceof CommandException) {
1146 CommandException.Error error =
1147 ((CommandException) (ar.exception)).getCommandError();
1148 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1149 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1150 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1151 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1152 }
1153 }
1154 cellScanResult = new CellNetworkScanResult(errorCode, null);
1155 }
1156 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001158 break;
1159
1160 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1161 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001162 ManualNetworkSelectionArgument selArg =
1163 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1165 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001166 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1167 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 break;
1169
1170 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null) {
1174 request.result = true;
1175 } else {
1176 request.result = false;
1177 loge("setNetworkSelectionModeManual " + ar.exception);
1178 }
1179 notifyRequester(request);
1180 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 break;
1182
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001183 case CMD_GET_MODEM_ACTIVITY_INFO:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001186 if (defaultPhone != null) {
1187 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001188 } else {
1189 ResultReceiver result = (ResultReceiver) request.argument;
1190 Bundle bundle = new Bundle();
1191 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1192 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1193 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001194 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001195 break;
1196
1197 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001200 ResultReceiver result = (ResultReceiver) request.argument;
1201
1202 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001203 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001204 // Update the last modem activity info and the result of the request.
1205 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1206 if (isModemActivityInfoValid(info)) {
1207 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1208 int[] txTimeMs = info.getTransmitTimeMillis();
1209 int[] lastModemTxTimeMs = mLastModemActivityInfo
1210 .getTransmitTimeMillis();
1211 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1212 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1213 }
1214 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1215 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1216 + mLastModemActivityInfo.getSleepTimeMillis());
1217 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1218 + mLastModemActivityInfo.getIdleTimeMillis());
1219 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1220 mLastModemActivityInfo.setReceiveTimeMillis(
1221 info.getReceiveTimeMillis()
1222 + mLastModemActivityInfo.getReceiveTimeMillis());
1223 }
1224 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1225 mLastModemActivityInfo.getSleepTimeMillis(),
1226 mLastModemActivityInfo.getIdleTimeMillis(),
1227 mLastModemActivityInfo.getTransmitTimeMillis(),
1228 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 } else {
1230 if (ar.result == null) {
1231 loge("queryModemActivityInfo: Empty response");
1232 } else if (ar.exception instanceof CommandException) {
1233 loge("queryModemActivityInfo: CommandException: " +
1234 ar.exception);
1235 } else {
1236 loge("queryModemActivityInfo: Unknown exception");
1237 }
1238 }
sqian1a1be542020-03-05 11:37:28 -08001239 Bundle bundle = new Bundle();
1240 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1241 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 break;
1244
Meng Wang1a7c35a2016-05-05 20:56:15 -07001245 case CMD_SET_ALLOWED_CARRIERS:
1246 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001247 CarrierRestrictionRules argument =
1248 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001249 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001250 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001251 break;
1252
1253 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1254 ar = (AsyncResult) msg.obj;
1255 request = (MainThreadRequest) ar.userObj;
1256 if (ar.exception == null && ar.result != null) {
1257 request.result = ar.result;
1258 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001259 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1260 if (ar.exception instanceof CommandException) {
1261 loge("setAllowedCarriers: CommandException: " + ar.exception);
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1265 request.result =
1266 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001268 } else {
1269 loge("setAllowedCarriers: Unknown exception");
1270 }
1271 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001272 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 break;
1274
1275 case CMD_GET_ALLOWED_CARRIERS:
1276 request = (MainThreadRequest) msg.obj;
1277 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001278 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 break;
1280
1281 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 if (ar.exception == null && ar.result != null) {
1285 request.result = ar.result;
1286 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001287 request.result = new IllegalStateException(
1288 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 if (ar.result == null) {
1290 loge("getAllowedCarriers: Empty response");
1291 } else if (ar.exception instanceof CommandException) {
1292 loge("getAllowedCarriers: CommandException: " +
1293 ar.exception);
1294 } else {
1295 loge("getAllowedCarriers: Unknown exception");
1296 }
1297 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001298 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 break;
1300
Nathan Haroldb3014052017-01-25 15:57:32 -08001301 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null && ar.result != null) {
1305 request.result = ar.result;
1306 } else {
1307 request.result = new IllegalArgumentException(
1308 "Failed to retrieve Forbidden Plmns");
1309 if (ar.result == null) {
1310 loge("getForbiddenPlmns: Empty response");
1311 } else {
1312 loge("getForbiddenPlmns: Unknown exception");
1313 }
1314 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001315 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001316 break;
1317
1318 case CMD_GET_FORBIDDEN_PLMNS:
1319 request = (MainThreadRequest) msg.obj;
1320 uiccCard = getUiccCardFromRequest(request);
1321 if (uiccCard == null) {
1322 loge("getForbiddenPlmns() UiccCard is null");
1323 request.result = new IllegalArgumentException(
1324 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001326 break;
1327 }
1328 Integer appType = (Integer) request.argument;
1329 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1330 if (uiccApp == null) {
1331 loge("getForbiddenPlmns() no app with specified type -- "
1332 + appType);
1333 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001334 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001335 break;
1336 } else {
1337 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1338 + " specified type -- " + appType);
1339 }
1340 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1341 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1342 onCompleted);
1343 break;
1344
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001345 case CMD_SWITCH_SLOTS:
1346 request = (MainThreadRequest) msg.obj;
1347 int[] physicalSlots = (int[]) request.argument;
1348 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1349 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1350 break;
1351
1352 case EVENT_SWITCH_SLOTS_DONE:
1353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
1355 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
1357 break;
1358 case CMD_GET_NETWORK_SELECTION_MODE:
1359 request = (MainThreadRequest) msg.obj;
1360 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1361 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1362 break;
1363
1364 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 if (ar.exception != null) {
1368 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1369 } else {
1370 int mode = ((int[]) ar.result)[0];
1371 if (mode == 0) {
1372 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1373 } else {
1374 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1375 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001376 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001377 notifyRequester(request);
1378 break;
1379 case CMD_GET_CDMA_ROAMING_MODE:
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1382 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1383 break;
1384 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception != null) {
1388 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1389 } else {
1390 request.result = ((int[]) ar.result)[0];
1391 }
1392 notifyRequester(request);
1393 break;
1394 case CMD_SET_CDMA_ROAMING_MODE:
1395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1397 int mode = (int) request.argument;
1398 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1399 break;
1400 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 request.result = ar.exception == null;
1404 notifyRequester(request);
1405 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001406 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1409 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1410 break;
1411 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception != null) {
1415 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1416 } else {
1417 request.result = ((int[]) ar.result)[0];
1418 }
1419 notifyRequester(request);
1420 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1424 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001425 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1426 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001427 break;
1428 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 request.result = ar.exception == null;
1432 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001433 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001434 case CMD_GET_ALL_CELL_INFO:
1435 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001436 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001437 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001438 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001439 case EVENT_GET_ALL_CELL_INFO_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001442 // If a timeout occurs, the response will be null
1443 request.result = (ar.exception == null && ar.result != null)
1444 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 synchronized (request) {
1446 request.notifyAll();
1447 }
1448 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001449 case CMD_REQUEST_CELL_INFO_UPDATE:
1450 request = (MainThreadRequest) msg.obj;
1451 request.phone.requestCellInfoUpdate(request.workSource,
1452 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1453 break;
1454 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1458 try {
1459 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001460 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001461 cb.onError(
1462 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1463 ar.exception.getClass().getName(),
1464 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001466 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001467 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001468 } else {
1469 // use the result as returned
1470 cb.onCellInfo((List<CellInfo>) ar.result);
1471 }
1472 } catch (RemoteException re) {
1473 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1474 }
1475 break;
Sarah Chincc055732020-11-18 13:39:35 -08001476 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 request = (MainThreadRequest) msg.obj;
1478 WorkSource ws = (WorkSource) request.argument;
1479 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001480 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 break;
Sarah Chincc055732020-11-18 13:39:35 -08001482 }
1483 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
1486 if (ar.exception == null) {
1487 request.result = ar.result;
1488 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001489 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001491 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 }
1493
1494 synchronized (request) {
1495 request.notifyAll();
1496 }
1497 break;
Sarah Chincc055732020-11-18 13:39:35 -08001498 }
chen xu6dac5ab2018-10-26 17:39:23 -07001499 case CMD_MODEM_REBOOT:
1500 request = (MainThreadRequest) msg.obj;
1501 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001502 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001503 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001504 case EVENT_CMD_MODEM_REBOOT_DONE:
1505 handleNullReturnEvent(msg, "rebootModem");
1506 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001507 case CMD_REQUEST_ENABLE_MODEM:
1508 request = (MainThreadRequest) msg.obj;
1509 boolean enable = (boolean) request.argument;
1510 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001511 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001512 PhoneConfigurationManager.getInstance()
1513 .enablePhone(request.phone, enable, onCompleted);
1514 break;
1515 case EVENT_ENABLE_MODEM_DONE:
1516 ar = (AsyncResult) msg.obj;
1517 request = (MainThreadRequest) ar.userObj;
1518 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001519 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001520 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001521 if ((boolean) request.result) {
1522 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1523 updateModemStateMetrics();
1524 } else {
1525 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1526 + ar.exception);
1527 }
1528 notifyRequester(request);
1529 break;
1530 case CMD_GET_MODEM_STATUS:
1531 request = (MainThreadRequest) msg.obj;
1532 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1533 PhoneConfigurationManager.getInstance()
1534 .getPhoneStatusFromModem(request.phone, onCompleted);
1535 break;
1536 case EVENT_GET_MODEM_STATUS_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 int id = request.phone.getPhoneId();
1540 if (ar.exception == null && ar.result != null) {
1541 request.result = ar.result;
1542 //update the cache as modem status has changed
1543 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1544 (boolean) request.result);
1545 } else {
1546 // Return true if modem status cannot be retrieved. For most cases,
1547 // modem status is on. And for older version modems, GET_MODEM_STATUS
1548 // and disable modem are not supported. Modem is always on.
1549 // TODO: this should be fixed in R to support a third
1550 // status UNKNOWN b/131631629
1551 request.result = true;
1552 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1553 + ar.exception);
1554 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001555 notifyRequester(request);
1556 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001557 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1558 request = (MainThreadRequest) msg.obj;
1559 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1560 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1561 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1562 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1563 break;
1564 }
1565 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1569 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1570 args.second.accept(ar.exception == null);
1571 notifyRequester(request);
1572 break;
1573 }
Sarah Chincc055732020-11-18 13:39:35 -08001574 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1577 Phone phone = getPhoneFromRequest(request);
1578 if (phone != null) {
1579 phone.getSystemSelectionChannels(onCompleted);
1580 } else {
1581 loge("getSystemSelectionChannels: No phone object");
1582 request.result = new ArrayList<RadioAccessSpecifier>();
1583 notifyRequester(request);
1584 }
1585 break;
1586 }
1587 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
1590 if (ar.exception == null && ar.result != null) {
1591 request.result = ar.result;
1592 } else {
1593 request.result = new IllegalArgumentException(
1594 "Failed to retrieve system selection channels");
1595 if (ar.result == null) {
1596 loge("getSystemSelectionChannels: Empty response");
1597 } else {
1598 loge("getSystemSelectionChannels: Unknown exception");
1599 }
1600 }
1601 notifyRequester(request);
1602 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001603 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
1606 if (ar.exception == null && ar.result != null) {
1607 request.result = ar.result;
1608 } else {
1609 request.result = -1;
1610 loge("Failed to set Forbidden Plmns");
1611 if (ar.result == null) {
1612 loge("setForbidenPlmns: Empty response");
1613 } else if (ar.exception != null) {
1614 loge("setForbiddenPlmns: Exception: " + ar.exception);
1615 request.result = -1;
1616 } else {
1617 loge("setForbiddenPlmns: Unknown exception");
1618 }
1619 }
1620 notifyRequester(request);
1621 break;
1622 case CMD_SET_FORBIDDEN_PLMNS:
1623 request = (MainThreadRequest) msg.obj;
1624 uiccCard = getUiccCardFromRequest(request);
1625 if (uiccCard == null) {
1626 loge("setForbiddenPlmns: UiccCard is null");
1627 request.result = -1;
1628 notifyRequester(request);
1629 break;
1630 }
1631 Pair<Integer, List<String>> setFplmnsArgs =
1632 (Pair<Integer, List<String>>) request.argument;
1633 appType = setFplmnsArgs.first;
1634 List<String> fplmns = setFplmnsArgs.second;
1635 uiccApp = uiccCard.getApplicationByType(appType);
1636 if (uiccApp == null) {
1637 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1638 request.result = -1;
1639 loge("Failed to get UICC App");
1640 notifyRequester(request);
1641 } else {
1642 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1643 ((SIMRecords) uiccApp.getIccRecords())
1644 .setForbiddenPlmns(onCompleted, fplmns);
1645 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001646 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001647 case CMD_ERASE_MODEM_CONFIG:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1650 defaultPhone.eraseModemConfig(onCompleted);
1651 break;
1652 case EVENT_ERASE_MODEM_CONFIG_DONE:
1653 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001654 break;
zoey chenf95ca592019-12-30 16:11:23 +08001655
1656 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1659 Pair<String, String> changed = (Pair<String, String>) request.argument;
1660 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1661 changed.first, changed.second, onCompleted);
1662 break;
1663 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 if (ar.exception == null) {
1667 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1668 } else {
1669 request.result = msg.arg1;
1670 }
1671 notifyRequester(request);
1672 break;
1673
1674 case CMD_SET_ICC_LOCK_ENABLED:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1677 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1678 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1679 enabled.first, enabled.second, onCompleted);
1680 break;
1681 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 if (ar.exception == null) {
1685 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1686 } else {
1687 request.result = msg.arg1;
1688 }
1689 notifyRequester(request);
1690 break;
1691
Peter Wangdafb9ac2020-01-15 14:13:38 -08001692 case MSG_NOTIFY_USER_ACTIVITY:
1693 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001694 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001695 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1696 getDefaultPhone().getContext().sendBroadcastAsUser(
1697 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1698 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001699
1700 case CMD_SET_DATA_THROTTLING: {
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1703 DataThrottlingRequest dataThrottlingRequest =
1704 (DataThrottlingRequest) request.argument;
1705 Phone phone = getPhoneFromRequest(request);
1706 if (phone != null) {
1707 phone.setDataThrottling(onCompleted,
1708 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1709 dataThrottlingRequest.getCompletionDurationMillis());
1710 } else {
1711 loge("setDataThrottling: No phone object");
1712 request.result =
1713 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1714 notifyRequester(request);
1715 }
1716
1717 break;
1718 }
1719 case EVENT_SET_DATA_THROTTLING_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722
1723 if (ar.exception == null) {
1724 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1725 } else if (ar.exception instanceof CommandException) {
1726 loge("setDataThrottling: CommandException: " + ar.exception);
1727 CommandException.Error error =
1728 ((CommandException) (ar.exception)).getCommandError();
1729
1730 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1731 request.result = TelephonyManager
1732 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1733 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1734 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1735 } else {
1736 request.result =
1737 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1738 }
1739 } else {
1740 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1741 }
1742 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1743 notifyRequester(request);
1744 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001745
1746 case CMD_SET_SIM_POWER: {
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1749 request = (MainThreadRequest) msg.obj;
1750 int stateToSet =
1751 ((Pair<Integer, IIntegerConsumer>)
1752 request.argument).first;
1753 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1754 break;
1755 }
1756 case EVENT_SET_SIM_POWER_DONE: {
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 IIntegerConsumer callback =
1760 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1761 if (ar.exception != null) {
1762 loge("setSimPower exception: " + ar.exception);
1763 int errorCode = TelephonyManager.CallForwardingInfoCallback
1764 .RESULT_ERROR_UNKNOWN;
1765 if (ar.exception instanceof CommandException) {
1766 CommandException.Error error =
1767 ((CommandException) (ar.exception)).getCommandError();
1768 if (error == CommandException.Error.SIM_ERR) {
1769 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1770 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1771 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1772 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1773 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1774 } else {
1775 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1776 }
1777 }
1778 try {
1779 callback.accept(errorCode);
1780 } catch (RemoteException e) {
1781 // Ignore if the remote process is no longer available to call back.
1782 Log.w(LOG_TAG, "setSimPower: callback not available.");
1783 }
1784 } else {
1785 try {
1786 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
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 }
1792 break;
1793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 default:
1796 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1797 break;
1798 }
1799 }
Jake Hambye994d462014-02-03 13:10:13 -08001800
Pengquan Menga1bb6272018-09-06 09:59:22 -07001801 private void notifyRequester(MainThreadRequest request) {
1802 synchronized (request) {
1803 request.notifyAll();
1804 }
1805 }
1806
Jake Hambye994d462014-02-03 13:10:13 -08001807 private void handleNullReturnEvent(Message msg, String command) {
1808 AsyncResult ar = (AsyncResult) msg.obj;
1809 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null) {
1811 request.result = true;
1812 } else {
1813 request.result = false;
1814 if (ar.exception instanceof CommandException) {
1815 loge(command + ": CommandException: " + ar.exception);
1816 } else {
1817 loge(command + ": Unknown exception");
1818 }
1819 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001820 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
1824 /**
1825 * Posts the specified command to be executed on the main thread,
1826 * waits for the request to complete, and returns the result.
1827 * @see #sendRequestAsync
1828 */
1829 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001830 return sendRequest(
1831 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001832 }
1833
1834 /**
1835 * Posts the specified command to be executed on the main thread,
1836 * waits for the request to complete, and returns the result.
1837 * @see #sendRequestAsync
1838 */
1839 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1840 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001841 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001842 }
1843
1844 /**
1845 * Posts the specified command to be executed on the main thread,
1846 * waits for the request to complete, and returns the result.
1847 * @see #sendRequestAsync
1848 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001849 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001850 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001851 }
1852
1853 /**
1854 * Posts the specified command to be executed on the main thread,
1855 * waits for the request to complete, and returns the result.
1856 * @see #sendRequestAsync
1857 */
Nathan Harold92bed182018-10-12 18:16:49 -07001858 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1859 return sendRequest(command, argument, subId, null, workSource);
1860 }
1861
1862 /**
1863 * Posts the specified command to be executed on the main thread,
1864 * waits for the request to complete, and returns the result.
1865 * @see #sendRequestAsync
1866 */
1867 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1868 return sendRequest(
1869 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1870 }
1871
1872 /**
1873 * Posts the specified command to be executed on the main thread,
1874 * waits for the request to complete, and returns the result.
1875 * @see #sendRequestAsync
1876 */
1877 private Object sendRequest(
1878 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1880 throw new RuntimeException("This method will deadlock if called from the main thread.");
1881 }
1882
Nathan Harold92bed182018-10-12 18:16:49 -07001883 MainThreadRequest request = null;
1884 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1885 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1886 } else if (phone != null) {
1887 request = new MainThreadRequest(argument, phone, workSource);
1888 } else {
1889 request = new MainThreadRequest(argument, subId, workSource);
1890 }
1891
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 Message msg = mMainThreadHandler.obtainMessage(command, request);
1893 msg.sendToTarget();
1894
1895 // Wait for the request to complete
1896 synchronized (request) {
1897 while (request.result == null) {
1898 try {
1899 request.wait();
1900 } catch (InterruptedException e) {
1901 // Do nothing, go back and wait until the request is complete
1902 }
1903 }
1904 }
1905 return request.result;
1906 }
1907
1908 /**
1909 * Asynchronous ("fire and forget") version of sendRequest():
1910 * Posts the specified command to be executed on the main thread, and
1911 * returns immediately.
1912 * @see #sendRequest
1913 */
1914 private void sendRequestAsync(int command) {
1915 mMainThreadHandler.sendEmptyMessage(command);
1916 }
1917
1918 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001919 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001920 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001921 */
1922 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001923 sendRequestAsync(command, argument, null, null);
1924 }
1925
1926 /**
1927 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1928 * @see {@link #sendRequest(int,Object)}
1929 */
1930 private void sendRequestAsync(
1931 int command, Object argument, Phone phone, WorkSource workSource) {
1932 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001933 Message msg = mMainThreadHandler.obtainMessage(command, request);
1934 msg.sendToTarget();
1935 }
1936
1937 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 * Initialize the singleton PhoneInterfaceManager instance.
1939 * This is only done once, at startup, from PhoneApp.onCreate().
1940 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001941 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 synchronized (PhoneInterfaceManager.class) {
1943 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001944 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 } else {
1946 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1947 }
1948 return sInstance;
1949 }
1950 }
1951
1952 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001953 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001956 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001957 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1959 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001960 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001961 mTelephonySharedPreferences =
1962 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001963 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001964 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001965 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001966
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 publish();
1968 }
1969
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 private Phone getDefaultPhone() {
1971 Phone thePhone = getPhone(getDefaultSubscription());
1972 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1973 }
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 private void publish() {
1976 if (DBG) log("publish: " + this);
1977
Peter Wangc035ce42020-01-08 21:00:22 -08001978 TelephonyFrameworkInitializer
1979 .getTelephonyServiceManager()
1980 .getTelephonyServiceRegisterer()
1981 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Stuart Scott584921c2015-01-15 17:10:34 -08001984 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001985 if (request.phone != null) {
1986 return request.phone;
1987 } else {
1988 return getPhoneFromSubId(request.subId);
1989 }
1990 }
1991
1992 private Phone getPhoneFromSubId(int subId) {
1993 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1994 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001995 }
1996
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001997 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1998 Phone phone = getPhoneFromRequest(request);
1999 return phone == null ? null :
2000 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2001 }
2002
Wink Saville36469e72014-06-11 15:17:00 -07002003 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002004 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002005 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002008 private void sendEraseModemConfig(Phone phone) {
2009 if (phone != null) {
2010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2011 mApp, phone.getSubId(), "eraseModemConfig");
2012 final long identity = Binder.clearCallingIdentity();
2013 try {
2014 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2015 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2016 } finally {
2017 Binder.restoreCallingIdentity(identity);
2018 }
2019 }
2020 }
2021
Peter Wang050bb052020-01-13 23:33:09 -08002022 private boolean isImsAvailableOnDevice() {
2023 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2024 if (pm == null) {
2025 // For some reason package manger is not available.. This will fail internally anyway,
2026 // so do not throw error and allow.
2027 return true;
2028 }
2029 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002033 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Wink Savilleb564aae2014-10-23 10:18:09 -07002036 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 if (DBG) log("dial: " + number);
2038 // No permission check needed here: This is just a wrapper around the
2039 // ACTION_DIAL intent, which is available to any app since it puts up
2040 // the UI before it does anything.
2041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 String url = createTelUrl(number);
2045 if (url == null) {
2046 return;
2047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049 // PENDING: should we just silently fail if phone is offhook or ringing?
2050 PhoneConstants.State state = mCM.getState(subId);
2051 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2052 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2053 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2054 mApp.startActivity(intent);
2055 }
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059 }
2060
2061 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002062 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 if (DBG) log("call: " + number);
2067
2068 // This is just a wrapper around the ACTION_CALL intent, but we still
2069 // need to do a permission check since we're calling startActivity()
2070 // from the context of the phone app.
2071 enforceCallPermission();
2072
Jordan Liu1617b712019-07-10 15:06:26 -07002073 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 != AppOpsManager.MODE_ALLOWED) {
2075 return;
2076 }
2077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 String url = createTelUrl(number);
2081 if (url == null) {
2082 return;
2083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002085 boolean isValid = false;
2086 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2087 if (slist != null) {
2088 for (SubscriptionInfo subInfoRecord : slist) {
2089 if (subInfoRecord.getSubscriptionId() == subId) {
2090 isValid = true;
2091 break;
2092 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002093 }
Wink Saville08874612014-08-31 19:19:58 -07002094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 if (!isValid) {
2096 return;
2097 }
Wink Saville08874612014-08-31 19:19:58 -07002098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2100 intent.putExtra(SUBSCRIPTION_KEY, subId);
2101 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2102 mApp.startActivity(intent);
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
2105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107
Wink Savilleb564aae2014-10-23 10:18:09 -07002108 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002109 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002110 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2111 }
2112
Wink Savilleb564aae2014-10-23 10:18:09 -07002113 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002114 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002115 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2116 }
2117
Wink Savilleb564aae2014-10-23 10:18:09 -07002118 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2124 checkSimPin.start();
2125 return checkSimPin.unlockSim(null, pin);
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
2128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2137 checkSimPuk.start();
2138 return checkSimPuk.unlockSim(puk, pin);
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
2144 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002145 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 * a synchronous one.
2147 */
2148 private static class UnlockSim extends Thread {
2149
2150 private final IccCard mSimCard;
2151
2152 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002153 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2154 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
2156 // For replies from SimCard interface
2157 private Handler mHandler;
2158
2159 // For async handler to identify request type
2160 private static final int SUPPLY_PIN_COMPLETE = 100;
2161
2162 public UnlockSim(IccCard simCard) {
2163 mSimCard = simCard;
2164 }
2165
2166 @Override
2167 public void run() {
2168 Looper.prepare();
2169 synchronized (UnlockSim.this) {
2170 mHandler = new Handler() {
2171 @Override
2172 public void handleMessage(Message msg) {
2173 AsyncResult ar = (AsyncResult) msg.obj;
2174 switch (msg.what) {
2175 case SUPPLY_PIN_COMPLETE:
2176 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2177 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002178 mRetryCount = msg.arg1;
2179 if (ar.exception != null) {
2180 if (ar.exception instanceof CommandException &&
2181 ((CommandException)(ar.exception)).getCommandError()
2182 == CommandException.Error.PASSWORD_INCORRECT) {
2183 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002184 } //When UiccCardApp dispose,handle message and return exception
2185 else if (ar.exception instanceof CommandException &&
2186 ((CommandException) (ar.exception)).getCommandError()
2187 == CommandException.Error.ABORTED) {
2188 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002189 } else {
2190 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2191 }
2192 } else {
2193 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 mDone = true;
2196 UnlockSim.this.notifyAll();
2197 }
2198 break;
2199 }
2200 }
2201 };
2202 UnlockSim.this.notifyAll();
2203 }
2204 Looper.loop();
2205 }
2206
2207 /*
2208 * Use PIN or PUK to unlock SIM card
2209 *
2210 * If PUK is null, unlock SIM card with PIN
2211 *
2212 * If PUK is not null, unlock SIM card with PUK and set PIN code
2213 */
Wink Saville9de0f752013-10-22 19:04:03 -07002214 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215
2216 while (mHandler == null) {
2217 try {
2218 wait();
2219 } catch (InterruptedException e) {
2220 Thread.currentThread().interrupt();
2221 }
2222 }
2223 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2224
2225 if (puk == null) {
2226 mSimCard.supplyPin(pin, callback);
2227 } else {
2228 mSimCard.supplyPuk(puk, pin, callback);
2229 }
2230
2231 while (!mDone) {
2232 try {
2233 Log.d(LOG_TAG, "wait for done");
2234 wait();
2235 } catch (InterruptedException e) {
2236 // Restore the interrupted status
2237 Thread.currentThread().interrupt();
2238 }
2239 }
2240 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002241 int[] resultArray = new int[2];
2242 resultArray[0] = mResult;
2243 resultArray[1] = mRetryCount;
2244 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246 }
2247
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002248 /**
2249 * This method has been removed due to privacy and stability concerns.
2250 */
2251 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002253 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2254 return;
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Nathan Harold1f889d82020-06-04 17:05:26 -07002257 @Override
2258 public void updateServiceLocationWithPackageName(String callingPackage) {
2259 mApp.getSystemService(AppOpsManager.class)
2260 .checkPackage(Binder.getCallingUid(), callingPackage);
2261
Nathan Haroldf096d982020-11-18 17:18:06 -08002262 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002263 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2264 // Callers targeting S have no business invoking this method.
2265 return;
2266 }
2267
2268 LocationAccessPolicy.LocationPermissionResult locationResult =
2269 LocationAccessPolicy.checkLocationPermission(mApp,
2270 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2271 .setCallingPackage(callingPackage)
2272 .setCallingFeatureId(null)
2273 .setCallingPid(Binder.getCallingPid())
2274 .setCallingUid(Binder.getCallingUid())
2275 .setMethod("updateServiceLocation")
2276 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2277 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2278 .build());
2279 // Apps that lack location permission have no business calling this method;
2280 // however, because no permission was declared in the public API, denials must
2281 // all be "soft".
2282 switch (locationResult) {
2283 case DENIED_HARD: /* fall through */
2284 case DENIED_SOFT:
2285 return;
2286 }
2287
2288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 final long identity = Binder.clearCallingIdentity();
2290 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002291 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002293 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 }
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002300 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
2302 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002303 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002306
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002308 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2309 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2310 callingFeatureId);
2311 }
2312
2313 @Deprecated
2314 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002316 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2317 }
2318
2319 @Override
2320 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2321 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002323 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 return false;
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 return isRadioOnForSubscriber(subId);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 }
2334
2335 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 if (phone != null) {
2340 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2341 } else {
2342 return false;
2343 }
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
2349 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002350 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
Wink Saville36469e72014-06-11 15:17:00 -07002352
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 if (phone != null) {
2360 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2361 }
2362 } finally {
2363 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 }
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
2367 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002368 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
Wink Savilleb564aae2014-10-23 10:18:09 -07002371 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002372 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373
2374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 final Phone phone = getPhone(subId);
2377 if (phone == null) {
2378 return false;
2379 }
2380 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2381 toggleRadioOnOffForSubscriber(subId);
2382 }
2383 return true;
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
Wink Saville36469e72014-06-11 15:17:00 -07002388
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002389 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002390 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002391 /*
2392 * If any of the Radios are available, it will need to be
2393 * shutdown. So return true if any Radio is available.
2394 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2398 Phone phone = PhoneFactory.getPhone(i);
2399 if (phone != null && phone.isRadioAvailable()) return true;
2400 }
2401 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2402 return false;
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002405 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002406 }
2407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002409 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 enforceModifyPermission();
2411
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2415 logv("Shutting down Phone " + i);
2416 shutdownRadioUsingPhoneId(i);
2417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002420 }
2421 }
2422
2423 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002424 Phone phone = PhoneFactory.getPhone(phoneId);
2425 if (phone != null && phone.isRadioAvailable()) {
2426 phone.shutdownRadio();
2427 }
2428 }
2429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2436 if (defaultPhone != null) {
2437 defaultPhone.setRadioPower(turnOn);
2438 return true;
2439 } else {
2440 loge("There's no default phone.");
2441 return false;
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002445 }
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Wink Savilleb564aae2014-10-23 10:18:09 -07002448 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null) {
2455 phone.setRadioPower(turnOn);
2456 return true;
2457 } else {
2458 return false;
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Wink Saville36469e72014-06-11 15:17:00 -07002465 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 public boolean enableDataConnectivity() {
2468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 int subId = mSubscriptionController.getDefaultDataSubId();
2473 final Phone phone = getPhone(subId);
2474 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002475 phone.getDataEnabledSettings().setDataEnabled(
2476 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 return true;
2478 } else {
2479 return false;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Wink Saville36469e72014-06-11 15:17:00 -07002486 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 public boolean disableDataConnectivity() {
2489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 int subId = mSubscriptionController.getDefaultDataSubId();
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002496 phone.getDataEnabledSettings().setDataEnabled(
2497 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 return true;
2499 } else {
2500 return false;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002508 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002513 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514 } else {
2515 return false;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
2522 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002523 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
2525
pkanwarae03a6b2016-11-06 20:37:09 -08002526 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 enforceCallPermission();
2528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2532 return;
2533 }
2534 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2535 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
pkanwar32d516d2016-10-14 19:37:38 -07002539 };
2540
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2547 return false;
2548 }
2549 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002556 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002557 }
2558
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002559 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 Phone phone = PhoneFactory.getPhone(slotIndex);
2563 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2564 PhoneConstantConversions.convertCallState(phone.getState());
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002571 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002572 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2573 }
2574
2575 @Override
2576 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 if (phone != null) {
2581 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2582 } else {
2583 return PhoneConstantConversions.convertDataState(
2584 PhoneConstants.DataState.DISCONNECTED);
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002592 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2594 }
2595
2596 @Override
2597 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
2602 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2603 } else {
2604 return TelephonyManager.DATA_ACTIVITY_NONE;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002612 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002613 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002614 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002615
2616 LocationAccessPolicy.LocationPermissionResult locationResult =
2617 LocationAccessPolicy.checkLocationPermission(mApp,
2618 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2619 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002620 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002621 .setCallingPid(Binder.getCallingPid())
2622 .setCallingUid(Binder.getCallingUid())
2623 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002624 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002625 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2626 .build());
2627 switch (locationResult) {
2628 case DENIED_HARD:
2629 throw new SecurityException("Not allowed to access cell location");
2630 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002631 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2632 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002639 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002640 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Svetoslav64fad262015-04-14 14:35:21 -07002644 }
2645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 @Override
Jack Yu01425032020-02-22 19:38:58 -08002647 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002648 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2649 // registered cell info, so return a NULL country instead.
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002652 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2653 // Get default phone in this case.
2654 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2655 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002656 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002658 if (phone == null) return "";
2659 ServiceStateTracker sst = phone.getServiceStateTracker();
2660 if (sst == null) return "";
2661 LocaleTracker lt = sst.getLocaleTracker();
2662 if (lt == null) return "";
2663 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2664 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2665 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002669 }
2670
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002671 /**
2672 * This method was removed due to potential issues caused by performing partial
2673 * updates of service state, and lack of a credible use case.
2674 *
2675 * This has the ability to break the telephony implementation by disabling notification of
2676 * changes in device connectivity. DO NOT USE THIS!
2677 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 public void enableLocationUpdates() {
2680 mApp.enforceCallingOrSelfPermission(
2681 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002684 /**
2685 * This method was removed due to potential issues caused by performing partial
2686 * updates of service state, and lack of a credible use case.
2687 *
2688 * This has the ability to break the telephony implementation by disabling notification of
2689 * changes in device connectivity. DO NOT USE THIS!
2690 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 @Override
2692 public void disableLocationUpdates() {
2693 mApp.enforceCallingOrSelfPermission(
2694 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
2697 @Override
2698 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002699 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2700 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002701 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002702 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2703 throw new SecurityException(
2704 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2705 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002706
Jordan Liu1617b712019-07-10 15:06:26 -07002707 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2709 return null;
2710 }
Svetoslav64fad262015-04-14 14:35:21 -07002711
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002712 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002714 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002715 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716
Nathan Haroldf180aac2018-06-01 18:43:55 -07002717 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2718 for (CellInfo ci : info) {
2719 if (ci instanceof CellInfoGsm) {
2720 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2721 } else if (ci instanceof CellInfoWcdma) {
2722 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002725 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002728 private List<CellInfo> getCachedCellInfo() {
2729 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2730 for (Phone phone : PhoneFactory.getPhones()) {
2731 List<CellInfo> info = phone.getAllCellInfo();
2732 if (info != null) cellInfos.addAll(info);
2733 }
2734 return cellInfos;
2735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736
2737 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002738 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002739 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002740 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002741
2742 LocationAccessPolicy.LocationPermissionResult locationResult =
2743 LocationAccessPolicy.checkLocationPermission(mApp,
2744 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2745 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002746 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002747 .setCallingPid(Binder.getCallingPid())
2748 .setCallingUid(Binder.getCallingUid())
2749 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002750 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2752 .build());
2753 switch (locationResult) {
2754 case DENIED_HARD:
2755 throw new SecurityException("Not allowed to access cell info");
2756 case DENIED_SOFT:
2757 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759
Nathan Haroldf096d982020-11-18 17:18:06 -08002760 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002761 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2762 return getCachedCellInfo();
2763 }
2764
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002765 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2770 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002771 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002772 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 if (info != null) cellInfos.addAll(info);
2774 }
2775 return cellInfos;
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779 }
2780
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002782 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2783 String callingFeatureId) {
2784 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2785 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002786 }
2787
2788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002789 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2790 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002791 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002792 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002793 }
2794
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002795 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2796 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002798 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002799
2800 LocationAccessPolicy.LocationPermissionResult locationResult =
2801 LocationAccessPolicy.checkLocationPermission(mApp,
2802 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2803 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002804 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002805 .setCallingPid(Binder.getCallingPid())
2806 .setCallingUid(Binder.getCallingUid())
2807 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002808 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2809 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002810 .build());
2811 switch (locationResult) {
2812 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002813 if (TelephonyPermissions
2814 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002815 // Safetynet logging for b/154934934
2816 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2817 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002818 throw new SecurityException("Not allowed to access cell info");
2819 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002820 if (TelephonyPermissions
2821 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002822 // Safetynet logging for b/154934934
2823 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2824 }
Nathan Harold5320c422019-05-09 10:26:08 -07002825 try {
2826 cb.onCellInfo(new ArrayList<CellInfo>());
2827 } catch (RemoteException re) {
2828 // Drop without consequences
2829 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002830 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002831 }
2832
Nathan Harolda939a962019-05-09 10:13:47 -07002833
2834 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002835 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2836
2837 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2838 }
2839
2840 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002842 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002843 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002847 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Shishir Agrawala9f32182016-04-12 12:00:16 -07002853 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002854 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002855 Phone phone = PhoneFactory.getPhone(slotIndex);
2856 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 return null;
2858 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002859 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002860 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002861 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002862 return null;
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 return phone.getImei();
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002871 }
2872
2873 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002874 public String getTypeAllocationCodeForSlot(int slotIndex) {
2875 Phone phone = PhoneFactory.getPhone(slotIndex);
2876 String tac = null;
2877 if (phone != null) {
2878 String imei = phone.getImei();
2879 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2880 }
2881 return tac;
2882 }
2883
2884 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002885 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002886 Phone phone = PhoneFactory.getPhone(slotIndex);
2887 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002888 return null;
2889 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002890
Jeff Davidson913390f2018-02-23 17:11:49 -08002891 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002892 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002893 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002894 return null;
2895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 return phone.getMeid();
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
Jack Yu2af8d712017-03-15 17:14:14 -07002903 }
2904
2905 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002906 public String getManufacturerCodeForSlot(int slotIndex) {
2907 Phone phone = PhoneFactory.getPhone(slotIndex);
2908 String manufacturerCode = null;
2909 if (phone != null) {
2910 String meid = phone.getMeid();
2911 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2912 }
2913 return manufacturerCode;
2914 }
2915
2916 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002917 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002919 Phone phone = PhoneFactory.getPhone(slotIndex);
2920 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 return null;
2922 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002923 int subId = phone.getSubId();
2924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 mApp, subId, callingPackage, callingFeatureId,
2926 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002927 return null;
2928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 return phone.getDeviceSvn();
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002936 }
2937
fionaxu43304da2017-11-27 22:51:16 -08002938 @Override
2939 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 final Phone phone = getPhone(subId);
2943 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
fionaxu43304da2017-11-27 22:51:16 -08002947 }
2948
2949 @Override
2950 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 final Phone phone = getPhone(subId);
2954 return phone == null ? null : phone.getCarrierName();
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu43304da2017-11-27 22:51:16 -08002958 }
2959
calvinpanffe225e2018-11-01 19:43:06 +08002960 @Override
chen xu0026ca62019-03-06 15:28:50 -08002961 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 final Phone phone = getPhone(subId);
2965 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002966 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
chen xu0026ca62019-03-06 15:28:50 -08002973 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002977 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
chen xu651eec72018-11-11 19:03:44 -08002983 @Override
chen xu864e11c2018-12-06 22:10:03 -08002984 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2985 if (!isSubscriptionMccMnc) {
2986 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2987 }
chen xu651eec72018-11-11 19:03:44 -08002988 final Phone phone = PhoneFactory.getPhone(slotIndex);
2989 if (phone == null) {
2990 return TelephonyManager.UNKNOWN_CARRIER_ID;
2991 }
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 }
2999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 //
3001 // Internal helper methods.
3002 //
3003
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003004 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3006 *
3007 * @throws SecurityException if the caller does not have the required permission
3008 */
3009 private void enforceModifyPermission() {
3010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3011 }
3012
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003013 /**
3014 * Make sure the caller is system.
3015 *
3016 * @throws SecurityException if the caller is not system.
3017 */
3018 private void enforceSystemCaller() {
3019 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3020 throw new SecurityException("Caller must be system");
3021 }
3022 }
3023
Shuo Qianf2b2df42019-11-13 17:43:31 -08003024 private void enforceActiveEmergencySessionPermission() {
3025 mApp.enforceCallingOrSelfPermission(
3026 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3027 }
3028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 /**
3030 * Make sure the caller has the CALL_PHONE permission.
3031 *
3032 * @throws SecurityException if the caller does not have the required permission
3033 */
3034 private void enforceCallPermission() {
3035 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3036 }
3037
paulhu423b5f22019-08-23 19:17:33 +08003038 private void enforceSettingsPermission() {
3039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003040 }
3041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 private String createTelUrl(String number) {
3043 if (TextUtils.isEmpty(number)) {
3044 return null;
3045 }
3046
Jake Hambye994d462014-02-03 13:10:13 -08003047 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 }
3049
Ihab Awadf9e92732013-12-05 18:02:52 -08003050 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3052 }
3053
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003054 private static void logv(String msg) {
3055 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3056 }
3057
Ihab Awadf9e92732013-12-05 18:02:52 -08003058 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3060 }
3061
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003062 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003064 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003065 }
3066
Sanket Padawe356d7632015-06-22 14:03:32 -07003067 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003068 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = PhoneFactory.getPhone(slotIndex);
3072 if (phone == null) {
3073 return PhoneConstants.PHONE_TYPE_NONE;
3074 } else {
3075 return phone.getPhoneType();
3076 }
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 }
3081
3082 /**
3083 * Returns the CDMA ERI icon index to display
3084 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003085 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003086 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3087 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3088 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003089 }
3090
Sanket Padawe356d7632015-06-22 14:03:32 -07003091 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003092 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003095 mApp, subId, callingPackage, callingFeatureId,
3096 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003097 return -1;
3098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 final Phone phone = getPhone(subId);
3103 if (phone != null) {
3104 return phone.getCdmaEriIconIndex();
3105 } else {
3106 return -1;
3107 }
3108 } finally {
3109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 }
3112
3113 /**
3114 * Returns the CDMA ERI icon mode,
3115 * 0 - ON
3116 * 1 - FLASHING
3117 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003118 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003119 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3120 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3121 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003122 }
3123
Sanket Padawe356d7632015-06-22 14:03:32 -07003124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003125 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3126 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003128 mApp, subId, callingPackage, callingFeatureId,
3129 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003130 return -1;
3131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final Phone phone = getPhone(subId);
3136 if (phone != null) {
3137 return phone.getCdmaEriIconMode();
3138 } else {
3139 return -1;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
3146 /**
3147 * Returns the CDMA ERI text,
3148 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003149 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003150 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3151 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3152 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003156 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3157 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003159 mApp, subId, callingPackage, callingFeatureId,
3160 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003161 return null;
3162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 final Phone phone = getPhone(subId);
3167 if (phone != null) {
3168 return phone.getCdmaEriText();
3169 } else {
3170 return null;
3171 }
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 }
3176
3177 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003178 * Returns the CDMA MDN.
3179 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3183 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 return phone.getLine1Number();
3190 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 return null;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003196 }
3197 }
3198
3199 /**
3200 * Returns the CDMA MIN.
3201 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003202 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003203 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3205 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 final Phone phone = getPhone(subId);
3210 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3211 return phone.getCdmaMin();
3212 } else {
3213 return null;
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003217 }
3218 }
3219
Hall Liud892bec2018-11-30 14:51:45 -08003220 @Override
3221 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3222 INumberVerificationCallback callback, String callingPackage) {
3223 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3224 != PERMISSION_GRANTED) {
3225 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3226 }
3227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3228
3229 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3230 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3231 throw new SecurityException("Calling package must be configured in the device config");
3232 }
3233
3234 if (range == null) {
3235 throw new NullPointerException("Range must be non-null");
3236 }
3237
3238 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003239 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003240
3241 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3242 }
3243
Junda Liuca05d5d2014-08-14 22:36:34 -07003244 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 * Returns true if CDMA provisioning needs to run.
3246 */
3247 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003250 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003257 * Sets the voice mail number of a given subId.
3258 */
3259 @Override
3260 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003261 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3262 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3267 new Pair<String, String>(alphaTag, number), new Integer(subId));
3268 return success;
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003272 }
3273
Ta-wei Yen87c49842016-05-13 21:19:52 -07003274 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003275 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003277 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3278 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003279 if (!TextUtils.equals(callingPackage, systemDialer)) {
3280 throw new SecurityException("caller must be system dialer");
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3286 if (phoneAccountHandle == null) {
3287 return null;
3288 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003292 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003293 }
3294
3295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3297 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003300 mApp, subId, callingPackage, callingFeatureId,
3301 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003302 return null;
3303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003305 final long identity = Binder.clearCallingIdentity();
3306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003311 }
3312
3313 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003314 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3315 VisualVoicemailSmsFilterSettings settings) {
3316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003325 }
3326
3327 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003328 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003338 }
3339
3340 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003341 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3342 String callingPackage, int subId) {
3343 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003352 }
3353
3354 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003355 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003365 }
3366
3367 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003368 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3369 String callingAttributionTag, int subId, String number, int port, String text,
3370 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003372 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003373 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003374 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003375 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3376 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003377 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003378
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003379 /**
fionaxu0152e512016-11-14 13:36:14 -08003380 * Sets the voice activation state of a given subId.
3381 */
3382 @Override
3383 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3385 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 final Phone phone = getPhone(subId);
3390 if (phone != null) {
3391 phone.setVoiceActivationState(activationState);
3392 } else {
3393 loge("setVoiceActivationState fails with invalid subId: " + subId);
3394 }
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003397 }
3398 }
3399
3400 /**
3401 * Sets the data activation state of a given subId.
3402 */
3403 @Override
3404 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3406 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 phone.setDataActivationState(activationState);
3413 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003414 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003418 }
3419 }
3420
3421 /**
3422 * Returns the voice activation state of a given subId.
3423 */
3424 @Override
3425 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427
fionaxu0152e512016-11-14 13:36:14 -08003428 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 if (phone != null) {
3432 return phone.getVoiceActivationState();
3433 } else {
3434 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3435 }
3436 } finally {
3437 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003438 }
3439 }
3440
3441 /**
3442 * Returns the data activation state of a given subId.
3443 */
3444 @Override
3445 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
fionaxu0152e512016-11-14 13:36:14 -08003448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 if (phone != null) {
3452 return phone.getDataActivationState();
3453 } else {
3454 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3455 }
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003458 }
3459 }
3460
3461 /**
Wink Saville36469e72014-06-11 15:17:00 -07003462 * Returns the unread count of voicemails for a subId
3463 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003464 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003465 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3466 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003468 mApp, subId, callingPackage, callingFeatureId,
3469 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003470 return 0;
3471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 return phone.getVoiceMessageCount();
3477 } else {
3478 return 0;
3479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003486 * returns true, if the device is in a state where both voice and data
3487 * are supported simultaneously. This can change based on location or network condition.
3488 */
3489 @Override
3490 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 final Phone phone = getPhone(subId);
3494 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003498 }
3499
3500 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003501 * Send the dialer code if called from the current default dialer or the caller has
3502 * carrier privilege.
3503 * @param inputCode The dialer code to send
3504 */
3505 @Override
3506 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003509 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3510 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003511 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003513 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
fionaxu235cc5e2017-03-06 22:25:57 -08003522 }
3523
Pengquan Menga1bb6272018-09-06 09:59:22 -07003524 @Override
3525 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003526 TelephonyPermissions
3527 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3528 mApp, subId, "getNetworkSelectionMode");
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 if (!isActiveSubscription(subId)) {
3532 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3533 }
3534 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003537 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003538 }
3539
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003541 public boolean isInEmergencySmsMode() {
3542 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 for (Phone phone : PhoneFactory.getPhones()) {
3546 if (phone.isInEmergencySmsMode()) {
3547 return true;
3548 }
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
3553 return false;
3554 }
3555
shilu366312e2019-12-17 09:28:10 -08003556 /**
3557 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3558 * @param subId The subscription to use to check the configuration.
3559 * @param c The callback that will be used to send the result.
3560 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003561 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003562 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3563 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003564 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3565 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003566
Brad Ebinger77b832e2019-10-17 17:03:22 -07003567 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3568 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3569 "IMS not available on device.");
3570 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 final long token = Binder.clearCallingIdentity();
3572 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(token);
3580 }
3581 }
3582
shilu366312e2019-12-17 09:28:10 -08003583 /**
3584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3585 * @param subId The subscription to use to check the configuration.
3586 * @param c The callback that will be used to send the result.
3587 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003589 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003590 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3591 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3593 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3594 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003595 final long token = Binder.clearCallingIdentity();
3596 try {
3597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3598 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3599 .removeRegistrationCallbackForSubscription(c, subId);
3600 } catch (ImsException e) {
3601 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3602 + "is inactive, ignoring unregister.");
3603 // If the subscription is no longer active, just return, since the callback
3604 // will already have been removed internally.
3605 } finally {
3606 Binder.restoreCallingIdentity(token);
3607 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 }
3609
Brad Ebinger774ba362019-10-22 17:36:18 -07003610 /**
3611 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3612 */
3613 @Override
3614 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3615 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3616 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3617 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3618 "IMS not available on device.");
3619 }
3620 final long token = Binder.clearCallingIdentity();
3621 try {
3622 Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3625 + subId + "'");
3626 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3627 }
3628 phone.getImsRegistrationState(regState -> {
3629 try {
3630 consumer.accept((regState == null)
3631 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3632 } catch (RemoteException e) {
3633 // Ignore if the remote process is no longer available to call back.
3634 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3635 }
3636 });
3637 } finally {
3638 Binder.restoreCallingIdentity(token);
3639 }
3640 }
3641
3642 /**
3643 * Get the transport type for the IMS service registration state.
3644 */
3645 @Override
3646 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003647 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3648 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003649 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3651 "IMS not available on device.");
3652 }
3653 final long token = Binder.clearCallingIdentity();
3654 try {
3655 Phone phone = getPhone(subId);
3656 if (phone == null) {
3657 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3658 + subId + "'");
3659 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3660 }
3661 phone.getImsRegistrationTech(regTech -> {
3662 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3663 int regTechConverted = (regTech == null)
3664 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3665 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3666 regTechConverted);
3667 try {
3668 consumer.accept(regTechConverted);
3669 } catch (RemoteException e) {
3670 // Ignore if the remote process is no longer available to call back.
3671 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3672 }
3673 });
3674 } finally {
3675 Binder.restoreCallingIdentity(token);
3676 }
3677 }
3678
shilu366312e2019-12-17 09:28:10 -08003679 /**
3680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3681 * @param subId The subscription to use to check the configuration.
3682 * @param c The callback that will be used to send the result.
3683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003685 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3686 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003687 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3688 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003689 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3691 "IMS not available on device.");
3692 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3694 final long token = Binder.clearCallingIdentity();
3695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (ImsException e) {
3699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 } finally {
3701 Binder.restoreCallingIdentity(token);
3702 }
3703 }
3704
shilu366312e2019-12-17 09:28:10 -08003705 /**
3706 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3707 * @param subId The subscription to use to check the configuration.
3708 * @param c The callback that will be used to send the result.
3709 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003711 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003712 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3713 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003714 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3715 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3716 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003717
3718 final long token = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003723 } catch (ImsException e) {
3724 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3725 + "is inactive, ignoring unregister.");
3726 // If the subscription is no longer active, just return, since the callback
3727 // will already have been removed internally.
3728 } finally {
3729 Binder.restoreCallingIdentity(token);
3730 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 }
3732
3733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003734 public boolean isCapable(int subId, int capability, int regTech) {
3735 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3737 final long token = Binder.clearCallingIdentity();
3738 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3743 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003745 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3746 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(token);
3749 }
3750 }
3751
3752 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003753 public boolean isAvailable(int subId, int capability, int regTech) {
3754 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 final long token = Binder.clearCallingIdentity();
3756 try {
3757 Phone phone = getPhone(subId);
3758 if (phone == null) return false;
3759 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003760 } catch (com.android.ims.ImsException e) {
3761 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3762 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
3766 }
3767
Brad Ebinger77b832e2019-10-17 17:03:22 -07003768 /**
3769 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3770 * subscription.
3771 * @param subId The subscription to use to check the configuration.
3772 * @param callback The callback that will be used to send the result.
3773 * @param capability The MmTelFeature capability that will be used to send the result.
3774 * @param transportType The transport type of the MmTelFeature capability.
3775 */
3776 @Override
3777 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3778 int transportType) {
3779 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3780 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3782 "IMS not available on device.");
3783 }
3784 final long token = Binder.clearCallingIdentity();
3785 try {
3786 int slotId = getSlotIndex(subId);
3787 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3788 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3789 + subId + "'");
3790 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3791 }
3792 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3793 transportType, aBoolean -> {
3794 try {
3795 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3796 } catch (RemoteException e) {
3797 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3798 + "running. Ignore");
3799 }
3800 });
3801 } finally {
3802 Binder.restoreCallingIdentity(token);
3803 }
3804 }
3805
shilu366312e2019-12-17 09:28:10 -08003806 /**
3807 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3808 * @param subId The subscription to use to check the configuration.
3809 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 @Override
3811 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003812 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3813 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003814
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3816 final long token = Binder.clearCallingIdentity();
3817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003818 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003820 } catch (ImsException e) {
3821 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
3825 }
3826
3827 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003828 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003830 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003834 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003836 } catch (ImsException e) {
3837 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 } finally {
3839 Binder.restoreCallingIdentity(identity);
3840 }
3841 }
3842
shilu366312e2019-12-17 09:28:10 -08003843 /**
3844 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3845 * @param subId The subscription to use to check the configuration.
3846 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003848 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003849 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3850 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3855 } catch (ImsException e) {
3856 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860 }
3861
3862 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003863 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003865 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 } catch (ImsException e) {
3871 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875 }
3876
shilu366312e2019-12-17 09:28:10 -08003877 /**
3878 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3879 * @param subId The subscription to use to check the configuration.
3880 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 @Override
3882 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003883 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3884 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 } catch (ImsException e) {
3891 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003898 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003900 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003905 } catch (ImsException e) {
3906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
shilu366312e2019-12-17 09:28:10 -08003912 /**
3913 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3914 * @param subId The subscription to use to check the configuration.
3915 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 @Override
3917 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003918 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3919 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003925 } catch (ImsException e) {
3926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
3930 }
3931
3932 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003933 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003935 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003939 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003941 } catch (ImsException e) {
3942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
3946 }
3947
3948 @Override
3949 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3951 "setVoWiFiNonPersistent");
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003956 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 @Override
3969 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3971 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003977 } catch (ImsException e) {
3978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
3984 @Override
3985 public void setVoWiFiModeSetting(int subId, int mode) {
3986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3987 "setVoWiFiModeSetting");
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
4000 @Override
4001 public int getVoWiFiRoamingModeSetting(int subId) {
4002 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004006 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004008 } catch (ImsException e) {
4009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 }
4014
4015 @Override
4016 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4018 "setVoWiFiRoamingModeSetting");
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004024 } catch (ImsException e) {
4025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setRttCapabilityEnabled");
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044 }
4045
shilu366312e2019-12-17 09:28:10 -08004046 /**
4047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4048 * @param subId The subscription to use to check the configuration.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
4051 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4053 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004059 } catch (ImsException e) {
4060 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064 }
4065
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004066 @Override
4067 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4068 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004071 if (!isImsAvailableOnDevice()) {
4072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4073 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004074 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004076 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004077 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
4083 }
4084
4085 @Override
4086 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4087 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4088 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004089 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4090 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4091 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004092 try {
4093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004095 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004097 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4098 + "is inactive, ignoring unregister.");
4099 // If the subscription is no longer active, just return, since the callback will already
4100 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
allenwtsu99c623b2020-01-03 18:24:23 +08004106
4107 private void checkModifyPhoneStatePermission(int subId, String message) {
4108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4109 message);
4110 }
4111
4112 private boolean isImsProvisioningRequired(int subId, int capability,
4113 boolean isMmtelCapability) {
4114 Phone phone = getPhone(subId);
4115 if (phone == null) {
4116 loge("phone instance null for subid " + subId);
4117 return false;
4118 }
4119 if (isMmtelCapability) {
4120 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4121 return false;
4122 }
4123 } else {
4124 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4125 return false;
4126 }
4127 }
4128 return true;
4129 }
4130
4131 @Override
4132 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4133 boolean isProvisioned) {
4134 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4135
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4139 if (!isImsProvisioningRequired(subId, capability, false)) {
4140 return;
4141 }
4142
4143 // this capability requires provisioning, route to the correct API.
4144 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4145 switch (capability) {
4146 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4147 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4148 ims.setEabProvisioned(isProvisioned);
4149 break;
4150 default: {
4151 throw new IllegalArgumentException("Tried to set provisioning for "
4152 + "rcs capability '" + capability + "', which does not require "
4153 + "provisioning.");
4154 }
4155 }
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159
4160 }
4161
4162
4163 @Override
4164 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4165 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4169 if (!isImsProvisioningRequired(subId, capability, false)) {
4170 return true;
4171 }
4172
4173 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4174 switch (capability) {
4175 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4176 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4177 return ims.isEabProvisionedOnDevice();
4178
4179 default: {
4180 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4181 + "capability '" + capability + "', which does not require "
4182 + "provisioning.");
4183 }
4184 }
4185
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004192 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4193 boolean isProvisioned) {
4194 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4195 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4196 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4197 }
allenwtsu99c623b2020-01-03 18:24:23 +08004198 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004202 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 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 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4210 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4211 ims.setVolteProvisioned(isProvisioned);
4212 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4213 ims.setWfcProvisioned(isProvisioned);
4214 }
4215 break;
4216 }
4217 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4218 // There is currently no difference in VT provisioning type.
4219 ims.setVtProvisioned(isProvisioned);
4220 break;
4221 }
4222 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4223 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4224 // change the capability of the feature instead if needed.
4225 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4226 == isProvisioned) {
4227 // No change in provisioning.
4228 return;
4229 }
4230 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4231 try {
4232 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004234 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4235 + ", Exception" + e.getMessage());
4236 }
4237 break;
4238 }
4239 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004240 throw new IllegalArgumentException("Tried to set provisioning for "
4241 + "MmTel capability '" + capability + "', which does not require "
4242 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004243 }
4244 }
4245
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
4251 @Override
4252 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4253 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4254 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4255 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4256 }
4257 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004261 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004262 return true;
4263 }
4264
4265 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4266 switch (capability) {
4267 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4268 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4269 return ims.isVolteProvisionedOnDevice();
4270 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4271 return ims.isWfcProvisionedOnDevice();
4272 }
4273 // This should never happen, since we are checking tech above to make sure it
4274 // is either LTE or IWLAN.
4275 throw new IllegalArgumentException("Invalid radio technology for voice "
4276 + "capability.");
4277 }
4278 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4279 // There is currently no difference in VT provisioning type.
4280 return ims.isVtProvisionedOnDevice();
4281 }
4282 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4283 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4284 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4285 }
4286 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004287 throw new IllegalArgumentException(
4288 "Tried to get provisioning for MmTel capability '" + capability
4289 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004290 }
4291 }
4292
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
4296 }
4297
4298 @Override
4299 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4300 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4301 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4302 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4303 }
4304 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4305 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4306 return (provisionedBits & capability) > 0;
4307 }
4308
4309 @Override
4310 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4311 boolean isProvisioned) {
4312 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4313 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4314 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4315 }
4316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4317 "setProvisioningStatusForCapability");
4318 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4319 // If the current provisioning status for capability already matches isProvisioned,
4320 // do nothing.
4321 if (((provisionedBits & capability) > 0) == isProvisioned) {
4322 return;
4323 }
4324 if (isProvisioned) {
4325 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4326 } else {
4327 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4328 }
4329 }
4330
4331 /**
4332 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4333 * technology. The bitfield should mirror the bitfield defined by
4334 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4335 */
4336 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4337 String key = getMmTelProvisioningKey(subId, tech);
4338 // Default is no capabilities are provisioned.
4339 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4340 }
4341
4342 /**
4343 * Sets the MmTel capability provisioning bitfield (defined by
4344 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4345 * technology specified.
4346 *
4347 * Note: This is a synchronous command and should not be called on UI thread.
4348 */
4349 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4350 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4351 String key = getMmTelProvisioningKey(subId, tech);
4352 editor.putInt(key, newField);
4353 editor.commit();
4354 }
4355
4356 private static String getMmTelProvisioningKey(int subId, int tech) {
4357 // resulting key is provision_ims_mmtel_{subId}_{tech}
4358 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4359 }
4360
4361 /**
4362 * Query CarrierConfig to see if the specified capability requires provisioning for the
4363 * carrier associated with the subscription id.
4364 */
4365 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4366 int capability) {
4367 CarrierConfigManager configManager = new CarrierConfigManager(context);
4368 PersistableBundle c = configManager.getConfigForSubId(subId);
4369 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004370 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004371 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4372 false);
4373 boolean requireVoiceVtProvisioning = c.getBoolean(
4374 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4375
4376 // First check to make sure that the capability requires provisioning.
4377 switch (capability) {
4378 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4379 // intentional fallthrough
4380 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4381 if (requireVoiceVtProvisioning) {
4382 // Voice and Video requires provisioning
4383 return true;
4384 }
4385 break;
4386 }
4387 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4388 if (requireUtProvisioning) {
4389 // UT requires provisioning
4390 return true;
4391 }
4392 break;
4393 }
4394 }
4395 return false;
4396 }
4397
allenwtsu99c623b2020-01-03 18:24:23 +08004398 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4399 int capability) {
4400 CarrierConfigManager configManager = new CarrierConfigManager(context);
4401 PersistableBundle c = configManager.getConfigForSubId(subId);
4402
4403 boolean requireRcsProvisioning = c.getBoolean(
4404 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4405
4406 // First check to make sure that the capability requires provisioning.
4407 switch (capability) {
4408 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4409 // intentional fallthrough
4410 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4411 if (requireRcsProvisioning) {
4412 // OPTION or PRESENCE requires provisioning
4413 return true;
4414 }
4415 break;
4416 }
4417 }
4418 return false;
4419 }
4420
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004421 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004422 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4424 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4425 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 enforceReadPrivilegedPermission("getImsProvisioningInt");
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004430 int slotId = getSlotIndex(subId);
4431 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4432 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4433 + subId + "' for key:" + key);
4434 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4435 }
4436 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004438 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4439 + subId + "' for key:" + key);
4440 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
4447 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004448 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4449 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4450 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004451 enforceReadPrivilegedPermission("getImsProvisioningString");
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 int slotId = getSlotIndex(subId);
4456 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4457 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4458 + subId + "' for key:" + key);
4459 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4460 }
4461 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4464 + subId + "' for key:" + key);
4465 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004473 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4474 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4475 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004481 int slotId = getSlotIndex(subId);
4482 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4483 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4484 + subId + "' for key:" + key);
4485 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4486 }
4487 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004489 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4490 + "' for key:" + key);
4491 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
4498 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4500 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4501 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4503 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004507 int slotId = getSlotIndex(subId);
4508 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4509 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4510 + subId + "' for key:" + key);
4511 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4512 }
4513 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004515 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4516 + "' for key:" + key);
4517 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 int slotId = SubscriptionManager.getSlotIndex(subId);
4525 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4527 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 }
4529 return slotId;
4530 }
4531
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004532 private int getSlotIndex(int subId) {
4533 int slotId = SubscriptionManager.getSlotIndex(subId);
4534 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4535 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4536 }
4537 return slotId;
4538 }
4539
Wink Saville36469e72014-06-11 15:17:00 -07004540 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004541 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004542 */
4543 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004544 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4545 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004546 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004547 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004548 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004549 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004550 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004551 mApp, subId, callingPackage, callingFeatureId,
4552 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4554 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 final Phone phone = getPhone(subId);
4559 if (phone != null) {
4560 return phone.getServiceState().getDataNetworkType();
4561 } else {
4562 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4563 }
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004567 }
4568
4569 /**
4570 * Returns the data network type
4571 */
4572 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004573 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4574 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4575 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004576 }
4577
4578 /**
4579 * Returns the data network type for a subId
4580 */
4581 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004582 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4583 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004585 mApp, subId, callingPackage, callingFeatureId,
4586 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4588 }
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 final Phone phone = getPhone(subId);
4593 if (phone != null) {
4594 return phone.getServiceState().getDataNetworkType();
4595 } else {
4596 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4597 }
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004601 }
4602
4603 /**
Wink Saville36469e72014-06-11 15:17:00 -07004604 * Returns the Voice network type for a subId
4605 */
4606 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004607 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4608 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004610 mApp, subId, callingPackage, callingFeatureId,
4611 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004612 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4613 }
4614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 final Phone phone = getPhone(subId);
4618 if (phone != null) {
4619 return phone.getServiceState().getVoiceNetworkType();
4620 } else {
4621 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4622 }
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004626 }
4627
4628 /**
4629 * @return true if a ICC card is present
4630 */
4631 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004632 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004633 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4634 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004635 }
4636
4637 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004638 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004639 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004640 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004641 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 final Phone phone = PhoneFactory.getPhone(slotIndex);
4645 if (phone != null) {
4646 return phone.getIccCard().hasIccCard();
4647 } else {
4648 return false;
4649 }
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004653 }
4654
4655 /**
4656 * Return if the current radio is LTE on CDMA. This
4657 * is a tri-state return value as for a period of time
4658 * the mode may be unknown.
4659 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004660 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004661 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004662 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004663 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004664 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004665 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4666 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4667 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004668 }
4669
Sanket Padawe356d7632015-06-22 14:03:32 -07004670 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004671 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4672 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004673 try {
4674 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4675 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004676 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4677 }
4678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 final Phone phone = getPhone(subId);
4682 if (phone == null) {
4683 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4684 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004685 return TelephonyProperties.lte_on_cdma_device()
4686 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004690 }
Wink Saville36469e72014-06-11 15:17:00 -07004691 }
4692
Wink Saville36469e72014-06-11 15:17:00 -07004693 /**
4694 * {@hide}
4695 * Returns Default subId, 0 in the case of single standby.
4696 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004697 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004698 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004699 }
4700
Shishir Agrawala9f32182016-04-12 12:00:16 -07004701 private int getSlotForDefaultSubscription() {
4702 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4703 }
4704
Wink Savilleb564aae2014-10-23 10:18:09 -07004705 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004706 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004707 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004708
Pengquan Menge92a50d2018-09-21 15:54:48 -07004709 private boolean isActiveSubscription(int subId) {
4710 return mSubscriptionController.isActiveSubId(subId);
4711 }
4712
Ihab Awadf2177b72013-11-25 13:33:23 -08004713 /**
4714 * @see android.telephony.TelephonyManager.WifiCallingChoices
4715 */
4716 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004719 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4721 getWhenToMakeWifiCallsDefaultPreference());
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004725 }
4726
4727 /**
4728 * @see android.telephony.TelephonyManager.WifiCallingChoices
4729 */
4730 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004734 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004739 }
4740
Sailesh Nepald1e68152013-12-12 19:08:02 -08004741 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004742 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004743 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004744 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004745
Jordan Liu4c733742019-02-28 12:03:40 -08004746 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4747 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4748 if (phoneId == -1) {
4749 throw new IllegalArgumentException("Given slot index: " + slotIndex
4750 + " does not correspond to an active phone");
4751 }
4752 return PhoneFactory.getPhone(phoneId);
4753 }
4754
Shishir Agrawal566b7612013-10-28 14:41:00 -07004755 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004756 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4757 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4759 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004761 if (DBG) {
4762 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4763 }
4764 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4765 p2);
4766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004767
Jordan Liu4c733742019-02-28 12:03:40 -08004768
4769 @Override
4770 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4771 int slotIndex, String callingPackage, String aid, int p2) {
4772 enforceModifyPermission();
4773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4774 if (DBG) {
4775 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4776 }
4777 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4778 callingPackage, aid, p2);
4779 }
4780
4781 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4782 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 if (TextUtils.equals(ISDR_AID, aid)) {
4786 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4788 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 if (bestComponent == null
4790 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4791 loge("The calling package is not allowed to access ISD-R.");
4792 throw new SecurityException(
4793 "The calling package is not allowed to access ISD-R.");
4794 }
Derek Tan740e1672017-06-27 14:56:27 -07004795 }
Derek Tan740e1672017-06-27 14:56:27 -07004796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004798 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4799 null /* workSource */);
4800 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 return response;
4802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004805 }
4806
4807 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004808 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4810 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004811 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4812 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004814
Jordan Liu4c733742019-02-28 12:03:40 -08004815 @Override
4816 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4817 enforceModifyPermission();
4818 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4819 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4820 channel);
4821 }
4822
4823 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 if (channel < 0) {
4827 return false;
4828 }
Jordan Liu4c733742019-02-28 12:03:40 -08004829 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4830 null /* workSource */);
4831 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 return success;
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004836 }
4837
4838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004839 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004840 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004843 if (DBG) {
4844 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4845 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4846 + p3 + " data=" + data);
4847 }
4848 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4849 command, p1, p2, p3, data);
4850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004851
Jordan Liu4c733742019-02-28 12:03:40 -08004852 @Override
4853 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4854 int command, int p1, int p2, int p3, String data) {
4855 enforceModifyPermission();
4856 if (DBG) {
4857 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4858 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4859 + p3 + " data=" + data);
4860 }
4861 return iccTransmitApduLogicalChannelWithPermission(
4862 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4863 data);
4864 }
4865
4866 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4867 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004870 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 return "";
4872 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004875 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4876 null /* workSource */);
4877 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 // Append the returned status code to the end of the response payload.
4880 String s = Integer.toHexString(
4881 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4882 if (response.payload != null) {
4883 s = IccUtils.bytesToHexString(response.payload) + s;
4884 }
4885 return s;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004888 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004889 }
Jake Hambye994d462014-02-03 13:10:13 -08004890
Evan Charltonc66da362014-05-16 14:06:40 -07004891 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004892 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4893 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4895 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004897 if (DBG) {
4898 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4899 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4900 }
4901 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4902 cla, command, p1, p2, p3, data);
4903 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004904
Jordan Liu4c733742019-02-28 12:03:40 -08004905 @Override
4906 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4907 int command, int p1, int p2, int p3, String data) {
4908 enforceModifyPermission();
4909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4910 if (DBG) {
4911 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4912 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4913 + " data=" + data);
4914 }
4915
4916 return iccTransmitApduBasicChannelWithPermission(
4917 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4918 p2, p3, data);
4919 }
4920
4921 // open APDU basic channel assuming the caller has sufficient permissions
4922 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4923 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4927 && TextUtils.equals(ISDR_AID, data)) {
4928 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4930 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 if (bestComponent == null
4932 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4933 loge("The calling package is not allowed to select ISD-R.");
4934 throw new SecurityException(
4935 "The calling package is not allowed to select ISD-R.");
4936 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004937 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004940 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 // Append the returned status code to the end of the response payload.
4945 String s = Integer.toHexString(
4946 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4947 if (response.payload != null) {
4948 s = IccUtils.bytesToHexString(response.payload) + s;
4949 }
4950 return s;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004953 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004954 }
4955
4956 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004957 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004958 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 if (DBG) {
4965 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4966 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4967 }
4968
4969 IccIoResult response =
4970 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4971 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4972 subId);
4973
4974 if (DBG) {
4975 log("Exchange SIM_IO [R]" + response);
4976 }
4977
4978 byte[] result = null;
4979 int length = 2;
4980 if (response.payload != null) {
4981 length = 2 + response.payload.length;
4982 result = new byte[length];
4983 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4984 } else {
4985 result = new byte[length];
4986 }
4987
4988 result[length - 1] = (byte) response.sw2;
4989 result[length - 2] = (byte) response.sw1;
4990 return result;
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004993 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004994 }
4995
Nathan Haroldb3014052017-01-25 15:57:32 -08004996 /**
4997 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4998 * on a particular subscription
4999 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005000 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5001 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005003 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005004 return null;
5005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 if (appType != TelephonyManager.APPTYPE_USIM
5010 && appType != TelephonyManager.APPTYPE_SIM) {
5011 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5012 return null;
5013 }
5014 Object response = sendRequest(
5015 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5016 if (response instanceof String[]) {
5017 return (String[]) response;
5018 }
yincheng zhaod698b842019-09-06 17:06:54 -07005019 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005021 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005024 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005025 }
5026
yincheng zhaod698b842019-09-06 17:06:54 -07005027 /**
5028 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5029 * subscription.
5030 *
5031 * @param subId the id of the subscription.
5032 * @param appType the uicc app type, must be USIM or SIM.
5033 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5034 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005035 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005036 * @return number of fplmns that is successfully written to the SIM.
5037 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005038 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5039 String callingFeatureId) {
5040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5041 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005042 if (DBG) logv("no permissions for setForbiddenplmns");
5043 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5044 }
5045 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5046 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5047 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5048 }
5049 if (fplmns == null) {
5050 throw new IllegalArgumentException("Fplmn List provided is null");
5051 }
5052 for (String fplmn : fplmns) {
5053 if (!CellIdentity.isValidPlmn(fplmn)) {
5054 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5055 }
5056 }
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 Object response = sendRequest(
5060 CMD_SET_FORBIDDEN_PLMNS,
5061 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5062 subId);
5063 return (int) response;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005070 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5077 if (response.payload == null) {
5078 return "";
5079 }
Evan Charltonc66da362014-05-16 14:06:40 -07005080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 // Append the returned status code to the end of the response payload.
5082 String s = Integer.toHexString(
5083 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5084 s = IccUtils.bytesToHexString(response.payload) + s;
5085 return s;
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
Evan Charltonc66da362014-05-16 14:06:40 -07005089 }
5090
Jake Hambye994d462014-02-03 13:10:13 -08005091 /**
5092 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5093 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5094 *
5095 * @param itemID the ID of the item to read
5096 * @return the NV item as a String, or null on error.
5097 */
5098 @Override
5099 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005107 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5109 return value;
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
Jake Hambye994d462014-02-03 13:10:13 -08005113 }
5114
5115 /**
5116 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5117 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5118 *
5119 * @param itemID the ID of the item to read
5120 * @param itemValue the value to write, as a String
5121 * @return true on success; false on any failure
5122 */
5123 @Override
5124 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005125 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5127 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5132 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005133 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5135 return success;
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Jake Hambye994d462014-02-03 13:10:13 -08005139 }
5140
5141 /**
5142 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5143 * Used for device configuration by some CDMA operators.
5144 *
5145 * @param preferredRoamingList byte array containing the new PRL
5146 * @return true on success; false on any failure
5147 */
5148 @Override
5149 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5151 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5156 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5157 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5158 return success;
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Jake Hambye994d462014-02-03 13:10:13 -08005162 }
5163
5164 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005165 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005166 * Used for device configuration by some CDMA operators.
5167 *
chen xu6dac5ab2018-10-26 17:39:23 -07005168 * @param slotIndex - device slot.
5169 *
Jake Hambye994d462014-02-03 13:10:13 -08005170 * @return true on success; false on any failure
5171 */
5172 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005173 public boolean resetModemConfig(int slotIndex) {
5174 Phone phone = PhoneFactory.getPhone(slotIndex);
5175 if (phone != null) {
5176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5177 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178
chen xu6dac5ab2018-10-26 17:39:23 -07005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5182 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5183 return success;
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
chen xu6dac5ab2018-10-26 17:39:23 -07005188 return false;
5189 }
5190
5191 /**
5192 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5193 *
5194 * @param slotIndex - device slot.
5195 *
5196 * @return true on success; false on any failure
5197 */
5198 @Override
5199 public boolean rebootModem(int slotIndex) {
5200 Phone phone = PhoneFactory.getPhone(slotIndex);
5201 if (phone != null) {
5202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5203 mApp, phone.getSubId(), "rebootModem");
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5208 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5209 return success;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
5213 }
5214 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005215 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005216
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005217 public String[] getPcscfAddress(String apnType, String callingPackage,
5218 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5221 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005222 return new String[0];
5223 }
5224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Wink Saville36469e72014-06-11 15:17:00 -07005231 }
5232
Brad Ebinger51f743a2017-01-23 13:50:20 -08005233 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005234 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5235 * {@link #disableIms(int)}.
5236 * @param slotIndex device slot.
5237 */
5238 public void resetIms(int slotIndex) {
5239 enforceModifyPermission();
5240
5241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 if (mImsResolver == null) {
5244 // may happen if the does not support IMS.
5245 return;
5246 }
5247 mImsResolver.disableIms(slotIndex);
5248 mImsResolver.enableIms(slotIndex);
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005255 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5256 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005257 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005258 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005259 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005263 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005264 // may happen if the device does not support IMS.
5265 return;
5266 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005267 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005271 }
5272
5273 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005274 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5275 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005276 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005277 public void disableIms(int slotId) {
5278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005282 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005283 // may happen if the device does not support IMS.
5284 return;
5285 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005286 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005290 }
5291
5292 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005293 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5294 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005295 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005296 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005297 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005298 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005302 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5304 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005305 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005306 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005310 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005311 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005312 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5313 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005314 @Override
5315 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005316 enforceModifyPermission();
5317
5318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005321 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
5325 }
5326
5327 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005328 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005329 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005330 */
5331 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333
5334 final long identity = Binder.clearCallingIdentity();
5335 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005336 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005337 // may happen if the device does not support IMS.
5338 return null;
5339 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005340 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005344 }
5345
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005346 /**
5347 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005348 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005349 */
5350 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005355 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005356 // may happen if the device does not support IMS.
5357 return null;
5358 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005359 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005363 }
5364
Brad Ebinger884c07b2018-02-15 16:17:40 -08005365 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005366 * Sets the ImsService Package Name that Telephony will bind to.
5367 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005368 * @param slotIndex the slot ID that the ImsService should bind for.
5369 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005370 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005371 * @param featureTypes An integer array of feature types associated with a packageName.
5372 * @param packageName The name of the package that the current configuration will be replaced
5373 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005374 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005375 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005376 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5377 int[] featureTypes, String packageName) {
5378 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5381 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005382 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005386 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005387 // may happen if the device does not support IMS.
5388 return false;
5389 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005390 Map<Integer, String> featureConfig = new HashMap<>();
5391 for (int featureType : featureTypes) {
5392 featureConfig.put(featureType, packageName);
5393 }
5394 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5395 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005399 }
5400
5401 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005402 * Clears any carrier ImsService overrides for the slot index specified that were previously
5403 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5404 *
5405 * This should only be used for testing.
5406 *
5407 * @param slotIndex the slot ID that the ImsService should bind for.
5408 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5409 */
5410 @Override
5411 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5412 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5414 "clearCarrierImsServiceOverride");
5415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5416 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5417 "clearCarrierImsServiceOverride");
5418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 if (mImsResolver == null) {
5422 // may happen if the device does not support IMS.
5423 return false;
5424 }
5425 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
5429 }
5430
5431 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005432 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005433 *
5434 * @param slotId The slot that the ImsService is associated with.
5435 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5436 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005437 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005438 * @return the package name of the ImsService configuration.
5439 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5441 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005442 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005443 TelephonyPermissions
5444 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5445 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5446 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005450 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005451 // may happen if the device does not support IMS.
5452 return "";
5453 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005454 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5456 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005460 }
5461
Brad Ebinger77b832e2019-10-17 17:03:22 -07005462 /**
5463 * Get the MmTelFeature state associated with the requested subscription id.
5464 * @param subId The subscription that the MmTelFeature is associated with.
5465 * @param callback A callback with an integer containing the
5466 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5467 */
5468 @Override
5469 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5470 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5471 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5472 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5473 "IMS not available on device.");
5474 }
5475 final long token = Binder.clearCallingIdentity();
5476 try {
5477 int slotId = getSlotIndex(subId);
5478 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5479 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5480 + subId + "'");
5481 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5482 }
5483 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5484 try {
5485 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5486 } catch (RemoteException e) {
5487 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5488 + "Ignore");
5489 }
5490 });
5491 } finally {
5492 Binder.restoreCallingIdentity(token);
5493 }
5494 }
5495
Wink Saville36469e72014-06-11 15:17:00 -07005496 public void setImsRegistrationState(boolean registered) {
5497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005501 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Wink Saville36469e72014-06-11 15:17:00 -07005505 }
5506
5507 /**
Stuart Scott54788802015-03-30 13:18:01 -07005508 * Set the network selection mode to automatic.
5509 *
5510 */
5511 @Override
5512 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
shilufc958392020-01-20 11:36:01 -08005518 if (!isActiveSubscription(subId)) {
5519 return;
5520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5522 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Stuart Scott54788802015-03-30 13:18:01 -07005526 }
5527
Jack Yud10cdd42020-09-28 20:28:01 -07005528 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005529 * Ask the radio to connect to the input network and change selection mode to manual.
5530 *
5531 * @param subId the id of the subscription.
5532 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5533 * the operator to attach to.
5534 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5535 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5536 * normal network selection next time.
5537 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005538 */
5539 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005540 public boolean setNetworkSelectionModeManual(
5541 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5543 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005544
5545 if (!isActiveSubscription(subId)) {
5546 return false;
5547 }
5548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 final long identity = Binder.clearCallingIdentity();
5550 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005551 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005553 if (DBG) {
5554 log("setNetworkSelectionModeManual: subId: " + subId
5555 + " operator: " + operatorInfo);
5556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005561 }
shilu84f6e8b2019-12-19 13:58:01 -08005562 /**
5563 * Get the manual network selection
5564 *
5565 * @param subId the id of the subscription.
5566 *
5567 * @return the previously saved user selected PLMN
5568 */
5569 @Override
5570 public String getManualNetworkSelectionPlmn(int subId) {
5571 TelephonyPermissions
5572 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5573 mApp, subId, "getManualNetworkSelectionPlmn");
5574
5575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 if (!isActiveSubscription(subId)) {
5578 return "";
5579 }
5580
5581 final Phone phone = getPhone(subId);
5582 if (phone == null) {
5583 return "";
5584 }
5585 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5586 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5587 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
5591 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005592
5593 /**
5594 * Scans for available networks.
5595 */
5596 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005597 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5598 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5600 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005601 LocationAccessPolicy.LocationPermissionResult locationResult =
5602 LocationAccessPolicy.checkLocationPermission(mApp,
5603 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5604 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005605 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005606 .setCallingPid(Binder.getCallingPid())
5607 .setCallingUid(Binder.getCallingUid())
5608 .setMethod("getCellNetworkScanResults")
5609 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5610 .build());
5611 switch (locationResult) {
5612 case DENIED_HARD:
5613 throw new SecurityException("Not allowed to access scan results -- location");
5614 case DENIED_SOFT:
5615 return null;
5616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617
Pengquan Menga1bb6272018-09-06 09:59:22 -07005618 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 try {
5620 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005621 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005626 }
5627
5628 /**
sqian80370722020-01-29 15:02:51 -08005629 * Get the call forwarding info, given the call forwarding reason.
5630 */
5631 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005632 public void getCallForwarding(int subId, int callForwardingReason,
5633 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005634 enforceReadPrivilegedPermission("getCallForwarding");
5635 long identity = Binder.clearCallingIdentity();
5636 try {
5637 if (DBG) {
5638 log("getCallForwarding: subId " + subId
5639 + " callForwardingReason" + callForwardingReason);
5640 }
Hall Liua1acea22020-09-18 19:04:59 -07005641
5642 Phone phone = getPhone(subId);
5643 if (phone == null) {
5644 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005645 callback.onError(
5646 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005647 } catch (RemoteException e) {
5648 // ignore
5649 }
5650 return;
5651 }
5652
5653 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5654 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5655 @Override
5656 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5657 try {
5658 callback.onCallForwardingInfoAvailable(info);
5659 } catch (RemoteException e) {
5660 // ignore
5661 }
5662 }
5663
5664 @Override
5665 public void onError(int error) {
5666 try {
5667 callback.onError(error);
5668 } catch (RemoteException e) {
5669 // ignore
5670 }
5671 }
5672 });
5673 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678
5679 /**
5680 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5681 * reason, the number to forward, and the timeout before the forwarding is attempted.
5682 */
5683 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005684 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5685 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005686 enforceModifyPermission();
5687 long identity = Binder.clearCallingIdentity();
5688 try {
5689 if (DBG) {
5690 log("setCallForwarding: subId " + subId
5691 + " callForwardingInfo" + callForwardingInfo);
5692 }
Hall Liua1acea22020-09-18 19:04:59 -07005693
5694 Phone phone = getPhone(subId);
5695 if (phone == null) {
5696 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005697 callback.accept(
5698 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005699 } catch (RemoteException e) {
5700 // ignore
5701 }
5702 return;
5703 }
5704
5705 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5706 FunctionalUtils.ignoreRemoteException(callback::accept));
5707
5708 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
5714 /**
Hall Liua1acea22020-09-18 19:04:59 -07005715 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005716 */
5717 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005718 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005719 enforceReadPrivilegedPermission("getCallForwarding");
5720 long identity = Binder.clearCallingIdentity();
5721 try {
Hall Liua1acea22020-09-18 19:04:59 -07005722
5723 Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 try {
5726 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5727 } catch (RemoteException e) {
5728 // ignore
5729 }
5730 return;
5731 }
5732
5733 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5734
sqian80370722020-01-29 15:02:51 -08005735 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005736 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
Hall Liua1acea22020-09-18 19:04:59 -07005743 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005744 */
5745 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005746 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005747 enforceModifyPermission();
5748 long identity = Binder.clearCallingIdentity();
5749 try {
Hall Liua1acea22020-09-18 19:04:59 -07005750 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5751
5752 Phone phone = getPhone(subId);
5753 if (phone == null) {
5754 try {
5755 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5756 } catch (RemoteException e) {
5757 // ignore
5758 }
5759 return;
5760 }
5761
5762 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5763 FunctionalUtils.ignoreRemoteException(callback::accept));
5764
5765 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
5771 /**
yinxub1bed742017-04-17 11:45:04 -07005772 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005773 *
yinxub1bed742017-04-17 11:45:04 -07005774 * @param subId id of the subscription
5775 * @param request contains the radio access networks with bands/channels to scan
5776 * @param messenger callback messenger for scan results or errors
5777 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005778 * @return the id of the requested scan which can be used to stop the scan.
5779 */
5780 @Override
5781 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005782 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5784 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005785 LocationAccessPolicy.LocationPermissionResult locationResult =
5786 LocationAccessPolicy.checkLocationPermission(mApp,
5787 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5788 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005789 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005790 .setCallingPid(Binder.getCallingPid())
5791 .setCallingUid(Binder.getCallingUid())
5792 .setMethod("requestNetworkScan")
5793 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5794 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005795 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005796 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5797 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005798 if (e != null) {
5799 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5800 throw e;
5801 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005802 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005803 return TelephonyScanManager.INVALID_SCAN_ID;
5804 }
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 }
Hall Liu912dfd32019-04-25 14:02:26 -07005807 int callingUid = Binder.getCallingUid();
5808 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 return mNetworkScanRequestTracker.startNetworkScan(
5812 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005813 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
yinxu504e1392017-04-12 16:03:22 -07005817 }
5818
Hall Liub2ac8ef2019-02-28 15:56:23 -08005819 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005820 NetworkScanRequest request, int subId, String callingPackage) {
5821 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005822 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5823 boolean hasNetworkScanPermission =
5824 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5825 == PERMISSION_GRANTED;
5826
5827 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5828 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5829 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005830 }
5831
5832 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5833 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005834 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5835 return new SecurityException("Specific channels must not be"
5836 + " scanned without location access.");
5837 }
5838 }
5839 }
5840
Hall Liub2ac8ef2019-02-28 15:56:23 -08005841 return null;
5842 }
5843
yinxu504e1392017-04-12 16:03:22 -07005844 /**
5845 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005846 *
5847 * @param subId id of the subscription
5848 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005849 */
5850 @Override
5851 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5853 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
Hall Liu912dfd32019-04-25 14:02:26 -07005855 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005858 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
yinxu504e1392017-04-12 16:03:22 -07005862 }
5863
5864 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005865 * Get the calculated preferred network type.
5866 * Used for debugging incorrect network type.
5867 *
5868 * @return the preferred network type, defined in RILConstants.java.
5869 */
5870 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005871 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005872 final Phone defaultPhone = getDefaultPhone();
5873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005874 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005875 return RILConstants.PREFERRED_NETWORK_MODE;
5876 }
5877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005881 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Junda Liu84d15a22014-07-02 11:21:04 -07005885 }
5886
5887 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005888 * Get the preferred network type.
5889 * Used for device configuration by some CDMA operators.
5890 *
5891 * @return the preferred network type, defined in RILConstants.java.
5892 */
5893 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005894 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005895 TelephonyPermissions
5896 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5897 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898
5899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 if (DBG) log("getPreferredNetworkType");
5902 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5903 int networkType = (result != null ? result[0] : -1);
5904 if (DBG) log("getPreferredNetworkType: " + networkType);
5905 return networkType;
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005909 }
5910
5911 /**
5912 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005913 *
5914 * @param networkType the preferred network type, defined in RILConstants.java.
5915 * @return true on success; false on any failure.
5916 */
5917 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005918 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5920 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
calvinpan089c2a62020-03-12 14:17:55 +08005924 Boolean success = (Boolean) sendRequest(
5925 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005926
5927 if (success) {
5928 Settings.Global.putInt(mApp.getContentResolver(),
5929 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5930 }
calvinpan089c2a62020-03-12 14:17:55 +08005931 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5932 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 } finally {
5934 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005935 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005936 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005937
5938 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005939 * Get the allowed network types that store in the telephony provider.
5940 *
5941 * @param subId the id of the subscription.
5942 * @return allowedNetworkTypes the allowed network types.
5943 */
5944 @Override
5945 public long getAllowedNetworkTypes(int subId) {
5946 TelephonyPermissions
5947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5948 mApp, subId, "getAllowedNetworkTypes");
5949
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 return SubscriptionManager.getLongSubscriptionProperty(
5953 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
5957 }
5958
5959 /**
5960 * Set the allowed network types.
5961 *
5962 * @param subId the id of the subscription.
5963 * @param allowedNetworkTypes the allowed network types.
5964 * @return true on success; false on any failure.
5965 */
5966 @Override
5967 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5969 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005970
calvinpan089c2a62020-03-12 14:17:55 +08005971 SubscriptionManager.setSubscriptionProperty(subId,
5972 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5973 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005974
calvinpan089c2a62020-03-12 14:17:55 +08005975 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5976 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5977 RILConstants.PREFERRED_NETWORK_MODE);
5978 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005979 }
5980
5981 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005982 * Get the allowed network types for certain reason.
5983 *
5984 * @param subId the id of the subscription.
5985 * @param reason the reason the allowed network type change is taking place
5986 * @return the allowed network types.
5987 */
5988 @Override
5989 public long getAllowedNetworkTypesForReason(int subId,
5990 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5991 TelephonyPermissions
5992 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5993 mApp, subId, "getAllowedNetworkTypesForReason");
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
5996 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
6000 }
6001
6002 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006003 * Enable/Disable E-UTRA-NR Dual Connectivity
6004 * @param subId subscription id of the sim card
6005 * @param nrDualConnectivityState expected NR dual connectivity state
6006 * This can be passed following states
6007 * <ol>
6008 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6009 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6010 * <li>Disable NR dual connectivity and force secondary cell to be released
6011 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6012 * </ol>
6013 * @return operation result.
6014 */
6015 @Override
6016 public int setNrDualConnectivityState(int subId,
6017 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6019 mApp, subId, "enableNRDualConnectivity");
6020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6024 nrDualConnectivityState, subId,
6025 workSource);
6026 if (DBG) log("enableNRDualConnectivity result: " + result);
6027 return result;
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
6033 /**
6034 * Is E-UTRA-NR Dual Connectivity enabled
6035 * @return true if dual connectivity is enabled else false
6036 */
6037 @Override
6038 public boolean isNrDualConnectivityEnabled(int subId) {
6039 TelephonyPermissions
6040 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6041 mApp, subId, "isNRDualConnectivityEnabled");
6042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6043 final long identity = Binder.clearCallingIdentity();
6044 try {
6045 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6046 null, subId, workSource);
6047 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6048 return isEnabled;
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
6053
6054 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006055 * get carrier bandwidth per primary and secondary carrier
6056 * @param subId subscription id of the sim card
6057 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6058 */
6059 @Override
6060 public CarrierBandwidth getCarrierBandwidth(int subId) {
6061 TelephonyPermissions
6062 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6063 mApp, subId, "isNRDualConnectivityEnabled");
6064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 CarrierBandwidth carrierBandwidth =
6068 getPhoneFromSubId(subId).getCarrierBandwidth();
6069 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6070 return carrierBandwidth;
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
6074 }
6075
6076 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006077 * Get the effective allowed network types on the device.
6078 * This API will return an intersection of allowed network types for all reasons,
6079 * including the configuration done through setAllowedNetworkTypes
6080 *
6081 * @param subId the id of the subscription.
6082 * @return the allowed network types
6083 */
6084 @Override
6085 public long getEffectiveAllowedNetworkTypes(int subId) {
6086 TelephonyPermissions
6087 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6088 mApp, subId, "getEffectiveAllowedNetworkTypes");
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
6095 }
6096
6097 /**
6098 * Set the allowed network types of the device and
6099 * provide the reason triggering the allowed network change.
6100 *
6101 * @param subId the id of the subscription.
6102 * @param reason the reason the allowed network type change is taking place
6103 * @param allowedNetworkTypes the allowed network types.
6104 * @return true on success; false on any failure.
6105 */
6106 @Override
6107 public boolean setAllowedNetworkTypesForReason(int subId,
6108 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "setAllowedNetworkTypesForReason");
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6114 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6115 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6116 RILConstants.PREFERRED_NETWORK_MODE);
6117 return setPreferredNetworkType(subId, preferredNetworkMode);
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
6121 }
6122
6123 /**
Miaoa84611c2019-03-15 09:21:10 +08006124 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006125 *
Miaoa84611c2019-03-15 09:21:10 +08006126 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006127 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006128 * @hide
6129 */
6130 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006131 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006134 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 try {
Miaoa84611c2019-03-15 09:21:10 +08006136 if (phone != null) {
6137 return phone.hasMatchedTetherApnSetting();
6138 } else {
6139 return false;
6140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006143 }
Junda Liu475951f2014-11-07 16:45:03 -08006144 }
6145
6146 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006147 * Enable or disable always reporting signal strength changes from radio.
6148 *
6149 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6150 */
6151 @Override
6152 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6153 enforceModifyPermission();
6154 enforceSystemCaller();
6155
6156 final long identity = Binder.clearCallingIdentity();
6157 final Phone phone = getPhone(subId);
6158 try {
6159 if (phone != null) {
6160 if (DBG) {
6161 log("setAlwaysReportSignalStrength: subId=" + subId
6162 + " isEnable=" + isEnable);
6163 }
6164 phone.setAlwaysReportSignalStrength(isEnable);
6165 } else {
6166 loge("setAlwaysReportSignalStrength: no phone found for subId="
6167 + subId);
6168 }
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006175 * Get the user enabled state of Mobile Data.
6176 *
6177 * TODO: remove and use isUserDataEnabled.
6178 * This can't be removed now because some vendor codes
6179 * calls through ITelephony directly while they should
6180 * use TelephonyManager.
6181 *
6182 * @return true on enabled
6183 */
6184 @Override
6185 public boolean getDataEnabled(int subId) {
6186 return isUserDataEnabled(subId);
6187 }
6188
6189 /**
6190 * Get whether mobile data is enabled per user setting.
6191 *
6192 * There are other factors deciding whether mobile data is actually enabled, but they are
6193 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006194 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006195 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006196 *
6197 * @return {@code true} if data is enabled else {@code false}
6198 */
6199 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006200 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006201 try {
6202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6203 null);
6204 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6206 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 int phoneId = mSubscriptionController.getPhoneId(subId);
6212 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6213 Phone phone = PhoneFactory.getPhone(phoneId);
6214 if (phone != null) {
6215 boolean retVal = phone.isUserDataEnabled();
6216 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6217 return retVal;
6218 } else {
6219 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6220 return false;
6221 }
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006224 }
6225 }
6226
6227 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006228 * Checks if the device is capable of mobile data by considering whether whether the
6229 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6230 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006231 *
Shuo Qian985d1232020-01-08 14:30:06 -08006232 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006233 */
6234 @Override
6235 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006236 try {
6237 try {
6238 mApp.enforceCallingOrSelfPermission(
6239 android.Manifest.permission.ACCESS_NETWORK_STATE,
6240 null);
6241 } catch (Exception e) {
6242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6243 "isDataEnabled");
6244 }
6245 } catch (Exception e) {
6246 enforceReadPrivilegedPermission("isDataEnabled");
6247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 int phoneId = mSubscriptionController.getPhoneId(subId);
6252 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6253 Phone phone = PhoneFactory.getPhone(phoneId);
6254 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006255 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6257 return retVal;
6258 } else {
6259 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6260 return false;
6261 }
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006264 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006265 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006266
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006267 /**
6268 * Check if data is enabled for a specific reason
6269 * @param subId Subscription index
6270 * @param reason the reason the data enable change is taking place
6271 * @return {@code true} if the overall data is enabled; {@code false} if not.
6272 */
6273 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006274 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006275 @TelephonyManager.DataEnabledReason int reason) {
6276 try {
6277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6278 null);
6279 } catch (Exception e) {
6280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006281 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006282 }
6283
6284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 int phoneId = mSubscriptionController.getPhoneId(subId);
6288 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006289 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006290 + " reason=" + reason);
6291 }
6292 Phone phone = PhoneFactory.getPhone(phoneId);
6293 if (phone != null) {
6294 boolean retVal;
6295 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6296 retVal = phone.isUserDataEnabled();
6297 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006298 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006299 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006300 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006301 return retVal;
6302 } else {
6303 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006304 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006305 + subId + " retVal=false");
6306 }
6307 return false;
6308 }
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
6312 }
6313
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006314 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006315 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006316 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6317 // Skip the check if it's one of these special uids
6318 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6319 }
6320
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006321 //load access rules from carrier configs, and check those as well: b/139133814
6322 SubscriptionController subController = SubscriptionController.getInstance();
6323 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6324 || subController == null) return privilegeFromSim;
6325
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006326 PackageManager pkgMgr = phone.getContext().getPackageManager();
6327 String[] packages = pkgMgr.getPackagesForUid(uid);
6328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006331 int subId = phone.getSubId();
6332 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6333 // A test override is in place for the privileges for this subId, so don't try to
6334 // read the subscription privileges.
6335 return privilegeFromSim;
6336 }
6337 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006338 SubscriptionManager subManager = (SubscriptionManager)
6339 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6340 for (String pkg : packages) {
6341 if (subManager.canManageSubscription(subInfo, pkg)) {
6342 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6343 }
6344 }
6345 return privilegeFromSim;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
6349 }
6350
6351 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6352 String pkgName) {
6353 //load access rules from carrier configs, and check those as well: b/139133814
6354 SubscriptionController subController = SubscriptionController.getInstance();
6355 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6356 || subController == null) return privilegeFromSim;
6357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006360 int subId = phone.getSubId();
6361 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6362 // A test override is in place for the privileges for this subId, so don't try to
6363 // read the subscription privileges.
6364 return privilegeFromSim;
6365 }
6366 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006367 SubscriptionManager subManager = (SubscriptionManager)
6368 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6369 return subManager.canManageSubscription(subInfo, pkgName)
6370 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006376 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006377 public int getCarrierPrivilegeStatus(int subId) {
6378 final Phone phone = getPhone(subId);
6379 if (phone == null) {
6380 loge("getCarrierPrivilegeStatus: Invalid subId");
6381 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6382 }
6383 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006384 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006385 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006386 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6387 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006388
6389 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6390 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006391 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006392 }
Junda Liu29340342014-07-10 15:23:27 -07006393
6394 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006395 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006396 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 final Phone phone = getPhone(subId);
6398 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006399 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006400 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6401 }
6402 UiccProfile profile =
6403 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6404 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006405 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006406 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6407 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006408 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006409 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006410 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 }
6412
6413 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006414 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6415 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006416 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006417 }
6418
6419 int phoneId = SubscriptionManager.getPhoneId(subId);
6420 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006421 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006422 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006423 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6424 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006425 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6426 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6427 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006428 }
6429
6430 @Override
6431 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006432 if (TextUtils.isEmpty(pkgName))
6433 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006434 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6435 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6436 UiccCard card = UiccController.getInstance().getUiccCard(i);
6437 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006438 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006439 continue;
6440 }
6441
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006442 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6443 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6444 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006445 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6446 break;
6447 }
6448 }
6449
6450 return result;
Junda Liu29340342014-07-10 15:23:27 -07006451 }
Derek Tan89e89d42014-07-08 17:00:10 -07006452
6453 @Override
Junda Liue64de782015-04-16 17:19:16 -07006454 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6455 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6456 loge("phoneId " + phoneId + " is not valid.");
6457 return null;
6458 }
6459 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006460 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006461 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006462 return null ;
6463 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006464 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006465 }
6466
Amith Yamasani6e118872016-02-19 12:53:51 -08006467 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006468 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006469 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006470 List<String> privilegedPackages = new ArrayList<>();
6471 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006472 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6473 // has UICC in that slot.
6474 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006475 if (card.hasCarrierPrivilegeRules()) {
6476 if (packages == null) {
6477 // Only check packages in user 0 for now
6478 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006479 PackageManager.MATCH_DISABLED_COMPONENTS
6480 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006481 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006482 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006483 }
6484 for (int p = packages.size() - 1; p >= 0; p--) {
6485 PackageInfo pkgInfo = packages.get(p);
6486 if (pkgInfo != null && pkgInfo.packageName != null
6487 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006488 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006489 privilegedPackages.add(pkgInfo.packageName);
6490 }
6491 }
6492 }
6493 }
6494 return privilegedPackages;
6495 }
6496
chen xuf7e9fe82019-05-09 19:31:02 -07006497 @Override
6498 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006499 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6500
6501 final long identity = Binder.clearCallingIdentity();
6502
chen xuf7e9fe82019-05-09 19:31:02 -07006503 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006504 try {
6505 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6506 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6507 }
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006510 }
6511 return privilegedPackages;
6512 }
6513
Wink Savilleb564aae2014-10-23 10:18:09 -07006514 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006515 final Phone phone = getPhone(subId);
6516 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006517 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006518 return null;
6519 }
6520 String iccId = card.getIccId();
6521 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006522 return null;
6523 }
6524 return iccId;
6525 }
6526
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006527 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006528 public void setCallComposerStatus(int subId, int status) {
6529 enforceModifyPermission();
6530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 Phone phone = getPhone(subId);
6534 if (phone != null) {
6535 Phone defaultPhone = phone.getImsPhone();
6536 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6537 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6538 imsPhone.setCallComposerStatus(status);
6539 }
6540 }
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 @Override
6547 public int getCallComposerStatus(int subId) {
6548 enforceReadPrivilegedPermission("getCallComposerStatus");
6549
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 Phone phone = getPhone(subId);
6553 if (phone != null) {
6554 Phone defaultPhone = phone.getImsPhone();
6555 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6556 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6557 return imsPhone.getCallComposerStatus();
6558 }
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6564 }
6565
6566 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006567 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6568 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006569 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006570 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 final String iccId = getIccId(subId);
6575 final Phone phone = getPhone(subId);
6576 if (phone == null) {
6577 return false;
6578 }
6579 final String subscriberId = phone.getSubscriberId();
6580
6581 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006582 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 + subscriberId + " to " + number);
6584 }
6585
6586 if (TextUtils.isEmpty(iccId)) {
6587 return false;
6588 }
6589
6590 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6591
6592 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6593 if (alphaTag == null) {
6594 editor.remove(alphaTagPrefKey);
6595 } else {
6596 editor.putString(alphaTagPrefKey, alphaTag);
6597 }
6598
6599 // Record both the line number and IMSI for this ICCID, since we need to
6600 // track all merged IMSIs based on line number
6601 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6602 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6603 if (number == null) {
6604 editor.remove(numberPrefKey);
6605 editor.remove(subscriberPrefKey);
6606 } else {
6607 editor.putString(numberPrefKey, number);
6608 editor.putString(subscriberPrefKey, subscriberId);
6609 }
6610
6611 editor.commit();
6612 return true;
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006615 }
Derek Tan7226c842014-07-02 17:42:23 -07006616 }
6617
6618 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006619 public String getLine1NumberForDisplay(int subId, String callingPackage,
6620 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006621 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006623 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006624 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006625 return null;
6626 }
Derek Tan97ebb422014-09-05 16:55:38 -07006627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 String iccId = getIccId(subId);
6631 if (iccId != null) {
6632 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6633 if (DBG_MERGE) {
6634 log("getLine1NumberForDisplay returning "
6635 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6636 }
6637 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6640 return null;
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006643 }
Derek Tan7226c842014-07-02 17:42:23 -07006644 }
6645
6646 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006647 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006650 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006651 return null;
6652 }
Derek Tan97ebb422014-09-05 16:55:38 -07006653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 String iccId = getIccId(subId);
6657 if (iccId != null) {
6658 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6659 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6660 }
6661 return null;
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006664 }
Derek Tan7226c842014-07-02 17:42:23 -07006665 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006666
6667 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006668 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6669 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006670 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6671 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006673 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006674 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006675 return null;
6676 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006677
Jordan Liub49b04b2019-05-06 14:45:15 -07006678 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6679 // the process, where TelephonyManager was instantiated.
6680 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006681 final long identity = Binder.clearCallingIdentity();
6682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006683 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 final TelephonyManager tele = TelephonyManager.from(context);
6685 final SubscriptionManager sub = SubscriptionManager.from(context);
6686
6687 // Figure out what subscribers are currently active
6688 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689
Jordan Liub49b04b2019-05-06 14:45:15 -07006690 // Only consider subs which match the current subId
6691 // This logic can be simplified. See b/131189269 for progress.
6692 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006693 activeSubscriberIds.add(tele.getSubscriberId(subId));
6694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695
6696 // First pass, find a number override for an active subscriber
6697 String mergeNumber = null;
6698 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6699 for (String key : prefs.keySet()) {
6700 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6701 final String subscriberId = (String) prefs.get(key);
6702 if (activeSubscriberIds.contains(subscriberId)) {
6703 final String iccId = key.substring(
6704 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6705 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6706 mergeNumber = (String) prefs.get(numberKey);
6707 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006708 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709 + " for active subscriber " + subscriberId);
6710 }
6711 if (!TextUtils.isEmpty(mergeNumber)) {
6712 break;
6713 }
6714 }
6715 }
6716 }
6717
6718 // Shortcut when no active merged subscribers
6719 if (TextUtils.isEmpty(mergeNumber)) {
6720 return null;
6721 }
6722
6723 // Second pass, find all subscribers under that line override
6724 final ArraySet<String> result = new ArraySet<>();
6725 for (String key : prefs.keySet()) {
6726 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6727 final String number = (String) prefs.get(key);
6728 if (mergeNumber.equals(number)) {
6729 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6730 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6731 final String subscriberId = (String) prefs.get(subscriberKey);
6732 if (!TextUtils.isEmpty(subscriberId)) {
6733 result.add(subscriberId);
6734 }
6735 }
6736 }
6737 }
6738
6739 final String[] resultArray = result.toArray(new String[result.size()]);
6740 Arrays.sort(resultArray);
6741 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006742 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6744 }
6745 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006746 } finally {
6747 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006748 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006749 }
6750
6751 @Override
zoey chen38003472019-12-13 17:16:31 +08006752 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6753 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 final TelephonyManager telephonyManager = mApp.getSystemService(
6758 TelephonyManager.class);
6759 String subscriberId = telephonyManager.getSubscriberId(subId);
6760 if (subscriberId == null) {
6761 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006762 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006763 + subId);
6764 }
6765 return null;
6766 }
6767
6768 final SubscriptionInfo info = SubscriptionController.getInstance()
6769 .getSubscriptionInfo(subId);
6770 final ParcelUuid groupUuid = info.getGroupUuid();
6771 // If it doesn't belong to any group, return just subscriberId of itself.
6772 if (groupUuid == null) {
6773 return new String[]{subscriberId};
6774 }
6775
6776 // Get all subscriberIds from the group.
6777 final List<String> mergedSubscriberIds = new ArrayList<>();
6778 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006779 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006780 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006781 for (SubscriptionInfo subInfo : groupInfos) {
6782 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6783 if (subscriberId != null) {
6784 mergedSubscriberIds.add(subscriberId);
6785 }
6786 }
6787
6788 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791
6792 }
6793 }
6794
6795 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006796 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006797 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006798 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799
6800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 final Phone phone = getPhone(subId);
6803 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006807 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006808
6809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006810 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006811 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6812 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006813 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6814 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 final Phone phone = getPhone(subId);
6819 if (phone == null) {
6820 return false;
6821 }
6822 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6823 cdmaNonRoamingList);
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006826 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006827 }
6828
6829 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006830 @Deprecated
6831 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6832 enforceModifyPermission();
6833
6834 int returnValue = 0;
6835 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006836 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006837 if(result.exception == null) {
6838 if (result.result != null) {
6839 byte[] responseData = (byte[])(result.result);
6840 if(responseData.length > oemResp.length) {
6841 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6842 responseData.length + "bytes. Buffer Size is " +
6843 oemResp.length + "bytes.");
6844 }
6845 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6846 returnValue = responseData.length;
6847 }
6848 } else {
6849 CommandException ex = (CommandException) result.exception;
6850 returnValue = ex.getCommandError().ordinal();
6851 if(returnValue > 0) returnValue *= -1;
6852 }
6853 } catch (RuntimeException e) {
6854 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6855 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6856 if(returnValue > 0) returnValue *= -1;
6857 }
6858
6859 return returnValue;
6860 }
6861
6862 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006863 public void setRadioCapability(RadioAccessFamily[] rafs) {
6864 try {
6865 ProxyController.getInstance().setRadioCapability(rafs);
6866 } catch (RuntimeException e) {
6867 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6868 }
6869 }
6870
6871 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006872 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006873 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006874 try {
6875 TelephonyPermissions
6876 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6877 mApp, phone.getSubId(), "getRadioAccessFamily");
6878 } catch (SecurityException e) {
6879 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6880 throw e;
6881 }
chen xub97461a2018-10-26 14:17:57 -07006882 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006883 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006884 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 final long identity = Binder.clearCallingIdentity();
6887 try {
chen xub97461a2018-10-26 14:17:57 -07006888 TelephonyPermissions
6889 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6890 mApp, phone.getSubId(), "getRadioAccessFamily");
6891 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
chen xub97461a2018-10-26 14:17:57 -07006895 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006896 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006897
6898 @Override
6899 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006900 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006901 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902
6903 final long identity = Binder.clearCallingIdentity();
6904 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006905 ImsManager.getInstance(defaultPhone.getContext(),
6906 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 } finally {
6908 Binder.restoreCallingIdentity(identity);
6909 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006910 }
6911
6912 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006913 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006914 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6916 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006917 return false;
6918 }
Svet Ganovb320e182015-04-16 12:30:10 -07006919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 // Check the user preference and the system-level IMS setting. Even if the user has
6923 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6924 // In the long run, we may instead need to check if there exists a connection service
6925 // which can support video calling.
6926 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006927 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 return imsManager.isVtEnabledByPlatform()
6929 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6930 && imsManager.isVtEnabledByUser();
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006934 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006935
Andrew Leea1239f22015-03-02 17:44:07 -08006936 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006937 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6938 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006940 mApp, subId, callingPackage, callingFeatureId,
6941 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 return false;
6943 }
6944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 CarrierConfigManager configManager =
6948 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006949 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
Andrew Leea1239f22015-03-02 17:44:07 -08006954 }
6955
6956 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006957 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006959 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 return false;
6961 }
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 CarrierConfigManager configManager =
6966 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006967 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
Andrew Leea1239f22015-03-02 17:44:07 -08006972 }
6973
Andrew Lee9431b832015-03-09 18:46:45 -07006974 @Override
6975 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006976 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006977 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006978 }
6979
6980 @Override
6981 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final long identity = Binder.clearCallingIdentity();
6983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006984 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
Andrew Lee9431b832015-03-09 18:46:45 -07006988 }
6989
Hall Liuf6668912018-10-31 17:05:23 -07006990 /**
6991 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6992 * support for the feature and device firmware support.
6993 *
6994 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6995 */
6996 @Override
6997 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006999 final Phone phone = getPhone(subscriptionId);
7000 if (phone == null) {
7001 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7002 return false;
7003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007005 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7007 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007008 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 return isCarrierSupported && isDeviceSupported;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
Hall Liu98187582018-01-22 19:15:32 -08007013 }
7014
Hall Liuf6668912018-10-31 17:05:23 -07007015 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007016 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7017 * RTT setting, will return true if the device and carrier both support RTT.
7018 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007019 */
7020 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 final long identity = Binder.clearCallingIdentity();
7022 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007023 boolean isRttSupported = isRttSupported(subscriptionId);
7024 boolean isUserRttSettingOn = Settings.Secure.getInt(
7025 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7026 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7027 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7028 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007032 }
7033
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007034 @Deprecated
7035 @Override
7036 public String getDeviceId(String callingPackage) {
7037 return getDeviceIdWithFeature(callingPackage, null);
7038 }
7039
Sanket Padawe7310cc72015-01-14 09:53:20 -08007040 /**
7041 * Returns the unique device ID of phone, for example, the IMEI for
7042 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7043 *
7044 * <p>Requires Permission:
7045 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7046 */
7047 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007048 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007049 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007050 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007051 return null;
7052 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007053 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007054 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007055 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007056 return null;
7057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058
7059 final long identity = Binder.clearCallingIdentity();
7060 try {
7061 return phone.getDeviceId();
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007065 }
7066
Ping Sunc67b7c22016-03-02 19:16:45 +08007067 /**
7068 * {@hide}
7069 * Returns the IMS Registration Status on a particular subid
7070 *
7071 * @param subId
7072 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007073 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007074 Phone phone = getPhone(subId);
7075 if (phone != null) {
7076 return phone.isImsRegistered();
7077 } else {
7078 return false;
7079 }
7080 }
7081
Santos Cordon7a1885b2015-02-03 11:15:19 -08007082 @Override
7083 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007090 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007091
Tyler Gunnf70ed162019-04-03 15:28:53 -07007092 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007093 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007094 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007096 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007097 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7098 }
7099 final long identity = Binder.clearCallingIdentity();
7100 try {
7101 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 }
7106
7107 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007108 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007109 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7110 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 Phone phone = getPhone(subscriptionId);
7114 if (phone == null) {
7115 return null;
7116 }
7117 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
7121 }
7122
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007123 /**
7124 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007125 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007126 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 Phone phone = getPhone(subId);
7130 if (phone != null) {
7131 return phone.isWifiCallingEnabled();
7132 } else {
7133 return false;
7134 }
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007137 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007138 }
7139
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007140 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007141 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007142 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007143 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 Phone phone = getPhone(subId);
7147 if (phone != null) {
7148 return phone.isVideoEnabled();
7149 } else {
7150 return false;
7151 }
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007154 }
7155 }
7156
7157 /**
7158 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7159 * defined in {@link ImsRegistrationImplBase}.
7160 */
7161 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 Phone phone = getPhone(subId);
7165 if (phone != null) {
7166 return phone.getImsRegistrationTech();
7167 } else {
7168 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7169 }
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007172 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007173 }
7174
Stuart Scott8eef64f2015-04-08 15:13:54 -07007175 @Override
7176 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007177 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007178 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7179 return;
7180 }
7181
Svet Ganovcc087f82015-05-12 20:35:54 -07007182 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183
Svet Ganovcc087f82015-05-12 20:35:54 -07007184 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007185 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7186 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007187 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007188 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007189 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007190 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007191 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7192 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007193 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007194 // There has been issues when Sms raw table somehow stores orphan
7195 // fragments. They lead to garbled message when new fragments come
7196 // in and combined with those stale ones. In case this happens again,
7197 // user can reset all network settings which will clean up this table.
7198 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007199 // Clean up IMS settings as well here.
7200 int slotId = getSlotIndex(subId);
7201 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7202 ImsManager.getInstance(mApp, slotId).factoryReset();
7203 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007204
7205 // Erase modem config if erase modem on network setting is enabled.
7206 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7207 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7208 if (configValue != null && Boolean.parseBoolean(configValue)) {
7209 sendEraseModemConfig(getDefaultPhone());
7210 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007211 } finally {
7212 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007213 }
7214 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007215
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007216 private void cleanUpSmsRawTable(Context context) {
7217 ContentResolver resolver = context.getContentResolver();
7218 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7219 resolver.delete(uri, null, null);
7220 }
7221
Narayan Kamath1c496c22015-04-16 14:40:19 +01007222 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007223 public String getSimLocaleForSubscriber(int subId) {
7224 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7225 final Phone phone = getPhone(subId);
7226 if (phone == null) {
7227 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007228 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 final long identity = Binder.clearCallingIdentity();
7231 try {
chen xu5d3637b2019-01-21 23:31:38 -08007232 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007233 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007234 if (info == null) {
7235 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7236 return null;
7237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 // Try and fetch the locale from the carrier properties or from the SIM language
7239 // preferences (EF-PL and EF-LI)...
7240 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007242 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7243 if (localeFromDefaultSim != null) {
7244 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7245 if (DBG) log("Using locale from subId: " + subId + " locale: "
7246 + localeFromDefaultSim);
7247 return localeFromDefaultSim.toLanguageTag();
7248 } else {
7249 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 }
7251 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 // The SIM language preferences only store a language (e.g. fr = French), not an
7254 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7255 // the SIM and carrier preferences does not include a country we add the country
7256 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007257 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007259 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 return mccLocale.toLanguageTag();
7261 }
7262
7263 if (DBG) log("No locale found - returning null");
7264 return null;
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007268 }
7269
7270 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007271 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007272 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007273 }
7274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 /**
7276 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7277 */
7278 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007279 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007280 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007281 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007282
Chenjie Yu1ba97252018-01-11 18:16:20 -08007283 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007284 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007285
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007286 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007287 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7288 * representing the state of the modem.
7289 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007290 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7291 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007292 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007293 */
7294 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007295 public void requestModemActivityInfo(ResultReceiver result) {
7296 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
sqian1a1be542020-03-05 11:37:28 -08007301 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 } finally {
7303 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007304 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007305 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007306
Siddharth Rayb8114062018-06-17 15:02:38 -07007307 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7308 // less than total activity duration.
7309 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7310 if (info == null) {
7311 return false;
7312 }
7313 int activityDurationMs =
7314 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7315 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007316 int[] txTimeMs = info.getTransmitTimeMillis();
7317 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7318 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007319 }
7320 return (info.isValid()
7321 && (info.getSleepTimeMillis() <= activityDurationMs)
7322 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007323 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007324 && (totalTxTimeMs <= activityDurationMs));
7325 }
7326
Jack Yu85bd38a2015-11-09 11:34:32 -08007327 /**
7328 * {@hide}
7329 * Returns the service state information on specified subscription.
7330 */
7331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007332 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7333 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007335 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007336 return null;
7337 }
7338
Hall Liuf19c44f2018-11-27 14:38:17 -08007339 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7340 LocationAccessPolicy.checkLocationPermission(mApp,
7341 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7342 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007343 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007344 .setCallingPid(Binder.getCallingPid())
7345 .setCallingUid(Binder.getCallingUid())
7346 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007347 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7349 .build());
7350
7351 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7352 LocationAccessPolicy.checkLocationPermission(mApp,
7353 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7354 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007355 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007356 .setCallingPid(Binder.getCallingPid())
7357 .setCallingUid(Binder.getCallingUid())
7358 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007359 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007360 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7361 .build());
7362 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7363 boolean hasFinePermission =
7364 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7365 boolean hasCoarsePermission =
7366 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 final long identity = Binder.clearCallingIdentity();
7369 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007370 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7371 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7372 Rlog.d(LOG_TAG,
7373 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7374 return null;
7375 }
7376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final Phone phone = getPhone(subId);
7378 if (phone == null) {
7379 return null;
7380 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007381
Hall Liuf19c44f2018-11-27 14:38:17 -08007382 ServiceState ss = phone.getServiceState();
7383
7384 // Scrub out the location info in ServiceState depending on what level of access
7385 // the caller has.
7386 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007387 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7388 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007392 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007393
7394 /**
7395 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7396 *
7397 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7398 * voicemail ringtone.
7399 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7400 * PhoneAccount.
7401 */
7402 @Override
7403 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7407 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007408 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007415 }
7416
7417 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007418 * Sets the per-account voicemail ringtone.
7419 *
7420 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7421 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7422 *
7423 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7424 * voicemail ringtone.
7425 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7426 * PhoneAccount.
7427 */
7428 @Override
7429 public void setVoicemailRingtoneUri(String callingPackage,
7430 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007432 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007433 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7434 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7436 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7437 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7443 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 }
7446 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007449 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007450 }
7451
7452 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007453 * Returns whether vibration is set for voicemail notification in Phone settings.
7454 *
7455 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7456 * voicemail vibration setting.
7457 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7458 */
7459 @Override
7460 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
7463 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7464 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007465 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007472 }
7473
Youhan Wange64578a2016-05-02 15:32:42 -07007474 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007475 * Sets the per-account voicemail vibration.
7476 *
7477 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7478 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7479 *
7480 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7481 * voicemail vibration setting.
7482 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7483 * specific PhoneAccount.
7484 */
7485 @Override
7486 public void setVoicemailVibrationEnabled(String callingPackage,
7487 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007490 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7491 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7493 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7494 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007495 }
7496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7500 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007501 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 }
7503 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007506 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007507 }
7508
7509 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007510 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7511 *
7512 * @throws SecurityException if the caller does not have the required permission
7513 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007514 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007515 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007516 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007517 }
7518
7519 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007520 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7521 * permission.
7522 *
7523 * @throws SecurityException if the caller does not have the required permission
7524 */
7525 private void enforceSendSmsPermission() {
7526 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7527 }
7528
7529 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007530 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007531 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007532 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007533 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007534 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 if (componentName == null) {
7540 throw new SecurityException(
7541 "Caller not current active visual voicemail package[null]");
7542 }
7543 String vvmPackage = componentName.getPackageName();
7544 if (!callingPackage.equals(vvmPackage)) {
7545 throw new SecurityException("Caller not current active visual voicemail package["
7546 + vvmPackage + "]");
7547 }
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007550 }
7551 }
7552
7553 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007554 * Return the application ID for the app type.
7555 *
7556 * @param subId the subscription ID that this request applies to.
7557 * @param appType the uicc app type.
7558 * @return Application ID for specificied app type, or null if no uicc.
7559 */
7560 @Override
7561 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007562 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007563 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564
7565 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007566 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 if (phone == null) {
7568 return null;
7569 }
7570 String aid = null;
7571 try {
7572 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7573 .getApplicationByType(appType).getAid();
7574 } catch (Exception e) {
7575 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7576 }
7577 return aid;
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007580 }
Youhan Wange64578a2016-05-02 15:32:42 -07007581 }
7582
Youhan Wang4001d252016-05-11 10:29:41 -07007583 /**
7584 * Return the Electronic Serial Number.
7585 *
7586 * @param subId the subscription ID that this request applies to.
7587 * @return ESN or null if error.
7588 */
7589 @Override
7590 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007591 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007592 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593
7594 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007595 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 if (phone == null) {
7597 return null;
7598 }
7599 String esn = null;
7600 try {
7601 esn = phone.getEsn();
7602 } catch (Exception e) {
7603 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7604 }
7605 return esn;
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007608 }
Youhan Wang4001d252016-05-11 10:29:41 -07007609 }
7610
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007611 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007612 * Return the Preferred Roaming List Version.
7613 *
7614 * @param subId the subscription ID that this request applies to.
7615 * @return PRLVersion or null if error.
7616 */
7617 @Override
7618 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007619 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007620 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621
7622 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007623 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 if (phone == null) {
7625 return null;
7626 }
7627 String cdmaPrlVersion = null;
7628 try {
7629 cdmaPrlVersion = phone.getCdmaPrlVersion();
7630 } catch (Exception e) {
7631 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7632 }
7633 return cdmaPrlVersion;
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007636 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007637 }
7638
7639 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007640 * Get snapshot of Telephony histograms
7641 * @return List of Telephony histograms
7642 * @hide
7643 */
7644 @Override
7645 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7647 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return RIL.getTelephonyRILTimingHistograms();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007655 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007656
7657 /**
7658 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007659 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7660 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007661 * Require system privileges. In the future we may add this to carrier APIs.
7662 *
Michele Berionne482f8202018-11-27 18:57:59 -08007663 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007664 */
7665 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007666 @TelephonyManager.SetCarrierRestrictionResult
7667 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007668 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007670
Michele Berionne482f8202018-11-27 18:57:59 -08007671 if (carrierRestrictionRules == null) {
7672 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007673 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 final long identity = Binder.clearCallingIdentity();
7676 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007677 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007678 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 } finally {
7680 Binder.restoreCallingIdentity(identity);
7681 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007682 }
7683
7684 /**
7685 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007686 * Get the allowed carrier list and the excluded carrier list, including the priority between
7687 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007688 * Require system privileges. In the future we may add this to carrier APIs.
7689 *
Michele Berionne482f8202018-11-27 18:57:59 -08007690 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007691 */
7692 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007693 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007694 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007699 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7700 if (response instanceof CarrierRestrictionRules) {
7701 return (CarrierRestrictionRules) response;
7702 }
7703 // Response is an Exception of some kind,
7704 // which is signalled to the user as a NULL retval
7705 return null;
7706 } catch (Exception e) {
7707 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7708 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007712 }
7713
fionaxu59545b42016-05-25 15:53:37 -07007714 /**
fionaxu59545b42016-05-25 15:53:37 -07007715 * Action set from carrier signalling broadcast receivers to enable/disable radio
7716 * @param subId the subscription ID that this action applies to.
7717 * @param enabled control enable or disable radio.
7718 * {@hide}
7719 */
7720 @Override
7721 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7722 enforceModifyPermission();
7723 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724
7725 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007726 if (phone == null) {
7727 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7728 return;
7729 }
7730 try {
7731 phone.carrierActionSetRadioEnabled(enabled);
7732 } catch (Exception e) {
7733 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 } finally {
7735 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007736 }
7737 }
7738
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007739 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007740 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7741 * network status based on which carrier apps could apply actions accordingly,
7742 * enable/disable default url handler for example.
7743 *
7744 * @param subId the subscription ID that this action applies to.
7745 * @param report control start/stop reporting the default network status.
7746 * {@hide}
7747 */
7748 @Override
7749 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7750 enforceModifyPermission();
7751 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752
7753 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007754 if (phone == null) {
7755 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7756 return;
7757 }
7758 try {
7759 phone.carrierActionReportDefaultNetworkStatus(report);
7760 } catch (Exception e) {
7761 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007764 }
7765 }
7766
7767 /**
fionaxud9622282017-07-17 17:51:30 -07007768 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7769 * @param subId the subscription ID that this action applies to.
7770 * {@hide}
7771 */
7772 @Override
7773 public void carrierActionResetAll(int subId) {
7774 enforceModifyPermission();
7775 final Phone phone = getPhone(subId);
7776 if (phone == null) {
7777 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7778 return;
7779 }
7780 try {
7781 phone.carrierActionResetAll();
7782 } catch (Exception e) {
7783 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7784 }
7785 }
7786
7787 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007788 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7789 * bug report is being generated.
7790 */
7791 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007792 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007793 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7794 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007795 writer.println("Permission Denial: can't dump Phone from pid="
7796 + Binder.getCallingPid()
7797 + ", uid=" + Binder.getCallingUid()
7798 + "without permission "
7799 + android.Manifest.permission.DUMP);
7800 return;
7801 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007802 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007803 }
Jack Yueb89b242016-06-22 13:27:47 -07007804
Brad Ebingerdac2f002018-04-03 15:17:52 -07007805 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007806 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7807 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7808 @NonNull String[] args) {
7809 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7810 this, in.getFileDescriptor(), out.getFileDescriptor(),
7811 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007812 }
7813
Jack Yueb89b242016-06-22 13:27:47 -07007814 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007815 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007816 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007817 * @param reason the reason the data enable change is taking place
7818 * @param enabled True if enabling the data, otherwise disabling.
7819 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007820 */
7821 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007822 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007823 boolean enabled) {
7824 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7825 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7826 try {
7827 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007828 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007829 } catch (SecurityException se) {
7830 enforceModifyPermission();
7831 }
7832 } else {
7833 enforceModifyPermission();
7834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 Phone phone = getPhone(subId);
7839 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007840 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7841 phone.carrierActionSetMeteredApnsEnabled(enabled);
7842 } else {
7843 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 }
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007848 }
7849 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007850
7851 /**
7852 * Get Client request stats
7853 * @return List of Client Request Stats
7854 * @hide
7855 */
7856 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007857 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7858 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007860 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007861 return null;
7862 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007863 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 final long identity = Binder.clearCallingIdentity();
7866 try {
7867 if (phone != null) {
7868 return phone.getClientRequestStats();
7869 }
7870
7871 return null;
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007875 }
7876
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007877 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007878 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007879 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007880 }
Jack Yueb4124c2017-02-16 15:32:43 -08007881
7882 /**
Grace Chen70990072017-03-24 17:21:30 -07007883 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007884 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007885 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007886 * @param state State of SIM (power down, power up, pass through)
7887 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7888 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7889 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007890 *
7891 **/
7892 @Override
Grace Chen70990072017-03-24 17:21:30 -07007893 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007894 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007895 Phone phone = PhoneFactory.getPhone(slotIndex);
7896
vagdeviaf9a5b92018-08-15 16:01:53 -07007897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 final long identity = Binder.clearCallingIdentity();
7900 try {
7901 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007902 phone.setSimPowerState(state, null, workSource);
7903 }
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
7908
7909 /**
7910 * Set SIM card power state.
7911 *
7912 * @param slotIndex SIM slot id.
7913 * @param state State of SIM (power down, power up, pass through)
7914 * @param callback callback to trigger after success or failure
7915 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7916 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7917 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7918 *
7919 **/
7920 @Override
7921 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7922 IIntegerConsumer callback) {
7923 enforceModifyPermission();
7924 Phone phone = PhoneFactory.getPhone(slotIndex);
7925
7926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7927
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 if (phone != null) {
7931 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7932 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 }
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007936 }
7937 }
Shuo Qiandd210312017-04-12 22:11:33 +00007938
Tyler Gunn65d45c22017-06-05 11:22:26 -07007939 private boolean isUssdApiAllowed(int subId) {
7940 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007941 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007942 if (configManager == null) {
7943 return false;
7944 }
7945 PersistableBundle pb = configManager.getConfigForSubId(subId);
7946 if (pb == null) {
7947 return false;
7948 }
7949 return pb.getBoolean(
7950 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7951 }
7952
Shuo Qiandd210312017-04-12 22:11:33 +00007953 /**
7954 * Check if phone is in emergency callback mode
7955 * @return true if phone is in emergency callback mode
7956 * @param subId sub id
7957 */
goneil9c5f4872017-12-05 14:07:56 -08007958 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007959 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007960 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007961 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 if (phone != null) {
7966 return phone.isInEcm();
7967 } else {
7968 return false;
7969 }
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007972 }
7973 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007974
7975 /**
7976 * Get the current signal strength information for the given subscription.
7977 * Because this information is not updated when the device is in a low power state
7978 * it should not be relied-upon to be current.
7979 * @param subId Subscription index
7980 * @return the most recent cached signal strength info from the modem
7981 */
7982 @Override
7983 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 Phone p = getPhone(subId);
7987 if (p == null) {
7988 return null;
7989 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 return p.getSignalStrength();
7992 } finally {
7993 Binder.restoreCallingIdentity(identity);
7994 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007996
Pengquan Meng77b7f132018-08-22 14:49:57 -07007997 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007998 * Get the current modem radio state for the given slot.
7999 * @param slotIndex slot index.
8000 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008001 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008002 * @return the current radio power state from the modem
8003 */
8004 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008005 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008006 Phone phone = PhoneFactory.getPhone(slotIndex);
8007 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8009 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008010 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8011 }
8012
8013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 return phone.getRadioPowerState();
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
8020 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8021 }
8022
8023 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008024 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8025 *
8026 * <p>Requires one of the following permissions:
8027 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8028 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8029 * privileges.
8030 *
8031 * @param subId subscription id
8032 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8033 * {@code false}.
8034 */
8035 @Override
8036 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008037 try {
8038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8039 null);
8040 } catch (Exception e) {
8041 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8042 mApp, subId, "isDataRoamingEnabled");
8043 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008044
Pengquan Menga1bb6272018-09-06 09:59:22 -07008045 boolean isEnabled = false;
8046 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008047 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008048 Phone phone = getPhone(subId);
8049 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008050 } finally {
8051 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008052 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008053 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008054 }
8055
8056
8057 /**
8058 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8059 *
8060 * <p> Requires permission:
8061 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8062 * privileges.
8063 *
8064 * @param subId subscription id
8065 * @param isEnabled {@code true} means enable, {@code false} means disable.
8066 */
8067 @Override
8068 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8070 mApp, subId, "setDataRoamingEnabled");
8071
Pengquan Menga1bb6272018-09-06 09:59:22 -07008072 final long identity = Binder.clearCallingIdentity();
8073 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008074 Phone phone = getPhone(subId);
8075 if (phone != null) {
8076 phone.setDataRoamingEnabled(isEnabled);
8077 }
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008080 }
8081 }
8082
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008083 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008084 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008085 TelephonyPermissions
8086 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008087 mApp, subId, "isManualNetworkSelectionAllowed");
8088
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008089 boolean isAllowed = true;
8090 final long identity = Binder.clearCallingIdentity();
8091 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008092 Phone phone = getPhone(subId);
8093 if (phone != null) {
8094 isAllowed = phone.isCspPlmnEnabled();
8095 }
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
8098 }
8099 return isAllowed;
8100 }
8101
8102 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008103 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008104 // Verify that tha callingPackage belongs to the calling UID
8105 mApp.getSystemService(AppOpsManager.class)
8106 .checkPackage(Binder.getCallingUid(), callingPackage);
8107
Jordan Liu1e142fc2019-04-22 15:10:43 -07008108 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008109 try {
8110 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008111 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008112 } catch (SecurityException e) {
8113 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8114 // has carrier privileges on an active UICC
8115 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8116 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008117 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008118 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008119 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008120
8121 final long identity = Binder.clearCallingIdentity();
8122 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008123 UiccController uiccController = UiccController.getInstance();
8124 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008125 if (hasReadPermission) {
8126 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008127 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008128
8129 // Remove private info if the caller doesn't have access
8130 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8131 for (UiccCardInfo cardInfo : cardInfos) {
8132 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8133 // is available
8134 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8135 if (card == null || card.getUiccProfile() == null) {
8136 // assume no access if the card or profile is unavailable
8137 filteredInfos.add(cardInfo.getUnprivileged());
8138 continue;
8139 }
8140 UiccProfile profile = card.getUiccProfile();
8141 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8142 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8143 filteredInfos.add(cardInfo);
8144 } else {
8145 filteredInfos.add(cardInfo.getUnprivileged());
8146 }
8147 }
8148 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008149 } finally {
8150 Binder.restoreCallingIdentity(identity);
8151 }
8152 }
8153
8154 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008155 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008156 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8161 if (slots == null) {
8162 Rlog.i(LOG_TAG, "slots is null.");
8163 return null;
8164 }
8165
8166 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8167 for (int i = 0; i < slots.length; i++) {
8168 UiccSlot slot = slots[i];
8169 if (slot == null) {
8170 continue;
8171 }
8172
Jordan Liu7be7e652019-05-06 18:55:02 +00008173 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174 UiccCard card = slot.getUiccCard();
8175 if (card != null) {
8176 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008177 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008178 cardId = slot.getEid();
8179 if (TextUtils.isEmpty(cardId)) {
8180 cardId = slot.getIccId();
8181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 }
8183
Jordan Liu857451f2019-05-09 16:35:35 -07008184 if (cardId != null) {
8185 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8186 // if cardId is an EID, it's all digits so this is fine
8187 cardId = IccUtils.stripTrailingFs(cardId);
8188 }
8189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 int cardState = 0;
8191 switch (slot.getCardState()) {
8192 case CARDSTATE_ABSENT:
8193 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8194 break;
8195 case CARDSTATE_PRESENT:
8196 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8197 break;
8198 case CARDSTATE_ERROR:
8199 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8200 break;
8201 case CARDSTATE_RESTRICTED:
8202 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8203 break;
8204 default:
8205 break;
8206
8207 }
8208
8209 infos[i] = new UiccSlotInfo(
8210 slot.isActive(),
8211 slot.isEuicc(),
8212 cardId,
8213 cardState,
8214 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008215 slot.isExtendedApduSupported(),
8216 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 }
8218 return infos;
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008221 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008222 }
8223
8224 @Override
8225 public boolean switchSlots(int[] physicalSlots) {
8226 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227
8228 final long identity = Binder.clearCallingIdentity();
8229 try {
8230 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8231 } finally {
8232 Binder.restoreCallingIdentity(identity);
8233 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008234 }
Jack Yu4c988042018-02-27 15:30:01 -08008235
8236 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008237 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008238 final long identity = Binder.clearCallingIdentity();
8239 try {
8240 return UiccController.getInstance().getCardIdForDefaultEuicc();
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
8244 }
8245
Pengquan Meng85728fb2018-03-12 16:31:21 -07008246 /**
goneil47ffb6e2018-04-06 15:40:58 -07008247 * A test API to reload the UICC profile.
8248 *
8249 * <p>Requires that the calling app has permission
8250 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8251 * @hide
8252 */
8253 @Override
8254 public void refreshUiccProfile(int subId) {
8255 enforceModifyPermission();
8256
8257 final long identity = Binder.clearCallingIdentity();
8258 try {
8259 Phone phone = getPhone(subId);
8260 if (phone == null) {
8261 return;
8262 }
8263 UiccCard uiccCard = phone.getUiccCard();
8264 if (uiccCard == null) {
8265 return;
8266 }
8267 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8268 if (uiccProfile == null) {
8269 return;
8270 }
8271 uiccProfile.refresh();
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 }
8276
8277 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008278 * Returns false if the mobile data is disabled by default, otherwise return true.
8279 */
8280 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008281 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008282 }
8283
8284 /**
8285 * Returns true if the data roaming is enabled by default, i.e the system property
8286 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8287 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8288 */
8289 private boolean getDefaultDataRoamingEnabled(int subId) {
8290 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008291 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008292 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008293 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8294 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8295 return isDataRoamingEnabled;
8296 }
8297
8298 /**
8299 * Returns the default network type for the given {@code subId}, if the default network type is
8300 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8301 */
8302 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008303 List<Integer> list = TelephonyProperties.default_network();
8304 int phoneId = mSubscriptionController.getPhoneId(subId);
8305 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8306 return list.get(phoneId);
8307 }
8308 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008309 }
fionaxua13278b2018-03-21 00:08:13 -07008310
8311 @Override
8312 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008313 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 final Phone phone = getPhone(subId);
8319 if (phone == null) {
8320 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8321 return;
8322 }
chen xueaba88a2019-03-15 13:15:10 -07008323 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8324 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008325 if (carrierPrivilegeRules == null) {
8326 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8327 } else {
8328 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 } finally {
8331 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008332 }
fionaxua13278b2018-03-21 00:08:13 -07008333 }
8334
8335 @Override
8336 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008337 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 final Phone phone = getPhone(subId);
8342 if (phone == null) {
8343 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8344 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8345 }
8346 return phone.getCarrierIdListVersion();
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008349 }
fionaxua13278b2018-03-21 00:08:13 -07008350 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008351
8352 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008353 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8354 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008356 mApp, subId, callingPackage, callingFeatureId,
8357 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008358 return -1;
8359 }
8360
8361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008368
8369 @Override
8370 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008371 TelephonyPermissions
8372 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008373 mApp, subId, "getCdmaRoamingMode");
8374
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
8381 }
8382
8383 @Override
8384 public boolean setCdmaRoamingMode(int subId, int mode) {
8385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8386 mApp, subId, "setCdmaRoamingMode");
8387
8388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8391 } finally {
8392 Binder.restoreCallingIdentity(identity);
8393 }
8394 }
8395
8396 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008397 public int getCdmaSubscriptionMode(int subId) {
8398 TelephonyPermissions
8399 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8400 mApp, subId, "getCdmaSubscriptionMode");
8401
8402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8405 } finally {
8406 Binder.restoreCallingIdentity(identity);
8407 }
8408 }
8409
8410 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008411 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8413 mApp, subId, "setCdmaSubscriptionMode");
8414
8415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8418 } finally {
8419 Binder.restoreCallingIdentity(identity);
8420 }
8421 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008422
sqianc5eccab2018-10-19 18:46:41 -07008423 @Override
sqian8c685422019-02-22 15:55:18 -08008424 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008425 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008427 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8428 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008429 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8430 }
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
sqian854d44b2018-12-12 16:48:18 -08008433 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8434 for (Phone phone: PhoneFactory.getPhones()) {
8435 if (phone.getEmergencyNumberTracker() != null
8436 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8437 emergencyNumberListInternal.put(
8438 phone.getSubId(),
8439 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8440 }
sqian11b7a0e2018-12-05 18:48:28 -08008441 }
sqian854d44b2018-12-12 16:48:18 -08008442 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
sqianc5eccab2018-10-19 18:46:41 -07008446 }
8447
8448 @Override
sqian8c685422019-02-22 15:55:18 -08008449 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008451 if (!exactMatch) {
8452 TelephonyPermissions
8453 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008454 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008455 }
8456 final long identity = Binder.clearCallingIdentity();
8457 try {
sqian854d44b2018-12-12 16:48:18 -08008458 for (Phone phone: PhoneFactory.getPhones()) {
8459 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008460 && phone.getEmergencyNumberTracker()
8461 .isEmergencyNumber(number, exactMatch)) {
8462 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008463 }
sqian11b7a0e2018-12-05 18:48:28 -08008464 }
8465 return false;
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
sqianf4ca7ed2019-01-15 18:32:07 -08008471 /**
8472 * Update emergency number list for test mode.
8473 */
8474 @Override
8475 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8476 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8477 "updateEmergencyNumberListTestMode");
8478
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 for (Phone phone: PhoneFactory.getPhones()) {
8482 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8483 if (tracker != null) {
8484 tracker.executeEmergencyNumberTestModeCommand(action, num);
8485 }
8486 }
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
8490 }
8491
8492 /**
8493 * Get the full emergency number list for test mode.
8494 */
8495 @Override
8496 public List<String> getEmergencyNumberListTestMode() {
8497 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8498 "getEmergencyNumberListTestMode");
8499
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 Set<String> emergencyNumbers = new HashSet<>();
8503 for (Phone phone: PhoneFactory.getPhones()) {
8504 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8505 if (tracker != null) {
8506 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8507 emergencyNumbers.add(num.getNumber());
8508 }
8509 }
8510 }
8511 return new ArrayList<>(emergencyNumbers);
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 }
8516
chen xud6b45bd2018-10-30 22:27:10 -07008517 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008518 public int getEmergencyNumberDbVersion(int subId) {
8519 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8520
8521 final long identity = Binder.clearCallingIdentity();
8522 try {
8523 final Phone phone = getPhone(subId);
8524 if (phone == null) {
8525 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8526 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8527 }
8528 return phone.getEmergencyNumberDbVersion();
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
8533
8534 @Override
8535 public void notifyOtaEmergencyNumberDbInstalled() {
8536 enforceModifyPermission();
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 for (Phone phone: PhoneFactory.getPhones()) {
8541 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8542 if (tracker != null) {
8543 tracker.updateOtaEmergencyNumberDatabase();
8544 }
8545 }
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008552 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008553 enforceActiveEmergencySessionPermission();
8554
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 for (Phone phone: PhoneFactory.getPhones()) {
8558 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8559 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008560 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8561 }
8562 }
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
8565 }
8566 }
8567
8568 @Override
8569 public void resetOtaEmergencyNumberDbFilePath() {
8570 enforceActiveEmergencySessionPermission();
8571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 for (Phone phone: PhoneFactory.getPhones()) {
8575 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8576 if (tracker != null) {
8577 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008578 }
8579 }
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
8583 }
8584
8585 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008586 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8587 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8588 Phone phone = getPhone(subId);
8589 if (phone == null) {
8590 return null;
8591 }
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 UiccProfile profile = UiccController.getInstance()
8595 .getUiccProfileForPhone(phone.getPhoneId());
8596 if (profile != null) {
8597 return profile.getCertsFromCarrierPrivilegeAccessRules();
8598 }
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 return null;
8603 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008604
8605 /**
8606 * Enable or disable a modem stack.
8607 */
8608 @Override
8609 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8610 enforceModifyPermission();
8611
8612 final long identity = Binder.clearCallingIdentity();
8613 try {
8614 Phone phone = PhoneFactory.getPhone(slotIndex);
8615 if (phone == null) {
8616 return false;
8617 } else {
8618 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8619 }
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
8622 }
8623 }
Michelecea4cf22018-12-21 15:00:11 -08008624
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008625 /**
8626 * Whether a modem stack is enabled or not.
8627 */
8628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008629 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8630 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008631 Phone phone = PhoneFactory.getPhone(slotIndex);
8632 if (phone == null) return false;
8633
8634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008635 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8636 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008637 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8638 }
8639
8640 final long identity = Binder.clearCallingIdentity();
8641 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008642 try {
8643 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8644 } catch (NoSuchElementException ex) {
8645 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8646 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
8650 }
8651
Michelecea4cf22018-12-21 15:00:11 -08008652 @Override
Michele0ea7d782019-03-19 14:58:42 -07008653 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008654 enforceModifyPermission();
8655
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
8658 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008659 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008660 .commit();
8661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
8664 }
8665
8666 @Override
Michele0ea7d782019-03-19 14:58:42 -07008667 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008668 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008670 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8671 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008672 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008673 }
Michelecea4cf22018-12-21 15:00:11 -08008674
8675 final long identity = Binder.clearCallingIdentity();
8676 try {
Michele0ea7d782019-03-19 14:58:42 -07008677 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
8681 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008682
Michele0ea7d782019-03-19 14:58:42 -07008683 @TelephonyManager.IsMultiSimSupportedResult
8684 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008685 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8686 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8687 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008688 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8689 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008690 }
8691 // Check if the hardware supports multisim functionality. If usage of multisim is not
8692 // supported by the modem, indicate that it is restricted.
8693 PhoneCapability staticCapability =
8694 mPhoneConfigurationManager.getStaticPhoneCapability();
8695 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008696 loge("isMultiSimSupportedInternal: no static configuration available");
8697 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008698 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008699 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008700 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8701 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008702 }
8703 // Check if support of multiple SIMs is restricted by carrier
8704 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008705 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008706 }
8707
Michele0ea7d782019-03-19 14:58:42 -07008708 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008709 }
8710
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008711 /**
8712 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008713 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8714 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8715 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008716 * @param numOfSims number of active sims we want to switch to
8717 */
8718 @Override
8719 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008720 if (numOfSims == 1) {
8721 enforceModifyPermission();
8722 } else {
8723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8724 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8725 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008726 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008727
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008728 try {
Michele30b57b22019-03-01 12:01:14 -08008729 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008730 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008731 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8732 return;
8733 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008734 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8735 } finally {
8736 Binder.restoreCallingIdentity(identity);
8737 }
8738 }
8739
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008740 @Override
8741 public boolean isApplicationOnUicc(int subId, int appType) {
8742 enforceReadPrivilegedPermission("isApplicationOnUicc");
8743 Phone phone = getPhone(subId);
8744 if (phone == null) {
8745 return false;
8746 }
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 UiccCard uiccCard = phone.getUiccCard();
8750 if (uiccCard == null) {
8751 return false;
8752 }
8753 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8754 if (uiccProfile == null) {
8755 return false;
8756 }
8757 if (TelephonyManager.APPTYPE_SIM <= appType
8758 && appType <= TelephonyManager.APPTYPE_ISIM) {
8759 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8760 }
8761 return false;
8762 } finally {
8763 Binder.restoreCallingIdentity(identity);
8764 }
8765 }
8766
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008767 /**
chen xub4baa772019-04-03 10:23:41 -07008768 * Get whether making changes to modem configurations will trigger reboot.
8769 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008770 */
8771 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008772 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8773 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008775 mApp, subId, callingPackage, callingFeatureId,
8776 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008777 return false;
8778 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008779 final long identity = Binder.clearCallingIdentity();
8780 try {
8781 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
8784 }
8785 }
8786
Nathan Harold29f5f052019-02-15 13:41:57 -08008787 private void updateModemStateMetrics() {
8788 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8789 // TODO: check the state for each modem if the api is ready.
8790 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8791 }
8792
Pengquan Meng3889a572019-01-23 11:16:29 -08008793 @Override
8794 public int[] getSlotsMapping() {
8795 enforceReadPrivilegedPermission("getSlotsMapping");
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8800 // All logical slots should have a mapping to a physical slot.
8801 int[] logicalSlotsMapping = new int[phoneCount];
8802 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8803 for (int i = 0; i < slotInfos.length; i++) {
8804 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8805 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8806 }
8807 }
8808 return logicalSlotsMapping;
8809 } finally {
8810 Binder.restoreCallingIdentity(identity);
8811 }
8812 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008813
8814 /**
8815 * Get the IRadio HAL Version
8816 */
8817 @Override
8818 public int getRadioHalVersion() {
8819 Phone phone = getDefaultPhone();
8820 if (phone == null) return -1;
8821 HalVersion hv = phone.getHalVersion();
8822 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8823 return hv.major * 100 + hv.minor;
8824 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008825
8826 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008827 * Get the current calling package name.
8828 * @return the current calling package name
8829 */
8830 @Override
8831 public String getCurrentPackageName() {
8832 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8833 }
8834
8835 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008836 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8837 * corresponding network requests on a subId.
8838 *
8839 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008840 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008841 * 2) APN is un-metered for this subscription, or
8842 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008843 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008844 *
8845 * @return whether data is allowed for a apn type.
8846 *
8847 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008848 */
8849 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008850 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008851 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8852 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008853
8854 // Now that all security checks passes, perform the operation as ourselves.
8855 final long identity = Binder.clearCallingIdentity();
8856 try {
8857 Phone phone = getPhone(subId);
8858 if (phone == null) return false;
8859
Jack Yu41407ee2019-05-13 16:54:09 -07008860 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008861 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
8865 }
8866
8867 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008868 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008869 enforceReadPrivilegedPermission("isApnMetered");
8870
8871 // Now that all security checks passes, perform the operation as ourselves.
8872 final long identity = Binder.clearCallingIdentity();
8873 try {
8874 Phone phone = getPhone(subId);
8875 if (phone == null) return true; // By default return true.
8876
Jack Yu41407ee2019-05-13 16:54:09 -07008877 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
8881 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008882
8883 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008884 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8885 int subscriptionId, IBooleanConsumer resultCallback) {
8886 enforceModifyPermission();
8887 long token = Binder.clearCallingIdentity();
8888 try {
8889 Phone phone = getPhone(subscriptionId);
8890 if (phone == null) {
8891 try {
8892 if (resultCallback != null) {
8893 resultCallback.accept(false);
8894 }
8895 } catch (RemoteException e) {
8896 // ignore
8897 }
8898 return;
8899 }
8900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8901 Pair.create(specifiers, (x) -> {
8902 try {
8903 if (resultCallback != null) {
8904 resultCallback.accept(x);
8905 }
8906 } catch (RemoteException e) {
8907 // ignore
8908 }
8909 });
8910 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8911 } finally {
8912 Binder.restoreCallingIdentity(token);
8913 }
8914 }
8915
8916 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008917 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8918 TelephonyPermissions
8919 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8920 mApp, subId, "getSystemSelectionChannels");
8921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 List<RadioAccessSpecifier> specifiers =
8925 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8926 null, subId, workSource);
8927 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8928 return specifiers;
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
8932 }
8933
8934 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008935 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008936 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008937 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8938 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8939 if (iccRecords == null) {
8940 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8941 return false;
8942 }
8943 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8944 }
8945
8946 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008947 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8948 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008949 if (callingPackage == null) {
8950 callingPackage = getCurrentPackageName();
8951 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008952 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8953 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008954 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8955 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008956 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8957 }
8958 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8959 Intent intent = new Intent();
8960 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8961 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8962 // Bring up choose default SMS subscription dialog right now
8963 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8964 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8965 mApp.startActivity(intent);
8966 }
chen xud5ca2d52019-05-28 15:20:57 -07008967
8968 @Override
8969 public String getMmsUAProfUrl(int subId) {
8970 //TODO investigate if this API should require proper permission check in R b/133791609
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008973 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8974 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8975 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8976 return carrierUAProfUrl;
8977 }
chen xud5ca2d52019-05-28 15:20:57 -07008978 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8979 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
8985 @Override
8986 public String getMmsUserAgent(int subId) {
8987 //TODO investigate if this API should require proper permission check in R b/133791609
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008990 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8991 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8992 if (!TextUtils.isEmpty(carrierUserAgent)) {
8993 return carrierUserAgent;
8994 }
chen xud5ca2d52019-05-28 15:20:57 -07008995 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8996 .getString(com.android.internal.R.string.config_mms_user_agent);
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
8999 }
9000 }
Jack Yub07d4972019-05-28 16:12:25 -07009001
9002 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009003 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9004 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subscriptionId);
9009 if (phone == null) return false;
9010
9011 switch (policy) {
9012 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9013 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9014 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9015 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9016 default:
9017 throw new IllegalArgumentException(policy + " is not a valid policy");
9018 }
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 }
9023
9024 @Override
9025 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9026 boolean enabled) {
9027 enforceModifyPermission();
9028
9029 final long identity = Binder.clearCallingIdentity();
9030 try {
9031 Phone phone = getPhone(subscriptionId);
9032 if (phone == null) return;
9033
9034 switch (policy) {
9035 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9036 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9037 break;
9038 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9039 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9040 break;
9041 default:
9042 throw new IllegalArgumentException(policy + " is not a valid policy");
9043 }
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
9048
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009049 /**
Hall Liub48cf452020-09-25 11:13:49 -07009050 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009051 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9052 * otherwise.
9053 */
9054 @Override
9055 public void setCepEnabled(boolean isCepEnabled) {
9056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9061 for (Phone phone : PhoneFactory.getPhones()) {
9062 Phone defaultPhone = phone.getImsPhone();
9063 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9064 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9065 ImsPhoneCallTracker imsPhoneCallTracker =
9066 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9067 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9068 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9069 + imsPhone.getMsisdn());
9070 }
9071 }
9072 } finally {
9073 Binder.restoreCallingIdentity(identity);
9074 }
9075 }
allenwtsu46dcc572020-01-08 18:24:03 +08009076
9077 /**
9078 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9079 *
9080 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9081 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9082 * before being read.
9083 */
9084 @Override
9085 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9086 isCompressed) {
9087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9088 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009089 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9090 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9091 }
9092 if (!isImsAvailableOnDevice()) {
9093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9094 "IMS not available on device.");
9095 }
9096
9097 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009098 try {
Hui Wang068ab862020-10-31 05:12:53 +00009099 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009102 }
9103 }
zoey chenf95ca592019-12-30 16:11:23 +08009104
9105 @Override
9106 public boolean isIccLockEnabled(int subId) {
9107 enforceReadPrivilegedPermission("isIccLockEnabled");
9108
9109 // Now that all security checks passes, perform the operation as ourselves.
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 Phone phone = getPhone(subId);
9113 if (phone != null && phone.getIccCard() != null) {
9114 return phone.getIccCard().getIccLockEnabled();
9115 } else {
9116 return false;
9117 }
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
9121 }
9122
9123 /**
zoey chene02881a2019-12-30 16:11:23 +08009124 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009125 *
zoey chene02881a2019-12-30 16:11:23 +08009126 * @return an integer representing the status of IccLock enabled or disabled in the following
9127 * three cases:
9128 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9129 * successfully.
9130 * - Positive number and zero for remaining password attempts.
9131 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009132 *
9133 */
9134 @Override
9135 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9136 enforceModifyPermission();
9137
9138 Phone phone = getPhone(subId);
9139 if (phone == null) {
9140 return 0;
9141 }
9142 // Now that all security checks passes, perform the operation as ourselves.
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9146 new Pair<Boolean, String>(enabled, password), phone, null);
9147 return attemptsRemaining;
9148
9149 } catch (Exception e) {
9150 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 return 0;
9155 }
9156
9157 /**
9158 * Change the ICC password used in ICC pin lock.
9159 *
zoey chene02881a2019-12-30 16:11:23 +08009160 * @return an integer representing the status of IccLock changed in the following three cases:
9161 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9162 * - Positive number and zero for remaining password attempts.
9163 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009164 *
9165 */
9166 @Override
9167 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9168 enforceModifyPermission();
9169
9170 Phone phone = getPhone(subId);
9171 if (phone == null) {
9172 return 0;
9173 }
9174 // Now that all security checks passes, perform the operation as ourselves.
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9178 new Pair<String, String>(oldPassword, newPassword), phone, null);
9179 return attemptsRemaining;
9180
9181 } catch (Exception e) {
9182 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 return 0;
9187 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009188
Peter Wangdafb9ac2020-01-15 14:13:38 -08009189 /**
9190 * Request for receiving user activity notification
9191 */
9192 @Override
9193 public void requestUserActivityNotification() {
9194 if (!mNotifyUserActivity.get()
9195 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9196 mNotifyUserActivity.set(true);
9197 }
9198 }
9199
9200 /**
9201 * Called when userActivity is signalled in the power manager.
9202 * This is safe to call from any thread, with any window manager locks held or not.
9203 */
9204 @Override
9205 public void userActivity() {
9206 // ***************************************
9207 // * Inherited from PhoneWindowManager *
9208 // ***************************************
9209 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9210 // WITH ITS LOCKS HELD.
9211 //
9212 // This code must be VERY careful about the locks
9213 // it acquires.
9214 // In fact, the current code acquires way too many,
9215 // and probably has lurking deadlocks.
9216
9217 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9218 throw new SecurityException("Only the OS may call notifyUserActivity()");
9219 }
9220
9221 if (mNotifyUserActivity.getAndSet(false)) {
9222 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9223 USER_ACTIVITY_NOTIFICATION_DELAY);
9224 }
9225 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009226
Malcolm Chen884180b2020-04-13 11:59:40 -07009227 @Override
9228 public boolean canConnectTo5GInDsdsMode() {
9229 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9230 }
Jack Yud10cdd42020-09-28 20:28:01 -07009231
9232 @Override
9233 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9234 String callingFeatureId) {
9235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9236 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9237 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9238 }
9239
9240 Phone phone = getPhone(subId);
9241 if (phone == null) {
9242 throw new RuntimeException("phone is not available");
9243 }
9244 // Now that all security checks passes, perform the operation as ourselves.
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 return phone.getEquivalentHomePlmns();
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009252
Hui Wang0866fcc2020-10-12 12:14:23 -07009253 @Override
9254 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9255 UaSecurityProtocolIdentifier securityProtocol,
9256 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9257 throws RemoteException {
9258 enforceModifyPermission();
9259 if (DBG) {
9260 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9261 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9262 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9263 }
9264
9265 if (!SubscriptionManager.isValidSubscriptionId(subId)
9266 || appType < TelephonyManager.APPTYPE_UNKNOWN
9267 || appType > TelephonyManager.APPTYPE_ISIM
9268 || nafUrl == null || securityProtocol == null || callback == null) {
9269 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9270 if (callback != null) {
9271 try {
9272 callback.onAuthenticationFailure(
9273 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9274 } catch (RemoteException exception) {
9275 log("Fail to notify onAuthenticationFailure due to " + exception);
9276 }
9277 return;
9278 }
9279 }
9280
9281 final long token = Binder.clearCallingIdentity();
9282 try {
9283 getGbaManager(subId).bootstrapAuthenticationRequest(
9284 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9285 forceBootStrapping, callback));
9286 } finally {
9287 Binder.restoreCallingIdentity(token);
9288 }
9289 }
9290
Jack Nudelman24d51a52020-11-24 12:08:04 -08009291 /**
9292 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9293 * requested radio power state will actually be set. See {@link
9294 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9295 *
9296 * @param subId the subscription ID of the phone requesting to set the radio power state.
9297 * @param enable {@code true} if trying to turn radio on.
9298 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9299 * false}.
9300 */
9301 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9302 Phone phone = getPhone(subId);
9303 if (phone != null) {
9304 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9305 return true;
9306 }
9307 return false;
9308 }
9309
9310 private int handleDataThrottlingRequest(int subId,
9311 DataThrottlingRequest dataThrottlingRequest) {
9312 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9313 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9314 if (!setRadioPowerForThermal(subId, true)) {
9315 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9316 }
9317
9318 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9319
9320 int thermalMitigationResult =
9321 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9322 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9323 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9324 }
9325 return thermalMitigationResult;
9326 }
9327
9328 /**
9329 * Thermal mitigation request to control functionalities at modem.
9330 *
9331 * @param subId the id of the subscription.
9332 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9333 *
9334 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9335 */
9336 @Override
9337 @ThermalMitigationResult
9338 public int sendThermalMitigationRequest(
9339 int subId,
9340 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9341 enforceModifyPermission();
9342
9343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9344 final long identity = Binder.clearCallingIdentity();
9345
9346 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9347 try {
9348 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9349 switch (thermalMitigationAction) {
9350 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9351 thermalMitigationResult =
9352 handleDataThrottlingRequest(subId,
9353 thermalMitigationRequest.getDataThrottlingRequest());
9354 break;
9355 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9356 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9357 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9358 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9359 }
9360
9361 // Ensure that radio is on. If not able to power on due to phone being
9362 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9363 if (!setRadioPowerForThermal(subId, true)) {
9364 thermalMitigationResult =
9365 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9366 break;
9367 }
9368
9369 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9370 false);
9371 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9372 break;
9373 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9374 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9375 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9376 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9377 }
9378
9379 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9380 if (registry != null) {
9381 TelephonyConnectionService service =
9382 registry.getTelephonyConnectionService();
9383 Phone phone = getPhone(subId);
9384 if (phone == null) {
9385 thermalMitigationResult =
9386 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9387 break;
9388 }
9389
9390 if (PhoneConstantConversions.convertCallState(phone.getState())
9391 != TelephonyManager.CALL_STATE_IDLE
9392 || phone.isInEmergencySmsMode() || phone.isInEcm()
9393 || (service != null && service.isEmergencyCallPending())) {
9394 String errorMessage = "Phone state is not valid. call state = "
9395 + PhoneConstantConversions.convertCallState(phone.getState())
9396 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9397 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9398 errorMessage += service == null
9399 ? " TelephonyConnectionService is null"
9400 : " isEmergencyCallPending = "
9401 + service.isEmergencyCallPending();
9402 Log.e(LOG_TAG, errorMessage);
9403 thermalMitigationResult =
9404 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9405 break;
9406 }
9407 } else {
9408 thermalMitigationResult =
9409 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9410 break;
9411 }
9412
9413 // Turn radio off. If not able to power off due to phone being unavailable,
9414 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9415 if (!setRadioPowerForThermal(subId, false)) {
9416 thermalMitigationResult =
9417 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9418 break;
9419 }
9420 thermalMitigationResult =
9421 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9422 break;
9423 default:
9424 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9425 + "not exist. Requested action: " + thermalMitigationAction);
9426 }
9427 } catch (IllegalArgumentException e) {
9428 throw e;
9429 } catch (Exception e) {
9430 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9431 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435
9436 if (DBG) {
9437 log("thermalMitigationRequest returning with thermalMitigationResult: "
9438 + thermalMitigationResult);
9439 }
9440
9441 return thermalMitigationResult;
9442 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009443
9444 /**
9445 * Set the GbaService Package Name that Telephony will bind to.
9446 *
9447 * @param subId The sim that the GbaService is associated with.
9448 * @param packageName The name of the package to be replaced with.
9449 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9450 */
9451 @Override
9452 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9453 enforceModifyPermission();
9454
9455 final long identity = Binder.clearCallingIdentity();
9456 try {
9457 return getGbaManager(subId).overrideServicePackage(packageName);
9458 } finally {
9459 Binder.restoreCallingIdentity(identity);
9460 }
9461 }
9462
9463 /**
9464 * Return the package name of the currently bound GbaService.
9465 *
9466 * @param subId The sim that the GbaService is associated with.
9467 * @return the package name of the GbaService configuration, null if GBA is not supported.
9468 */
9469 @Override
9470 public String getBoundGbaService(int subId) {
9471 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 return getGbaManager(subId).getServicePackage();
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
9481 /**
9482 * Set the release time for telephony to unbind GbaService.
9483 *
9484 * @param subId The sim that the GbaService is associated with.
9485 * @param interval The release time to unbind GbaService by millisecond.
9486 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9487 */
9488 @Override
9489 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9490 enforceModifyPermission();
9491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 return getGbaManager(subId).overrideReleaseTime(interval);
9495 } finally {
9496 Binder.restoreCallingIdentity(identity);
9497 }
9498 }
9499
9500 /**
9501 * Return the release time for telephony to unbind GbaService.
9502 *
9503 * @param subId The sim that the GbaService is associated with.
9504 * @return The release time to unbind GbaService by millisecond.
9505 */
9506 @Override
9507 public int getGbaReleaseTime(int subId) {
9508 enforceReadPrivilegedPermission("getGbaReleaseTime");
9509
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 return getGbaManager(subId).getReleaseTime();
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
9517
9518 private GbaManager getGbaManager(int subId) {
9519 GbaManager instance = GbaManager.getInstance(subId);
9520 if (instance == null) {
9521 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9522 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9523 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9524 }
9525 return instance;
9526 }
Hui Wang068ab862020-10-31 05:12:53 +00009527
9528 /**
9529 * indicate whether the device and the carrier can support
9530 * RCS VoLTE single registration.
9531 */
9532 @Override
9533 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9534 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9535
9536 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9537 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9538 }
9539
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
9542 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9543 if (rpm != null) {
9544 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9545 }
9546 return false;
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
9552 /**
9553 * Register RCS provisioning callback.
9554 */
9555 @Override
9556 public void registerRcsProvisioningChangedCallback(int subId,
9557 IRcsConfigCallback callback) {
9558 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9559
9560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9561 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9562 }
9563 if (!isImsAvailableOnDevice()) {
9564 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9565 "IMS not available on device.");
9566 }
9567
9568 final long identity = Binder.clearCallingIdentity();
9569 try {
9570 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9571 .addRcsProvisioningCallbackForSubscription(callback, subId);
9572 } catch (ImsException e) {
9573 throw new ServiceSpecificException(e.getCode());
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 /**
9580 * Unregister RCS provisioning callback.
9581 */
9582 @Override
9583 public void unregisterRcsProvisioningChangedCallback(int subId,
9584 IRcsConfigCallback callback) {
9585 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9586
9587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9588 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9589 }
9590 if (!isImsAvailableOnDevice()) {
9591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9592 "IMS not available on device.");
9593 }
9594
9595 final long identity = Binder.clearCallingIdentity();
9596 try {
9597 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9598 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9599 } catch (ImsException e) {
9600 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9601 + "is inactive, ignoring unregister.");
9602 } finally {
9603 Binder.restoreCallingIdentity(identity);
9604 }
9605 }
9606
9607 /**
9608 * trigger RCS reconfiguration.
9609 */
9610 public void triggerRcsReconfiguration(int subId) {
9611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9612 mApp, subId, "triggerRcsReconfiguration");
9613
9614 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9615 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9616 }
9617 if (!isImsAvailableOnDevice()) {
9618 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9619 "IMS not available on device.");
9620 }
9621
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
9624 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
9628 }
9629
9630 /**
9631 * Provide the client configuration parameters of the RCS application.
9632 */
9633 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9635 mApp, subId, "setRcsClientConfiguration");
9636
9637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9638 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9639 }
9640 if (!isImsAvailableOnDevice()) {
9641 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9642 "IMS not available on device.");
9643 }
9644
9645 final long identity = Binder.clearCallingIdentity();
9646
9647 try {
9648 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9649 if (configBinder == null) {
9650 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9651 } else {
9652 configBinder.setRcsClientConfiguration(rcc);
9653 }
9654 } catch (RemoteException e) {
9655 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
9660
9661 /**
9662 * Overrides the config of RCS VoLTE single registration enabled for the device.
9663 */
9664 @Override
9665 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9667 "setDeviceSingleRegistrationEnabledOverride");
9668 enforceModifyPermission();
9669
9670 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9671 : Boolean.parseBoolean(enabledStr);
9672 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9673 }
9674
9675 /**
9676 * Gets the config of RCS VoLTE single registration enabled for the device.
9677 */
9678 @Override
9679 public boolean getDeviceSingleRegistrationEnabled() {
9680 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9681 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9682 }
9683
9684 /**
9685 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9686 */
9687 @Override
9688 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9689 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9690 "setCarrierSingleRegistrationEnabledOverride");
9691 enforceModifyPermission();
9692
9693 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9694 : Boolean.parseBoolean(enabledStr);
9695 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9696 subId, enabled);
9697 }
9698
9699 /**
9700 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9701 */
9702 @Override
9703 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9704 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9705 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9706 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009707
9708 /**
9709 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9710 * their mobile plan.
9711 */
9712 @Override
9713 public String getMobileProvisioningUrl() {
9714 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9715 final long identity = Binder.clearCallingIdentity();
9716 try {
9717 return getDefaultPhone().getMobileProvisioningUrl();
9718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
9721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009722}