blob: 482c3668fd132c7c5458b749a259dd4402c69cc5 [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)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003231 throw new SecurityException("Calling package must be configured in the device config: "
3232 + "calling package: " + callingPackage
3233 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003234 }
3235
3236 if (range == null) {
3237 throw new NullPointerException("Range must be non-null");
3238 }
3239
3240 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003241 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003242
3243 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3244 }
3245
Junda Liuca05d5d2014-08-14 22:36:34 -07003246 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003247 * Returns true if CDMA provisioning needs to run.
3248 */
3249 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003259 * Sets the voice mail number of a given subId.
3260 */
3261 @Override
3262 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003263 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3264 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3269 new Pair<String, String>(alphaTag, number), new Integer(subId));
3270 return success;
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003274 }
3275
Ta-wei Yen87c49842016-05-13 21:19:52 -07003276 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003277 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003279 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3280 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003281 if (!TextUtils.equals(callingPackage, systemDialer)) {
3282 throw new SecurityException("caller must be system dialer");
3283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3288 if (phoneAccountHandle == null) {
3289 return null;
3290 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003291 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003294 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003295 }
3296
3297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003298 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3299 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003300 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003302 mApp, subId, callingPackage, callingFeatureId,
3303 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003304 return null;
3305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003307 final long identity = Binder.clearCallingIdentity();
3308 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003313 }
3314
3315 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003316 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3317 VisualVoicemailSmsFilterSettings settings) {
3318 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003323 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003327 }
3328
3329 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003330 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003340 }
3341
3342 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003343 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3344 String callingPackage, int subId) {
3345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003350 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003354 }
3355
3356 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003357 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003367 }
3368
3369 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003370 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3371 String callingAttributionTag, int subId, String number, int port, String text,
3372 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003374 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003375 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003376 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003377 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3378 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003379 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003380
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003381 /**
fionaxu0152e512016-11-14 13:36:14 -08003382 * Sets the voice activation state of a given subId.
3383 */
3384 @Override
3385 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3387 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 if (phone != null) {
3393 phone.setVoiceActivationState(activationState);
3394 } else {
3395 loge("setVoiceActivationState fails with invalid subId: " + subId);
3396 }
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003399 }
3400 }
3401
3402 /**
3403 * Sets the data activation state of a given subId.
3404 */
3405 @Override
3406 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3408 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 final Phone phone = getPhone(subId);
3413 if (phone != null) {
3414 phone.setDataActivationState(activationState);
3415 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003416 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417 }
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003420 }
3421 }
3422
3423 /**
3424 * Returns the voice activation state of a given subId.
3425 */
3426 @Override
3427 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429
fionaxu0152e512016-11-14 13:36:14 -08003430 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 if (phone != null) {
3434 return phone.getVoiceActivationState();
3435 } else {
3436 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3437 }
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003440 }
3441 }
3442
3443 /**
3444 * Returns the data activation state of a given subId.
3445 */
3446 @Override
3447 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449
fionaxu0152e512016-11-14 13:36:14 -08003450 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 if (phone != null) {
3454 return phone.getDataActivationState();
3455 } else {
3456 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003460 }
3461 }
3462
3463 /**
Wink Saville36469e72014-06-11 15:17:00 -07003464 * Returns the unread count of voicemails for a subId
3465 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003466 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003467 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3468 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003470 mApp, subId, callingPackage, callingFeatureId,
3471 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003472 return 0;
3473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 final Phone phone = getPhone(subId);
3477 if (phone != null) {
3478 return phone.getVoiceMessageCount();
3479 } else {
3480 return 0;
3481 }
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003485 }
3486
3487 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003488 * returns true, if the device is in a state where both voice and data
3489 * are supported simultaneously. This can change based on location or network condition.
3490 */
3491 @Override
3492 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003500 }
3501
3502 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003503 * Send the dialer code if called from the current default dialer or the caller has
3504 * carrier privilege.
3505 * @param inputCode The dialer code to send
3506 */
3507 @Override
3508 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003511 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3512 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003513 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003514 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
fionaxu235cc5e2017-03-06 22:25:57 -08003524 }
3525
Pengquan Menga1bb6272018-09-06 09:59:22 -07003526 @Override
3527 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003528 TelephonyPermissions
3529 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3530 mApp, subId, "getNetworkSelectionMode");
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 if (!isActiveSubscription(subId)) {
3534 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3535 }
3536 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003540 }
3541
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003543 public boolean isInEmergencySmsMode() {
3544 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 for (Phone phone : PhoneFactory.getPhones()) {
3548 if (phone.isInEmergencySmsMode()) {
3549 return true;
3550 }
3551 }
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 return false;
3556 }
3557
shilu366312e2019-12-17 09:28:10 -08003558 /**
3559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3560 * @param subId The subscription to use to check the configuration.
3561 * @param c The callback that will be used to send the result.
3562 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003563 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003564 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3565 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003566 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3567 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003568
Brad Ebinger77b832e2019-10-17 17:03:22 -07003569 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3570 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3571 "IMS not available on device.");
3572 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 final long token = Binder.clearCallingIdentity();
3574 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003576 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003578 } catch (ImsException e) {
3579 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 } finally {
3581 Binder.restoreCallingIdentity(token);
3582 }
3583 }
3584
shilu366312e2019-12-17 09:28:10 -08003585 /**
3586 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3587 * @param subId The subscription to use to check the configuration.
3588 * @param c The callback that will be used to send the result.
3589 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003591 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003592 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3593 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3595 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3596 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003597 final long token = Binder.clearCallingIdentity();
3598 try {
3599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3600 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3601 .removeRegistrationCallbackForSubscription(c, subId);
3602 } catch (ImsException e) {
3603 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3604 + "is inactive, ignoring unregister.");
3605 // If the subscription is no longer active, just return, since the callback
3606 // will already have been removed internally.
3607 } finally {
3608 Binder.restoreCallingIdentity(token);
3609 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 }
3611
Brad Ebinger774ba362019-10-22 17:36:18 -07003612 /**
3613 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3614 */
3615 @Override
3616 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3617 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3618 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3619 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3620 "IMS not available on device.");
3621 }
3622 final long token = Binder.clearCallingIdentity();
3623 try {
3624 Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3627 + subId + "'");
3628 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3629 }
3630 phone.getImsRegistrationState(regState -> {
3631 try {
3632 consumer.accept((regState == null)
3633 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3634 } catch (RemoteException e) {
3635 // Ignore if the remote process is no longer available to call back.
3636 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3637 }
3638 });
3639 } finally {
3640 Binder.restoreCallingIdentity(token);
3641 }
3642 }
3643
3644 /**
3645 * Get the transport type for the IMS service registration state.
3646 */
3647 @Override
3648 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003649 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3650 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003651 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3652 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3653 "IMS not available on device.");
3654 }
3655 final long token = Binder.clearCallingIdentity();
3656 try {
3657 Phone phone = getPhone(subId);
3658 if (phone == null) {
3659 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3660 + subId + "'");
3661 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3662 }
3663 phone.getImsRegistrationTech(regTech -> {
3664 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3665 int regTechConverted = (regTech == null)
3666 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3667 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3668 regTechConverted);
3669 try {
3670 consumer.accept(regTechConverted);
3671 } catch (RemoteException e) {
3672 // Ignore if the remote process is no longer available to call back.
3673 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3674 }
3675 });
3676 } finally {
3677 Binder.restoreCallingIdentity(token);
3678 }
3679 }
3680
shilu366312e2019-12-17 09:28:10 -08003681 /**
3682 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3683 * @param subId The subscription to use to check the configuration.
3684 * @param c The callback that will be used to send the result.
3685 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003687 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3688 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003689 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3690 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003691 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3693 "IMS not available on device.");
3694 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3696 final long token = Binder.clearCallingIdentity();
3697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003698 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003700 } catch (ImsException e) {
3701 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 } finally {
3703 Binder.restoreCallingIdentity(token);
3704 }
3705 }
3706
shilu366312e2019-12-17 09:28:10 -08003707 /**
3708 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3709 * @param subId The subscription to use to check the configuration.
3710 * @param c The callback that will be used to send the result.
3711 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003713 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003714 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3715 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3718 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003719
3720 final long token = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003724 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003725 } catch (ImsException e) {
3726 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3727 + "is inactive, ignoring unregister.");
3728 // If the subscription is no longer active, just return, since the callback
3729 // will already have been removed internally.
3730 } finally {
3731 Binder.restoreCallingIdentity(token);
3732 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 }
3734
3735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003736 public boolean isCapable(int subId, int capability, int regTech) {
3737 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3739 final long token = Binder.clearCallingIdentity();
3740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3745 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003746 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003747 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3748 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
3752 }
3753
3754 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003755 public boolean isAvailable(int subId, int capability, int regTech) {
3756 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 final long token = Binder.clearCallingIdentity();
3758 try {
3759 Phone phone = getPhone(subId);
3760 if (phone == null) return false;
3761 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003762 } catch (com.android.ims.ImsException e) {
3763 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3764 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
3768 }
3769
Brad Ebinger77b832e2019-10-17 17:03:22 -07003770 /**
3771 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3772 * subscription.
3773 * @param subId The subscription to use to check the configuration.
3774 * @param callback The callback that will be used to send the result.
3775 * @param capability The MmTelFeature capability that will be used to send the result.
3776 * @param transportType The transport type of the MmTelFeature capability.
3777 */
3778 @Override
3779 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3780 int transportType) {
3781 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3782 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3783 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3784 "IMS not available on device.");
3785 }
3786 final long token = Binder.clearCallingIdentity();
3787 try {
3788 int slotId = getSlotIndex(subId);
3789 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3790 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3791 + subId + "'");
3792 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3793 }
3794 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3795 transportType, aBoolean -> {
3796 try {
3797 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3798 } catch (RemoteException e) {
3799 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3800 + "running. Ignore");
3801 }
3802 });
3803 } finally {
3804 Binder.restoreCallingIdentity(token);
3805 }
3806 }
3807
shilu366312e2019-12-17 09:28:10 -08003808 /**
3809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3810 * @param subId The subscription to use to check the configuration.
3811 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 @Override
3813 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003814 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3815 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003816
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3818 final long token = Binder.clearCallingIdentity();
3819 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003820 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003822 } catch (ImsException e) {
3823 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 } finally {
3825 Binder.restoreCallingIdentity(token);
3826 }
3827 }
3828
3829 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003830 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003832 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003836 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003838 } catch (ImsException e) {
3839 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
shilu366312e2019-12-17 09:28:10 -08003845 /**
3846 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3847 * @param subId The subscription to use to check the configuration.
3848 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003850 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003851 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3852 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003856 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3857 } catch (ImsException e) {
3858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
3864 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003865 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003867 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003872 } catch (ImsException e) {
3873 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 } finally {
3875 Binder.restoreCallingIdentity(identity);
3876 }
3877 }
3878
shilu366312e2019-12-17 09:28:10 -08003879 /**
3880 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3881 * @param subId The subscription to use to check the configuration.
3882 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 @Override
3884 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003885 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3886 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003890 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 } catch (ImsException e) {
3893 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
3897 }
3898
3899 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003900 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003902 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003907 } catch (ImsException e) {
3908 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
3912 }
3913
shilu366312e2019-12-17 09:28:10 -08003914 /**
3915 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3916 * @param subId The subscription to use to check the configuration.
3917 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 @Override
3919 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003920 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3921 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003925 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003927 } catch (ImsException e) {
3928 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
3932 }
3933
3934 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003935 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003937 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003941 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 }
3949
3950 @Override
3951 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3953 "setVoWiFiNonPersistent");
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003958 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (ImsException e) {
3960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
3964 }
3965
shilu366312e2019-12-17 09:28:10 -08003966 /**
3967 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3968 * @param subId The subscription to use to check the configuration.
3969 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 @Override
3971 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003972 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3973 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003979 } catch (ImsException e) {
3980 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
3984 }
3985
3986 @Override
3987 public void setVoWiFiModeSetting(int subId, int mode) {
3988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3989 "setVoWiFiModeSetting");
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
3996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
4000 }
4001
4002 @Override
4003 public int getVoWiFiRoamingModeSetting(int subId) {
4004 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004010 } catch (ImsException e) {
4011 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
4015 }
4016
4017 @Override
4018 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4020 "setVoWiFiRoamingModeSetting");
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004024 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004026 } catch (ImsException e) {
4027 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031 }
4032
4033 @Override
4034 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4036 "setRttCapabilityEnabled");
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
4046 }
4047
shilu366312e2019-12-17 09:28:10 -08004048 /**
4049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4050 * @param subId The subscription to use to check the configuration.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
4053 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4055 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004061 } catch (ImsException e) {
4062 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
4066 }
4067
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004068 @Override
4069 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4070 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004073 if (!isImsAvailableOnDevice()) {
4074 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4075 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004076 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004079 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
4085 }
4086
4087 @Override
4088 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4089 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4090 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004091 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4092 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4093 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004094 try {
4095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004097 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004098 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004099 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4100 + "is inactive, ignoring unregister.");
4101 // If the subscription is no longer active, just return, since the callback will already
4102 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
allenwtsu99c623b2020-01-03 18:24:23 +08004108
4109 private void checkModifyPhoneStatePermission(int subId, String message) {
4110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4111 message);
4112 }
4113
4114 private boolean isImsProvisioningRequired(int subId, int capability,
4115 boolean isMmtelCapability) {
4116 Phone phone = getPhone(subId);
4117 if (phone == null) {
4118 loge("phone instance null for subid " + subId);
4119 return false;
4120 }
4121 if (isMmtelCapability) {
4122 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4123 return false;
4124 }
4125 } else {
4126 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4127 return false;
4128 }
4129 }
4130 return true;
4131 }
4132
4133 @Override
4134 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4135 boolean isProvisioned) {
4136 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4141 if (!isImsProvisioningRequired(subId, capability, false)) {
4142 return;
4143 }
4144
4145 // this capability requires provisioning, route to the correct API.
4146 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4147 switch (capability) {
4148 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4149 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4150 ims.setEabProvisioned(isProvisioned);
4151 break;
4152 default: {
4153 throw new IllegalArgumentException("Tried to set provisioning for "
4154 + "rcs capability '" + capability + "', which does not require "
4155 + "provisioning.");
4156 }
4157 }
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161
4162 }
4163
4164
4165 @Override
4166 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4167 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4171 if (!isImsProvisioningRequired(subId, capability, false)) {
4172 return true;
4173 }
4174
4175 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4176 switch (capability) {
4177 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4178 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4179 return ims.isEabProvisionedOnDevice();
4180
4181 default: {
4182 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4183 + "capability '" + capability + "', which does not require "
4184 + "provisioning.");
4185 }
4186 }
4187
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4195 boolean isProvisioned) {
4196 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4197 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4198 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4199 }
allenwtsu99c623b2020-01-03 18:24:23 +08004200 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004204 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 return;
4206 }
4207
4208 // this capability requires provisioning, route to the correct API.
4209 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4210 switch (capability) {
4211 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4212 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4213 ims.setVolteProvisioned(isProvisioned);
4214 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4215 ims.setWfcProvisioned(isProvisioned);
4216 }
4217 break;
4218 }
4219 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4220 // There is currently no difference in VT provisioning type.
4221 ims.setVtProvisioned(isProvisioned);
4222 break;
4223 }
4224 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4225 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4226 // change the capability of the feature instead if needed.
4227 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4228 == isProvisioned) {
4229 // No change in provisioning.
4230 return;
4231 }
4232 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4233 try {
4234 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004235 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004236 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4237 + ", Exception" + e.getMessage());
4238 }
4239 break;
4240 }
4241 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004242 throw new IllegalArgumentException("Tried to set provisioning for "
4243 + "MmTel capability '" + capability + "', which does not require "
4244 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004245 }
4246 }
4247
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
4251 }
4252
4253 @Override
4254 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4255 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4256 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4257 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4258 }
4259 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004263 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 return true;
4265 }
4266
4267 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4268 switch (capability) {
4269 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4270 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4271 return ims.isVolteProvisionedOnDevice();
4272 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4273 return ims.isWfcProvisionedOnDevice();
4274 }
4275 // This should never happen, since we are checking tech above to make sure it
4276 // is either LTE or IWLAN.
4277 throw new IllegalArgumentException("Invalid radio technology for voice "
4278 + "capability.");
4279 }
4280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4281 // There is currently no difference in VT provisioning type.
4282 return ims.isVtProvisionedOnDevice();
4283 }
4284 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4285 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4286 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4287 }
4288 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004289 throw new IllegalArgumentException(
4290 "Tried to get provisioning for MmTel capability '" + capability
4291 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004292 }
4293 }
4294
4295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
4300 @Override
4301 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4302 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4303 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4304 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4305 }
4306 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4307 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4308 return (provisionedBits & capability) > 0;
4309 }
4310
4311 @Override
4312 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4313 boolean isProvisioned) {
4314 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4315 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4316 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4317 }
4318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4319 "setProvisioningStatusForCapability");
4320 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4321 // If the current provisioning status for capability already matches isProvisioned,
4322 // do nothing.
4323 if (((provisionedBits & capability) > 0) == isProvisioned) {
4324 return;
4325 }
4326 if (isProvisioned) {
4327 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4328 } else {
4329 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4330 }
4331 }
4332
4333 /**
4334 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4335 * technology. The bitfield should mirror the bitfield defined by
4336 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4337 */
4338 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4339 String key = getMmTelProvisioningKey(subId, tech);
4340 // Default is no capabilities are provisioned.
4341 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4342 }
4343
4344 /**
4345 * Sets the MmTel capability provisioning bitfield (defined by
4346 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4347 * technology specified.
4348 *
4349 * Note: This is a synchronous command and should not be called on UI thread.
4350 */
4351 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4352 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4353 String key = getMmTelProvisioningKey(subId, tech);
4354 editor.putInt(key, newField);
4355 editor.commit();
4356 }
4357
4358 private static String getMmTelProvisioningKey(int subId, int tech) {
4359 // resulting key is provision_ims_mmtel_{subId}_{tech}
4360 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4361 }
4362
4363 /**
4364 * Query CarrierConfig to see if the specified capability requires provisioning for the
4365 * carrier associated with the subscription id.
4366 */
4367 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4368 int capability) {
4369 CarrierConfigManager configManager = new CarrierConfigManager(context);
4370 PersistableBundle c = configManager.getConfigForSubId(subId);
4371 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004372 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4374 false);
4375 boolean requireVoiceVtProvisioning = c.getBoolean(
4376 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4377
4378 // First check to make sure that the capability requires provisioning.
4379 switch (capability) {
4380 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4381 // intentional fallthrough
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4383 if (requireVoiceVtProvisioning) {
4384 // Voice and Video requires provisioning
4385 return true;
4386 }
4387 break;
4388 }
4389 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4390 if (requireUtProvisioning) {
4391 // UT requires provisioning
4392 return true;
4393 }
4394 break;
4395 }
4396 }
4397 return false;
4398 }
4399
allenwtsu99c623b2020-01-03 18:24:23 +08004400 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4401 int capability) {
4402 CarrierConfigManager configManager = new CarrierConfigManager(context);
4403 PersistableBundle c = configManager.getConfigForSubId(subId);
4404
4405 boolean requireRcsProvisioning = c.getBoolean(
4406 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4407
4408 // First check to make sure that the capability requires provisioning.
4409 switch (capability) {
4410 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4411 // intentional fallthrough
4412 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4413 if (requireRcsProvisioning) {
4414 // OPTION or PRESENCE requires provisioning
4415 return true;
4416 }
4417 break;
4418 }
4419 }
4420 return false;
4421 }
4422
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004423 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004424 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4426 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4427 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004428 enforceReadPrivilegedPermission("getImsProvisioningInt");
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004432 int slotId = getSlotIndex(subId);
4433 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4434 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4435 + subId + "' for key:" + key);
4436 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4437 }
4438 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004439 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004440 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4441 + subId + "' for key:" + key);
4442 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
4449 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004450 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4451 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4452 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004453 enforceReadPrivilegedPermission("getImsProvisioningString");
4454 final long identity = Binder.clearCallingIdentity();
4455 try {
4456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004457 int slotId = getSlotIndex(subId);
4458 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4459 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4460 + subId + "' for key:" + key);
4461 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4462 }
4463 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004465 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4466 + subId + "' for key:" + key);
4467 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
4471 }
4472
4473 @Override
4474 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004475 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4476 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4477 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4479 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004483 int slotId = getSlotIndex(subId);
4484 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4485 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4486 + subId + "' for key:" + key);
4487 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4488 }
4489 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004491 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4492 + "' for key:" + key);
4493 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
4497 }
4498
4499 @Override
4500 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004501 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4502 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4503 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4505 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 final long identity = Binder.clearCallingIdentity();
4507 try {
4508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004509 int slotId = getSlotIndex(subId);
4510 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4511 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4512 + subId + "' for key:" + key);
4513 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4514 }
4515 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4518 + "' for key:" + key);
4519 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 int slotId = SubscriptionManager.getSlotIndex(subId);
4527 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4529 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 }
4531 return slotId;
4532 }
4533
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004534 private int getSlotIndex(int subId) {
4535 int slotId = SubscriptionManager.getSlotIndex(subId);
4536 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4537 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4538 }
4539 return slotId;
4540 }
4541
Wink Saville36469e72014-06-11 15:17:00 -07004542 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004543 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004544 */
4545 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004546 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4547 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004548 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004549 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004550 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004551 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004552 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004553 mApp, subId, callingPackage, callingFeatureId,
4554 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004555 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4556 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 final long identity = Binder.clearCallingIdentity();
4559 try {
4560 final Phone phone = getPhone(subId);
4561 if (phone != null) {
4562 return phone.getServiceState().getDataNetworkType();
4563 } else {
4564 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4565 }
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004569 }
4570
4571 /**
4572 * Returns the data network type
4573 */
4574 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004575 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4576 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4577 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004578 }
4579
4580 /**
4581 * Returns the data network type for a subId
4582 */
4583 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004584 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4585 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004587 mApp, subId, callingPackage, callingFeatureId,
4588 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004589 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4590 }
4591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 final Phone phone = getPhone(subId);
4595 if (phone != null) {
4596 return phone.getServiceState().getDataNetworkType();
4597 } else {
4598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4599 }
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004603 }
4604
4605 /**
Wink Saville36469e72014-06-11 15:17:00 -07004606 * Returns the Voice network type for a subId
4607 */
4608 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004609 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4610 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004612 mApp, subId, callingPackage, callingFeatureId,
4613 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004614 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4615 }
4616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 final Phone phone = getPhone(subId);
4620 if (phone != null) {
4621 return phone.getServiceState().getVoiceNetworkType();
4622 } else {
4623 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4624 }
4625 } finally {
4626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004628 }
4629
4630 /**
4631 * @return true if a ICC card is present
4632 */
4633 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004634 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004635 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4636 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004637 }
4638
4639 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004640 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004642 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004643 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 final Phone phone = PhoneFactory.getPhone(slotIndex);
4647 if (phone != null) {
4648 return phone.getIccCard().hasIccCard();
4649 } else {
4650 return false;
4651 }
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004655 }
4656
4657 /**
4658 * Return if the current radio is LTE on CDMA. This
4659 * is a tri-state return value as for a period of time
4660 * the mode may be unknown.
4661 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004662 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004663 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004664 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004665 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004666 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004667 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4668 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4669 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004670 }
4671
Sanket Padawe356d7632015-06-22 14:03:32 -07004672 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004673 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4674 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004675 try {
4676 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4677 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004678 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4679 }
4680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 final Phone phone = getPhone(subId);
4684 if (phone == null) {
4685 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4686 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004687 return TelephonyProperties.lte_on_cdma_device()
4688 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 }
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004692 }
Wink Saville36469e72014-06-11 15:17:00 -07004693 }
4694
Wink Saville36469e72014-06-11 15:17:00 -07004695 /**
4696 * {@hide}
4697 * Returns Default subId, 0 in the case of single standby.
4698 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004699 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004700 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004701 }
4702
Shishir Agrawala9f32182016-04-12 12:00:16 -07004703 private int getSlotForDefaultSubscription() {
4704 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4705 }
4706
Wink Savilleb564aae2014-10-23 10:18:09 -07004707 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004708 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004709 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004710
Pengquan Menge92a50d2018-09-21 15:54:48 -07004711 private boolean isActiveSubscription(int subId) {
4712 return mSubscriptionController.isActiveSubId(subId);
4713 }
4714
Ihab Awadf2177b72013-11-25 13:33:23 -08004715 /**
4716 * @see android.telephony.TelephonyManager.WifiCallingChoices
4717 */
4718 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004721 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4723 getWhenToMakeWifiCallsDefaultPreference());
4724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004727 }
4728
4729 /**
4730 * @see android.telephony.TelephonyManager.WifiCallingChoices
4731 */
4732 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004736 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
4740 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004741 }
4742
Sailesh Nepald1e68152013-12-12 19:08:02 -08004743 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004744 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004745 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004746 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004747
Jordan Liu4c733742019-02-28 12:03:40 -08004748 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4749 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4750 if (phoneId == -1) {
4751 throw new IllegalArgumentException("Given slot index: " + slotIndex
4752 + " does not correspond to an active phone");
4753 }
4754 return PhoneFactory.getPhone(phoneId);
4755 }
4756
Shishir Agrawal566b7612013-10-28 14:41:00 -07004757 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004758 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4759 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4761 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004763 if (DBG) {
4764 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4765 }
4766 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4767 p2);
4768 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004769
Jordan Liu4c733742019-02-28 12:03:40 -08004770
4771 @Override
4772 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4773 int slotIndex, String callingPackage, String aid, int p2) {
4774 enforceModifyPermission();
4775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4776 if (DBG) {
4777 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4778 }
4779 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4780 callingPackage, aid, p2);
4781 }
4782
4783 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4784 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 if (TextUtils.equals(ISDR_AID, aid)) {
4788 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004789 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4790 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 if (bestComponent == null
4792 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4793 loge("The calling package is not allowed to access ISD-R.");
4794 throw new SecurityException(
4795 "The calling package is not allowed to access ISD-R.");
4796 }
Derek Tan740e1672017-06-27 14:56:27 -07004797 }
Derek Tan740e1672017-06-27 14:56:27 -07004798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004800 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4801 null /* workSource */);
4802 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 return response;
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004807 }
4808
4809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004810 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004813 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4814 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004816
Jordan Liu4c733742019-02-28 12:03:40 -08004817 @Override
4818 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4819 enforceModifyPermission();
4820 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4821 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4822 channel);
4823 }
4824
4825 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 final long identity = Binder.clearCallingIdentity();
4827 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 if (channel < 0) {
4829 return false;
4830 }
Jordan Liu4c733742019-02-28 12:03:40 -08004831 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4832 null /* workSource */);
4833 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 return success;
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004838 }
4839
4840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004841 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004842 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4844 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004845 if (DBG) {
4846 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4847 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4848 + p3 + " data=" + data);
4849 }
4850 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4851 command, p1, p2, p3, data);
4852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004853
Jordan Liu4c733742019-02-28 12:03:40 -08004854 @Override
4855 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4856 int command, int p1, int p2, int p3, String data) {
4857 enforceModifyPermission();
4858 if (DBG) {
4859 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4860 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4861 + p3 + " data=" + data);
4862 }
4863 return iccTransmitApduLogicalChannelWithPermission(
4864 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4865 data);
4866 }
4867
4868 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4869 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004872 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 return "";
4874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004877 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4878 null /* workSource */);
4879 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 // Append the returned status code to the end of the response payload.
4882 String s = Integer.toHexString(
4883 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4884 if (response.payload != null) {
4885 s = IccUtils.bytesToHexString(response.payload) + s;
4886 }
4887 return s;
4888 } finally {
4889 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004890 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004891 }
Jake Hambye994d462014-02-03 13:10:13 -08004892
Evan Charltonc66da362014-05-16 14:06:40 -07004893 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004894 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4895 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4897 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004899 if (DBG) {
4900 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4901 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4902 }
4903 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4904 cla, command, p1, p2, p3, data);
4905 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004906
Jordan Liu4c733742019-02-28 12:03:40 -08004907 @Override
4908 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4909 int command, int p1, int p2, int p3, String data) {
4910 enforceModifyPermission();
4911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4912 if (DBG) {
4913 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4914 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4915 + " data=" + data);
4916 }
4917
4918 return iccTransmitApduBasicChannelWithPermission(
4919 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4920 p2, p3, data);
4921 }
4922
4923 // open APDU basic channel assuming the caller has sufficient permissions
4924 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4925 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4929 && TextUtils.equals(ISDR_AID, data)) {
4930 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4932 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 if (bestComponent == null
4934 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4935 loge("The calling package is not allowed to select ISD-R.");
4936 throw new SecurityException(
4937 "The calling package is not allowed to select ISD-R.");
4938 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004939 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004942 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4943 null /* workSource */);
4944 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 // Append the returned status code to the end of the response payload.
4947 String s = Integer.toHexString(
4948 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4949 if (response.payload != null) {
4950 s = IccUtils.bytesToHexString(response.payload) + s;
4951 }
4952 return s;
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004955 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004956 }
4957
4958 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004959 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004960 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4962 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 if (DBG) {
4967 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4968 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4969 }
4970
4971 IccIoResult response =
4972 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4973 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4974 subId);
4975
4976 if (DBG) {
4977 log("Exchange SIM_IO [R]" + response);
4978 }
4979
4980 byte[] result = null;
4981 int length = 2;
4982 if (response.payload != null) {
4983 length = 2 + response.payload.length;
4984 result = new byte[length];
4985 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4986 } else {
4987 result = new byte[length];
4988 }
4989
4990 result[length - 1] = (byte) response.sw2;
4991 result[length - 2] = (byte) response.sw1;
4992 return result;
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004995 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004996 }
4997
Nathan Haroldb3014052017-01-25 15:57:32 -08004998 /**
4999 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5000 * on a particular subscription
5001 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005002 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5003 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005005 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005006 return null;
5007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 if (appType != TelephonyManager.APPTYPE_USIM
5012 && appType != TelephonyManager.APPTYPE_SIM) {
5013 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5014 return null;
5015 }
5016 Object response = sendRequest(
5017 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5018 if (response instanceof String[]) {
5019 return (String[]) response;
5020 }
yincheng zhaod698b842019-09-06 17:06:54 -07005021 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005023 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005026 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005027 }
5028
yincheng zhaod698b842019-09-06 17:06:54 -07005029 /**
5030 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5031 * subscription.
5032 *
5033 * @param subId the id of the subscription.
5034 * @param appType the uicc app type, must be USIM or SIM.
5035 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5036 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005037 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005038 * @return number of fplmns that is successfully written to the SIM.
5039 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005040 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5041 String callingFeatureId) {
5042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5043 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005044 if (DBG) logv("no permissions for setForbiddenplmns");
5045 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5046 }
5047 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5048 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5049 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5050 }
5051 if (fplmns == null) {
5052 throw new IllegalArgumentException("Fplmn List provided is null");
5053 }
5054 for (String fplmn : fplmns) {
5055 if (!CellIdentity.isValidPlmn(fplmn)) {
5056 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5057 }
5058 }
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 Object response = sendRequest(
5062 CMD_SET_FORBIDDEN_PLMNS,
5063 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5064 subId);
5065 return (int) response;
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
5069 }
5070
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005072 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5074 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5079 if (response.payload == null) {
5080 return "";
5081 }
Evan Charltonc66da362014-05-16 14:06:40 -07005082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 // Append the returned status code to the end of the response payload.
5084 String s = Integer.toHexString(
5085 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5086 s = IccUtils.bytesToHexString(response.payload) + s;
5087 return s;
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
Evan Charltonc66da362014-05-16 14:06:40 -07005091 }
5092
Jake Hambye994d462014-02-03 13:10:13 -08005093 /**
5094 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5095 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5096 *
5097 * @param itemID the ID of the item to read
5098 * @return the NV item as a String, or null on error.
5099 */
5100 @Override
5101 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5104 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005109 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5111 return value;
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Jake Hambye994d462014-02-03 13:10:13 -08005115 }
5116
5117 /**
5118 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5119 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5120 *
5121 * @param itemID the ID of the item to read
5122 * @param itemValue the value to write, as a String
5123 * @return true on success; false on any failure
5124 */
5125 @Override
5126 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5129 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130
5131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5134 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005135 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5137 return success;
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Jake Hambye994d462014-02-03 13:10:13 -08005141 }
5142
5143 /**
5144 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5145 * Used for device configuration by some CDMA operators.
5146 *
5147 * @param preferredRoamingList byte array containing the new PRL
5148 * @return true on success; false on any failure
5149 */
5150 @Override
5151 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5153 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
5155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5158 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5159 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5160 return success;
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Jake Hambye994d462014-02-03 13:10:13 -08005164 }
5165
5166 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005167 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005168 * Used for device configuration by some CDMA operators.
5169 *
chen xu6dac5ab2018-10-26 17:39:23 -07005170 * @param slotIndex - device slot.
5171 *
Jake Hambye994d462014-02-03 13:10:13 -08005172 * @return true on success; false on any failure
5173 */
5174 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005175 public boolean resetModemConfig(int slotIndex) {
5176 Phone phone = PhoneFactory.getPhone(slotIndex);
5177 if (phone != null) {
5178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5179 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180
chen xu6dac5ab2018-10-26 17:39:23 -07005181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5184 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5185 return success;
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 }
chen xu6dac5ab2018-10-26 17:39:23 -07005190 return false;
5191 }
5192
5193 /**
5194 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5195 *
5196 * @param slotIndex - device slot.
5197 *
5198 * @return true on success; false on any failure
5199 */
5200 @Override
5201 public boolean rebootModem(int slotIndex) {
5202 Phone phone = PhoneFactory.getPhone(slotIndex);
5203 if (phone != null) {
5204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5205 mApp, phone.getSubId(), "rebootModem");
5206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5210 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5211 return success;
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005217 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005218
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005219 public String[] getPcscfAddress(String apnType, String callingPackage,
5220 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005221 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5223 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005224 return new String[0];
5225 }
5226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 final long identity = Binder.clearCallingIdentity();
5228 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005229 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Wink Saville36469e72014-06-11 15:17:00 -07005233 }
5234
Brad Ebinger51f743a2017-01-23 13:50:20 -08005235 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005236 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5237 * {@link #disableIms(int)}.
5238 * @param slotIndex device slot.
5239 */
5240 public void resetIms(int slotIndex) {
5241 enforceModifyPermission();
5242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 if (mImsResolver == null) {
5246 // may happen if the does not support IMS.
5247 return;
5248 }
5249 mImsResolver.disableIms(slotIndex);
5250 mImsResolver.enableIms(slotIndex);
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
5256 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005257 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5258 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005259 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005260 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005261 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005265 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005266 // may happen if the device does not support IMS.
5267 return;
5268 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005269 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005273 }
5274
5275 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005276 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5277 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005278 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005279 public void disableIms(int slotId) {
5280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281
5282 final long identity = Binder.clearCallingIdentity();
5283 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005284 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005285 // may happen if the device does not support IMS.
5286 return;
5287 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005288 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005292 }
5293
5294 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005295 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5296 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005297 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005298 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005299 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005300 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005304 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005305 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5306 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005307 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005308 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005312 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005313 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005314 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5315 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005316 @Override
5317 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005318 enforceModifyPermission();
5319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005323 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
5328
5329 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005330 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005331 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005332 */
5333 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5334 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335
5336 final long identity = Binder.clearCallingIdentity();
5337 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005338 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005339 // may happen if the device does not support IMS.
5340 return null;
5341 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005342 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005346 }
5347
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005348 /**
5349 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005350 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005351 */
5352 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005357 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005358 // may happen if the device does not support IMS.
5359 return null;
5360 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005361 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005365 }
5366
Brad Ebinger884c07b2018-02-15 16:17:40 -08005367 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005368 * Sets the ImsService Package Name that Telephony will bind to.
5369 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005370 * @param slotIndex the slot ID that the ImsService should bind for.
5371 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005372 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005373 * @param featureTypes An integer array of feature types associated with a packageName.
5374 * @param packageName The name of the package that the current configuration will be replaced
5375 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005376 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005377 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005378 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5379 int[] featureTypes, String packageName) {
5380 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5381 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5383 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005384 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005388 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005389 // may happen if the device does not support IMS.
5390 return false;
5391 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005392 Map<Integer, String> featureConfig = new HashMap<>();
5393 for (int featureType : featureTypes) {
5394 featureConfig.put(featureType, packageName);
5395 }
5396 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5397 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005401 }
5402
5403 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005404 * Clears any carrier ImsService overrides for the slot index specified that were previously
5405 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5406 *
5407 * This should only be used for testing.
5408 *
5409 * @param slotIndex the slot ID that the ImsService should bind for.
5410 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5411 */
5412 @Override
5413 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5414 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5415 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5416 "clearCarrierImsServiceOverride");
5417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5418 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5419 "clearCarrierImsServiceOverride");
5420
5421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 if (mImsResolver == null) {
5424 // may happen if the device does not support IMS.
5425 return false;
5426 }
5427 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
5430 }
5431 }
5432
5433 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005435 *
5436 * @param slotId The slot that the ImsService is associated with.
5437 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5438 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005439 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005440 * @return the package name of the ImsService configuration.
5441 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005442 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5443 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005444 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005445 TelephonyPermissions
5446 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5447 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5448 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005452 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005453 // may happen if the device does not support IMS.
5454 return "";
5455 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005456 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005457 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5458 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005462 }
5463
Brad Ebinger77b832e2019-10-17 17:03:22 -07005464 /**
5465 * Get the MmTelFeature state associated with the requested subscription id.
5466 * @param subId The subscription that the MmTelFeature is associated with.
5467 * @param callback A callback with an integer containing the
5468 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5469 */
5470 @Override
5471 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5472 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5473 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5474 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5475 "IMS not available on device.");
5476 }
5477 final long token = Binder.clearCallingIdentity();
5478 try {
5479 int slotId = getSlotIndex(subId);
5480 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5481 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5482 + subId + "'");
5483 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5484 }
5485 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5486 try {
5487 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5488 } catch (RemoteException e) {
5489 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5490 + "Ignore");
5491 }
5492 });
5493 } finally {
5494 Binder.restoreCallingIdentity(token);
5495 }
5496 }
5497
Wink Saville36469e72014-06-11 15:17:00 -07005498 public void setImsRegistrationState(boolean registered) {
5499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005503 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Wink Saville36469e72014-06-11 15:17:00 -07005507 }
5508
5509 /**
Stuart Scott54788802015-03-30 13:18:01 -07005510 * Set the network selection mode to automatic.
5511 *
5512 */
5513 @Override
5514 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5516 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
shilufc958392020-01-20 11:36:01 -08005520 if (!isActiveSubscription(subId)) {
5521 return;
5522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5524 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Stuart Scott54788802015-03-30 13:18:01 -07005528 }
5529
Jack Yud10cdd42020-09-28 20:28:01 -07005530 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005531 * Ask the radio to connect to the input network and change selection mode to manual.
5532 *
5533 * @param subId the id of the subscription.
5534 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5535 * the operator to attach to.
5536 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5537 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5538 * normal network selection next time.
5539 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005540 */
5541 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005542 public boolean setNetworkSelectionModeManual(
5543 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5545 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005546
5547 if (!isActiveSubscription(subId)) {
5548 return false;
5549 }
5550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 final long identity = Binder.clearCallingIdentity();
5552 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005553 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005555 if (DBG) {
5556 log("setNetworkSelectionModeManual: subId: " + subId
5557 + " operator: " + operatorInfo);
5558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005563 }
shilu84f6e8b2019-12-19 13:58:01 -08005564 /**
5565 * Get the manual network selection
5566 *
5567 * @param subId the id of the subscription.
5568 *
5569 * @return the previously saved user selected PLMN
5570 */
5571 @Override
5572 public String getManualNetworkSelectionPlmn(int subId) {
5573 TelephonyPermissions
5574 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5575 mApp, subId, "getManualNetworkSelectionPlmn");
5576
5577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (!isActiveSubscription(subId)) {
5580 return "";
5581 }
5582
5583 final Phone phone = getPhone(subId);
5584 if (phone == null) {
5585 return "";
5586 }
5587 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5588 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5589 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
5593 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005594
5595 /**
5596 * Scans for available networks.
5597 */
5598 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005599 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5600 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005603 LocationAccessPolicy.LocationPermissionResult locationResult =
5604 LocationAccessPolicy.checkLocationPermission(mApp,
5605 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5606 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005607 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005608 .setCallingPid(Binder.getCallingPid())
5609 .setCallingUid(Binder.getCallingUid())
5610 .setMethod("getCellNetworkScanResults")
5611 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5612 .build());
5613 switch (locationResult) {
5614 case DENIED_HARD:
5615 throw new SecurityException("Not allowed to access scan results -- location");
5616 case DENIED_SOFT:
5617 return null;
5618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619
Pengquan Menga1bb6272018-09-06 09:59:22 -07005620 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 try {
5622 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005623 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005628 }
5629
5630 /**
sqian80370722020-01-29 15:02:51 -08005631 * Get the call forwarding info, given the call forwarding reason.
5632 */
5633 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005634 public void getCallForwarding(int subId, int callForwardingReason,
5635 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005636 enforceReadPrivilegedPermission("getCallForwarding");
5637 long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) {
5640 log("getCallForwarding: subId " + subId
5641 + " callForwardingReason" + callForwardingReason);
5642 }
Hall Liua1acea22020-09-18 19:04:59 -07005643
5644 Phone phone = getPhone(subId);
5645 if (phone == null) {
5646 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005647 callback.onError(
5648 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005649 } catch (RemoteException e) {
5650 // ignore
5651 }
5652 return;
5653 }
5654
5655 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5656 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5657 @Override
5658 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5659 try {
5660 callback.onCallForwardingInfoAvailable(info);
5661 } catch (RemoteException e) {
5662 // ignore
5663 }
5664 }
5665
5666 @Override
5667 public void onError(int error) {
5668 try {
5669 callback.onError(error);
5670 } catch (RemoteException e) {
5671 // ignore
5672 }
5673 }
5674 });
5675 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680
5681 /**
5682 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5683 * reason, the number to forward, and the timeout before the forwarding is attempted.
5684 */
5685 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005686 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5687 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005688 enforceModifyPermission();
5689 long identity = Binder.clearCallingIdentity();
5690 try {
5691 if (DBG) {
5692 log("setCallForwarding: subId " + subId
5693 + " callForwardingInfo" + callForwardingInfo);
5694 }
Hall Liua1acea22020-09-18 19:04:59 -07005695
5696 Phone phone = getPhone(subId);
5697 if (phone == null) {
5698 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005699 callback.accept(
5700 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005701 } catch (RemoteException e) {
5702 // ignore
5703 }
5704 return;
5705 }
5706
5707 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5708 FunctionalUtils.ignoreRemoteException(callback::accept));
5709
5710 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715
5716 /**
Hall Liua1acea22020-09-18 19:04:59 -07005717 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005718 */
5719 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005720 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005721 enforceReadPrivilegedPermission("getCallForwarding");
5722 long identity = Binder.clearCallingIdentity();
5723 try {
Hall Liua1acea22020-09-18 19:04:59 -07005724
5725 Phone phone = getPhone(subId);
5726 if (phone == null) {
5727 try {
5728 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5729 } catch (RemoteException e) {
5730 // ignore
5731 }
5732 return;
5733 }
5734
5735 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5736
sqian80370722020-01-29 15:02:51 -08005737 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005738 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
5742 }
5743
5744 /**
Hall Liua1acea22020-09-18 19:04:59 -07005745 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005746 */
5747 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005748 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005749 enforceModifyPermission();
5750 long identity = Binder.clearCallingIdentity();
5751 try {
Hall Liua1acea22020-09-18 19:04:59 -07005752 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5753
5754 Phone phone = getPhone(subId);
5755 if (phone == null) {
5756 try {
5757 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5758 } catch (RemoteException e) {
5759 // ignore
5760 }
5761 return;
5762 }
5763
5764 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5765 FunctionalUtils.ignoreRemoteException(callback::accept));
5766
5767 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
5771 }
5772
5773 /**
yinxub1bed742017-04-17 11:45:04 -07005774 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005775 *
yinxub1bed742017-04-17 11:45:04 -07005776 * @param subId id of the subscription
5777 * @param request contains the radio access networks with bands/channels to scan
5778 * @param messenger callback messenger for scan results or errors
5779 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005780 * @return the id of the requested scan which can be used to stop the scan.
5781 */
5782 @Override
5783 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005784 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5786 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005787 LocationAccessPolicy.LocationPermissionResult locationResult =
5788 LocationAccessPolicy.checkLocationPermission(mApp,
5789 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5790 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005791 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005792 .setCallingPid(Binder.getCallingPid())
5793 .setCallingUid(Binder.getCallingUid())
5794 .setMethod("requestNetworkScan")
5795 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5796 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005797 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005798 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5799 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005800 if (e != null) {
5801 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5802 throw e;
5803 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005804 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005805 return TelephonyScanManager.INVALID_SCAN_ID;
5806 }
5807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 }
Hall Liu912dfd32019-04-25 14:02:26 -07005809 int callingUid = Binder.getCallingUid();
5810 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 return mNetworkScanRequestTracker.startNetworkScan(
5814 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005815 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
yinxu504e1392017-04-12 16:03:22 -07005819 }
5820
Hall Liub2ac8ef2019-02-28 15:56:23 -08005821 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005822 NetworkScanRequest request, int subId, String callingPackage) {
5823 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5825 boolean hasNetworkScanPermission =
5826 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5827 == PERMISSION_GRANTED;
5828
5829 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5830 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5831 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005832 }
5833
5834 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5835 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005836 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5837 return new SecurityException("Specific channels must not be"
5838 + " scanned without location access.");
5839 }
5840 }
5841 }
5842
Hall Liub2ac8ef2019-02-28 15:56:23 -08005843 return null;
5844 }
5845
yinxu504e1392017-04-12 16:03:22 -07005846 /**
5847 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005848 *
5849 * @param subId id of the subscription
5850 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005851 */
5852 @Override
5853 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5855 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
Hall Liu912dfd32019-04-25 14:02:26 -07005857 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 final long identity = Binder.clearCallingIdentity();
5859 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005860 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
yinxu504e1392017-04-12 16:03:22 -07005864 }
5865
5866 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005867 * Get the calculated preferred network type.
5868 * Used for debugging incorrect network type.
5869 *
5870 * @return the preferred network type, defined in RILConstants.java.
5871 */
5872 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005873 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005874 final Phone defaultPhone = getDefaultPhone();
5875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005876 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005877 return RILConstants.PREFERRED_NETWORK_MODE;
5878 }
5879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005883 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
Junda Liu84d15a22014-07-02 11:21:04 -07005887 }
5888
5889 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005890 * Get the preferred network type.
5891 * Used for device configuration by some CDMA operators.
5892 *
5893 * @return the preferred network type, defined in RILConstants.java.
5894 */
5895 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005896 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005897 TelephonyPermissions
5898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5899 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 if (DBG) log("getPreferredNetworkType");
5904 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5905 int networkType = (result != null ? result[0] : -1);
5906 if (DBG) log("getPreferredNetworkType: " + networkType);
5907 return networkType;
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005911 }
5912
5913 /**
5914 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005915 *
5916 * @param networkType the preferred network type, defined in RILConstants.java.
5917 * @return true on success; false on any failure.
5918 */
5919 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005920 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
calvinpan089c2a62020-03-12 14:17:55 +08005926 Boolean success = (Boolean) sendRequest(
5927 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005928
5929 if (success) {
5930 Settings.Global.putInt(mApp.getContentResolver(),
5931 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5932 }
calvinpan089c2a62020-03-12 14:17:55 +08005933 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5934 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 } finally {
5936 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005937 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005938 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005939
5940 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005941 * Get the allowed network types that store in the telephony provider.
5942 *
5943 * @param subId the id of the subscription.
5944 * @return allowedNetworkTypes the allowed network types.
5945 */
5946 @Override
5947 public long getAllowedNetworkTypes(int subId) {
5948 TelephonyPermissions
5949 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5950 mApp, subId, "getAllowedNetworkTypes");
5951
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 return SubscriptionManager.getLongSubscriptionProperty(
5955 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
5959 }
5960
5961 /**
5962 * Set the allowed network types.
5963 *
5964 * @param subId the id of the subscription.
5965 * @param allowedNetworkTypes the allowed network types.
5966 * @return true on success; false on any failure.
5967 */
5968 @Override
5969 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5971 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005972
calvinpan089c2a62020-03-12 14:17:55 +08005973 SubscriptionManager.setSubscriptionProperty(subId,
5974 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5975 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005976
calvinpan089c2a62020-03-12 14:17:55 +08005977 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5978 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5979 RILConstants.PREFERRED_NETWORK_MODE);
5980 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005981 }
5982
5983 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005984 * Get the allowed network types for certain reason.
5985 *
5986 * @param subId the id of the subscription.
5987 * @param reason the reason the allowed network type change is taking place
5988 * @return the allowed network types.
5989 */
5990 @Override
5991 public long getAllowedNetworkTypesForReason(int subId,
5992 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5993 TelephonyPermissions
5994 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5995 mApp, subId, "getAllowedNetworkTypesForReason");
5996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
6002 }
6003
6004 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006005 * Enable/Disable E-UTRA-NR Dual Connectivity
6006 * @param subId subscription id of the sim card
6007 * @param nrDualConnectivityState expected NR dual connectivity state
6008 * This can be passed following states
6009 * <ol>
6010 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6011 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6012 * <li>Disable NR dual connectivity and force secondary cell to be released
6013 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6014 * </ol>
6015 * @return operation result.
6016 */
6017 @Override
6018 public int setNrDualConnectivityState(int subId,
6019 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6021 mApp, subId, "enableNRDualConnectivity");
6022 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6026 nrDualConnectivityState, subId,
6027 workSource);
6028 if (DBG) log("enableNRDualConnectivity result: " + result);
6029 return result;
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
6033 }
6034
6035 /**
6036 * Is E-UTRA-NR Dual Connectivity enabled
6037 * @return true if dual connectivity is enabled else false
6038 */
6039 @Override
6040 public boolean isNrDualConnectivityEnabled(int subId) {
6041 TelephonyPermissions
6042 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6043 mApp, subId, "isNRDualConnectivityEnabled");
6044 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6048 null, subId, workSource);
6049 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6050 return isEnabled;
6051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
6054 }
6055
6056 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006057 * get carrier bandwidth per primary and secondary carrier
6058 * @param subId subscription id of the sim card
6059 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6060 */
6061 @Override
6062 public CarrierBandwidth getCarrierBandwidth(int subId) {
6063 TelephonyPermissions
6064 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6065 mApp, subId, "isNRDualConnectivityEnabled");
6066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 CarrierBandwidth carrierBandwidth =
6070 getPhoneFromSubId(subId).getCarrierBandwidth();
6071 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6072 return carrierBandwidth;
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
6076 }
6077
6078 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006079 * Get the effective allowed network types on the device.
6080 * This API will return an intersection of allowed network types for all reasons,
6081 * including the configuration done through setAllowedNetworkTypes
6082 *
6083 * @param subId the id of the subscription.
6084 * @return the allowed network types
6085 */
6086 @Override
6087 public long getEffectiveAllowedNetworkTypes(int subId) {
6088 TelephonyPermissions
6089 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6090 mApp, subId, "getEffectiveAllowedNetworkTypes");
6091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
6097 }
6098
6099 /**
6100 * Set the allowed network types of the device and
6101 * provide the reason triggering the allowed network change.
6102 *
6103 * @param subId the id of the subscription.
6104 * @param reason the reason the allowed network type change is taking place
6105 * @param allowedNetworkTypes the allowed network types.
6106 * @return true on success; false on any failure.
6107 */
6108 @Override
6109 public boolean setAllowedNetworkTypesForReason(int subId,
6110 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6112 mApp, subId, "setAllowedNetworkTypesForReason");
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6116 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6117 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6118 RILConstants.PREFERRED_NETWORK_MODE);
6119 return setPreferredNetworkType(subId, preferredNetworkMode);
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
6123 }
6124
6125 /**
Miaoa84611c2019-03-15 09:21:10 +08006126 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006127 *
Miaoa84611c2019-03-15 09:21:10 +08006128 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006129 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006130 * @hide
6131 */
6132 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006133 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006136 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 try {
Miaoa84611c2019-03-15 09:21:10 +08006138 if (phone != null) {
6139 return phone.hasMatchedTetherApnSetting();
6140 } else {
6141 return false;
6142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006145 }
Junda Liu475951f2014-11-07 16:45:03 -08006146 }
6147
6148 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006149 * Enable or disable always reporting signal strength changes from radio.
6150 *
6151 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6152 */
6153 @Override
6154 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6155 enforceModifyPermission();
6156 enforceSystemCaller();
6157
6158 final long identity = Binder.clearCallingIdentity();
6159 final Phone phone = getPhone(subId);
6160 try {
6161 if (phone != null) {
6162 if (DBG) {
6163 log("setAlwaysReportSignalStrength: subId=" + subId
6164 + " isEnable=" + isEnable);
6165 }
6166 phone.setAlwaysReportSignalStrength(isEnable);
6167 } else {
6168 loge("setAlwaysReportSignalStrength: no phone found for subId="
6169 + subId);
6170 }
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
6174 }
6175
6176 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006177 * Get the user enabled state of Mobile Data.
6178 *
6179 * TODO: remove and use isUserDataEnabled.
6180 * This can't be removed now because some vendor codes
6181 * calls through ITelephony directly while they should
6182 * use TelephonyManager.
6183 *
6184 * @return true on enabled
6185 */
6186 @Override
6187 public boolean getDataEnabled(int subId) {
6188 return isUserDataEnabled(subId);
6189 }
6190
6191 /**
6192 * Get whether mobile data is enabled per user setting.
6193 *
6194 * There are other factors deciding whether mobile data is actually enabled, but they are
6195 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006196 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006197 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006198 *
6199 * @return {@code true} if data is enabled else {@code false}
6200 */
6201 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006202 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006203 try {
6204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6205 null);
6206 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6208 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210
6211 final long identity = Binder.clearCallingIdentity();
6212 try {
6213 int phoneId = mSubscriptionController.getPhoneId(subId);
6214 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6215 Phone phone = PhoneFactory.getPhone(phoneId);
6216 if (phone != null) {
6217 boolean retVal = phone.isUserDataEnabled();
6218 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6219 return retVal;
6220 } else {
6221 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6222 return false;
6223 }
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006226 }
6227 }
6228
6229 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006230 * Checks if the device is capable of mobile data by considering whether whether the
6231 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6232 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006233 *
Shuo Qian985d1232020-01-08 14:30:06 -08006234 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006235 */
6236 @Override
6237 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006238 try {
6239 try {
6240 mApp.enforceCallingOrSelfPermission(
6241 android.Manifest.permission.ACCESS_NETWORK_STATE,
6242 null);
6243 } catch (Exception e) {
6244 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6245 "isDataEnabled");
6246 }
6247 } catch (Exception e) {
6248 enforceReadPrivilegedPermission("isDataEnabled");
6249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 int phoneId = mSubscriptionController.getPhoneId(subId);
6254 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6255 Phone phone = PhoneFactory.getPhone(phoneId);
6256 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006257 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6259 return retVal;
6260 } else {
6261 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6262 return false;
6263 }
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006266 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006267 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006268
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006269 /**
6270 * Check if data is enabled for a specific reason
6271 * @param subId Subscription index
6272 * @param reason the reason the data enable change is taking place
6273 * @return {@code true} if the overall data is enabled; {@code false} if not.
6274 */
6275 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006276 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006277 @TelephonyManager.DataEnabledReason int reason) {
6278 try {
6279 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6280 null);
6281 } catch (Exception e) {
6282 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006283 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006284 }
6285
6286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
6289 int phoneId = mSubscriptionController.getPhoneId(subId);
6290 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006291 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006292 + " reason=" + reason);
6293 }
6294 Phone phone = PhoneFactory.getPhone(phoneId);
6295 if (phone != null) {
6296 boolean retVal;
6297 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6298 retVal = phone.isUserDataEnabled();
6299 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006300 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006301 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006302 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006303 return retVal;
6304 } else {
6305 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006306 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006307 + subId + " retVal=false");
6308 }
6309 return false;
6310 }
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
6314 }
6315
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006316 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006317 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006318 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6319 // Skip the check if it's one of these special uids
6320 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6321 }
6322
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006323 //load access rules from carrier configs, and check those as well: b/139133814
6324 SubscriptionController subController = SubscriptionController.getInstance();
6325 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6326 || subController == null) return privilegeFromSim;
6327
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006328 PackageManager pkgMgr = phone.getContext().getPackageManager();
6329 String[] packages = pkgMgr.getPackagesForUid(uid);
6330
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006333 int subId = phone.getSubId();
6334 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6335 // A test override is in place for the privileges for this subId, so don't try to
6336 // read the subscription privileges.
6337 return privilegeFromSim;
6338 }
6339 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006340 SubscriptionManager subManager = (SubscriptionManager)
6341 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6342 for (String pkg : packages) {
6343 if (subManager.canManageSubscription(subInfo, pkg)) {
6344 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6345 }
6346 }
6347 return privilegeFromSim;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
6351 }
6352
6353 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6354 String pkgName) {
6355 //load access rules from carrier configs, and check those as well: b/139133814
6356 SubscriptionController subController = SubscriptionController.getInstance();
6357 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6358 || subController == null) return privilegeFromSim;
6359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006362 int subId = phone.getSubId();
6363 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6364 // A test override is in place for the privileges for this subId, so don't try to
6365 // read the subscription privileges.
6366 return privilegeFromSim;
6367 }
6368 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006369 SubscriptionManager subManager = (SubscriptionManager)
6370 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6371 return subManager.canManageSubscription(subInfo, pkgName)
6372 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
6376 }
6377
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006378 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006379 public int getCarrierPrivilegeStatus(int subId) {
6380 final Phone phone = getPhone(subId);
6381 if (phone == null) {
6382 loge("getCarrierPrivilegeStatus: Invalid subId");
6383 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6384 }
6385 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006386 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006387 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006388 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6389 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006390
6391 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6392 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006393 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006394 }
Junda Liu29340342014-07-10 15:23:27 -07006395
6396 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006398 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006399 final Phone phone = getPhone(subId);
6400 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006401 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006402 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6403 }
6404 UiccProfile profile =
6405 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6406 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006407 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006408 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6409 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006410 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006411 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006412 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 }
6414
6415 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006416 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6417 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006418 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006419 }
6420
6421 int phoneId = SubscriptionManager.getPhoneId(subId);
6422 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006423 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006424 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006425 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6426 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006427 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6428 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6429 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006430 }
6431
6432 @Override
6433 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006434 if (TextUtils.isEmpty(pkgName))
6435 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006436 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6437 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6438 UiccCard card = UiccController.getInstance().getUiccCard(i);
6439 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006440 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006441 continue;
6442 }
6443
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006444 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6445 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6446 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006447 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6448 break;
6449 }
6450 }
6451
6452 return result;
Junda Liu29340342014-07-10 15:23:27 -07006453 }
Derek Tan89e89d42014-07-08 17:00:10 -07006454
6455 @Override
Junda Liue64de782015-04-16 17:19:16 -07006456 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6457 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6458 loge("phoneId " + phoneId + " is not valid.");
6459 return null;
6460 }
6461 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006462 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006463 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006464 return null ;
6465 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006466 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006467 }
6468
Amith Yamasani6e118872016-02-19 12:53:51 -08006469 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006470 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006471 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006472 List<String> privilegedPackages = new ArrayList<>();
6473 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006474 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6475 // has UICC in that slot.
6476 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006477 if (card.hasCarrierPrivilegeRules()) {
6478 if (packages == null) {
6479 // Only check packages in user 0 for now
6480 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006481 PackageManager.MATCH_DISABLED_COMPONENTS
6482 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006483 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006484 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006485 }
6486 for (int p = packages.size() - 1; p >= 0; p--) {
6487 PackageInfo pkgInfo = packages.get(p);
6488 if (pkgInfo != null && pkgInfo.packageName != null
6489 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006490 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006491 privilegedPackages.add(pkgInfo.packageName);
6492 }
6493 }
6494 }
6495 }
6496 return privilegedPackages;
6497 }
6498
chen xuf7e9fe82019-05-09 19:31:02 -07006499 @Override
6500 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006501 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6502
6503 final long identity = Binder.clearCallingIdentity();
6504
chen xuf7e9fe82019-05-09 19:31:02 -07006505 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006506 try {
6507 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6508 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6509 }
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006512 }
6513 return privilegedPackages;
6514 }
6515
Wink Savilleb564aae2014-10-23 10:18:09 -07006516 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006517 final Phone phone = getPhone(subId);
6518 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006519 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006520 return null;
6521 }
6522 String iccId = card.getIccId();
6523 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006524 return null;
6525 }
6526 return iccId;
6527 }
6528
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006529 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006530 public void setCallComposerStatus(int subId, int status) {
6531 enforceModifyPermission();
6532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 Phone phone = getPhone(subId);
6536 if (phone != null) {
6537 Phone defaultPhone = phone.getImsPhone();
6538 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6539 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6540 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006541 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6542 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006543 }
6544 }
Shuo Qiand8782462020-12-22 19:10:14 -08006545 } catch (ImsException e) {
6546 throw new ServiceSpecificException(e.getCode());
6547 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006548 Binder.restoreCallingIdentity(identity);
6549 }
6550 }
6551
6552 @Override
6553 public int getCallComposerStatus(int subId) {
6554 enforceReadPrivilegedPermission("getCallComposerStatus");
6555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 Phone phone = getPhone(subId);
6559 if (phone != null) {
6560 Phone defaultPhone = phone.getImsPhone();
6561 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6562 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6563 return imsPhone.getCallComposerStatus();
6564 }
6565 }
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
6569 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6570 }
6571
6572 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006573 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6574 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006576 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 final String iccId = getIccId(subId);
6581 final Phone phone = getPhone(subId);
6582 if (phone == null) {
6583 return false;
6584 }
6585 final String subscriberId = phone.getSubscriberId();
6586
6587 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006588 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 + subscriberId + " to " + number);
6590 }
6591
6592 if (TextUtils.isEmpty(iccId)) {
6593 return false;
6594 }
6595
6596 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6597
6598 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6599 if (alphaTag == null) {
6600 editor.remove(alphaTagPrefKey);
6601 } else {
6602 editor.putString(alphaTagPrefKey, alphaTag);
6603 }
6604
6605 // Record both the line number and IMSI for this ICCID, since we need to
6606 // track all merged IMSIs based on line number
6607 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6608 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6609 if (number == null) {
6610 editor.remove(numberPrefKey);
6611 editor.remove(subscriberPrefKey);
6612 } else {
6613 editor.putString(numberPrefKey, number);
6614 editor.putString(subscriberPrefKey, subscriberId);
6615 }
6616
6617 editor.commit();
6618 return true;
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006621 }
Derek Tan7226c842014-07-02 17:42:23 -07006622 }
6623
6624 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006625 public String getLine1NumberForDisplay(int subId, String callingPackage,
6626 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006627 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006630 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006631 return null;
6632 }
Derek Tan97ebb422014-09-05 16:55:38 -07006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 String iccId = getIccId(subId);
6637 if (iccId != null) {
6638 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6639 if (DBG_MERGE) {
6640 log("getLine1NumberForDisplay returning "
6641 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6642 }
6643 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6646 return null;
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006649 }
Derek Tan7226c842014-07-02 17:42:23 -07006650 }
6651
6652 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006653 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6654 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006656 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006657 return null;
6658 }
Derek Tan97ebb422014-09-05 16:55:38 -07006659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 String iccId = getIccId(subId);
6663 if (iccId != null) {
6664 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6665 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6666 }
6667 return null;
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006670 }
Derek Tan7226c842014-07-02 17:42:23 -07006671 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006672
6673 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006674 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6675 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006676 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6677 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006679 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006680 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006681 return null;
6682 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006683
Jordan Liub49b04b2019-05-06 14:45:15 -07006684 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6685 // the process, where TelephonyManager was instantiated.
6686 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006687 final long identity = Binder.clearCallingIdentity();
6688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006689 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 final TelephonyManager tele = TelephonyManager.from(context);
6691 final SubscriptionManager sub = SubscriptionManager.from(context);
6692
6693 // Figure out what subscribers are currently active
6694 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695
Jordan Liub49b04b2019-05-06 14:45:15 -07006696 // Only consider subs which match the current subId
6697 // This logic can be simplified. See b/131189269 for progress.
6698 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006699 activeSubscriberIds.add(tele.getSubscriberId(subId));
6700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701
6702 // First pass, find a number override for an active subscriber
6703 String mergeNumber = null;
6704 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6705 for (String key : prefs.keySet()) {
6706 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6707 final String subscriberId = (String) prefs.get(key);
6708 if (activeSubscriberIds.contains(subscriberId)) {
6709 final String iccId = key.substring(
6710 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6711 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6712 mergeNumber = (String) prefs.get(numberKey);
6713 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006714 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 + " for active subscriber " + subscriberId);
6716 }
6717 if (!TextUtils.isEmpty(mergeNumber)) {
6718 break;
6719 }
6720 }
6721 }
6722 }
6723
6724 // Shortcut when no active merged subscribers
6725 if (TextUtils.isEmpty(mergeNumber)) {
6726 return null;
6727 }
6728
6729 // Second pass, find all subscribers under that line override
6730 final ArraySet<String> result = new ArraySet<>();
6731 for (String key : prefs.keySet()) {
6732 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6733 final String number = (String) prefs.get(key);
6734 if (mergeNumber.equals(number)) {
6735 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6736 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6737 final String subscriberId = (String) prefs.get(subscriberKey);
6738 if (!TextUtils.isEmpty(subscriberId)) {
6739 result.add(subscriberId);
6740 }
6741 }
6742 }
6743 }
6744
6745 final String[] resultArray = result.toArray(new String[result.size()]);
6746 Arrays.sort(resultArray);
6747 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006748 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6750 }
6751 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006752 } finally {
6753 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006754 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006755 }
6756
6757 @Override
zoey chen38003472019-12-13 17:16:31 +08006758 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6759 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 final TelephonyManager telephonyManager = mApp.getSystemService(
6764 TelephonyManager.class);
6765 String subscriberId = telephonyManager.getSubscriberId(subId);
6766 if (subscriberId == null) {
6767 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006768 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006769 + subId);
6770 }
6771 return null;
6772 }
6773
6774 final SubscriptionInfo info = SubscriptionController.getInstance()
6775 .getSubscriptionInfo(subId);
6776 final ParcelUuid groupUuid = info.getGroupUuid();
6777 // If it doesn't belong to any group, return just subscriberId of itself.
6778 if (groupUuid == null) {
6779 return new String[]{subscriberId};
6780 }
6781
6782 // Get all subscriberIds from the group.
6783 final List<String> mergedSubscriberIds = new ArrayList<>();
6784 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006785 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006786 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006787 for (SubscriptionInfo subInfo : groupInfos) {
6788 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6789 if (subscriberId != null) {
6790 mergedSubscriberIds.add(subscriberId);
6791 }
6792 }
6793
6794 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797
6798 }
6799 }
6800
6801 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006802 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006803 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006804 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 final Phone phone = getPhone(subId);
6809 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006813 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006814
6815 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006816 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006817 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6818 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6820 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 final Phone phone = getPhone(subId);
6825 if (phone == null) {
6826 return false;
6827 }
6828 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6829 cdmaNonRoamingList);
6830 } finally {
6831 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006832 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006833 }
6834
6835 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006836 @Deprecated
6837 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6838 enforceModifyPermission();
6839
6840 int returnValue = 0;
6841 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006842 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006843 if(result.exception == null) {
6844 if (result.result != null) {
6845 byte[] responseData = (byte[])(result.result);
6846 if(responseData.length > oemResp.length) {
6847 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6848 responseData.length + "bytes. Buffer Size is " +
6849 oemResp.length + "bytes.");
6850 }
6851 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6852 returnValue = responseData.length;
6853 }
6854 } else {
6855 CommandException ex = (CommandException) result.exception;
6856 returnValue = ex.getCommandError().ordinal();
6857 if(returnValue > 0) returnValue *= -1;
6858 }
6859 } catch (RuntimeException e) {
6860 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6861 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6862 if(returnValue > 0) returnValue *= -1;
6863 }
6864
6865 return returnValue;
6866 }
6867
6868 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006869 public void setRadioCapability(RadioAccessFamily[] rafs) {
6870 try {
6871 ProxyController.getInstance().setRadioCapability(rafs);
6872 } catch (RuntimeException e) {
6873 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6874 }
6875 }
6876
6877 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006878 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006879 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006880 try {
6881 TelephonyPermissions
6882 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6883 mApp, phone.getSubId(), "getRadioAccessFamily");
6884 } catch (SecurityException e) {
6885 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6886 throw e;
6887 }
chen xub97461a2018-10-26 14:17:57 -07006888 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006889 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006890 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 final long identity = Binder.clearCallingIdentity();
6893 try {
chen xub97461a2018-10-26 14:17:57 -07006894 TelephonyPermissions
6895 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6896 mApp, phone.getSubId(), "getRadioAccessFamily");
6897 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 } finally {
6899 Binder.restoreCallingIdentity(identity);
6900 }
chen xub97461a2018-10-26 14:17:57 -07006901 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006902 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006903
6904 @Override
6905 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006906 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006911 ImsManager.getInstance(defaultPhone.getContext(),
6912 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006916 }
6917
6918 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006919 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006920 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6922 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006923 return false;
6924 }
Svet Ganovb320e182015-04-16 12:30:10 -07006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 // Check the user preference and the system-level IMS setting. Even if the user has
6929 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6930 // In the long run, we may instead need to check if there exists a connection service
6931 // which can support video calling.
6932 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006933 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 return imsManager.isVtEnabledByPlatform()
6935 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6936 && imsManager.isVtEnabledByUser();
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006940 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006941
Andrew Leea1239f22015-03-02 17:44:07 -08006942 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006943 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6944 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006946 mApp, subId, callingPackage, callingFeatureId,
6947 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 return false;
6949 }
6950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 CarrierConfigManager configManager =
6954 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006955 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
Andrew Leea1239f22015-03-02 17:44:07 -08006960 }
6961
6962 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006963 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006965 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 return false;
6967 }
6968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 CarrierConfigManager configManager =
6972 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006973 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
Andrew Leea1239f22015-03-02 17:44:07 -08006978 }
6979
Andrew Lee9431b832015-03-09 18:46:45 -07006980 @Override
6981 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006982 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006983 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006984 }
6985
6986 @Override
6987 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 } finally {
6992 Binder.restoreCallingIdentity(identity);
6993 }
Andrew Lee9431b832015-03-09 18:46:45 -07006994 }
6995
Hall Liuf6668912018-10-31 17:05:23 -07006996 /**
6997 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6998 * support for the feature and device firmware support.
6999 *
7000 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7001 */
7002 @Override
7003 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007005 final Phone phone = getPhone(subscriptionId);
7006 if (phone == null) {
7007 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7008 return false;
7009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7013 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007014 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 return isCarrierSupported && isDeviceSupported;
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
Hall Liu98187582018-01-22 19:15:32 -08007019 }
7020
Hall Liuf6668912018-10-31 17:05:23 -07007021 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007022 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7023 * RTT setting, will return true if the device and carrier both support RTT.
7024 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007025 */
7026 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007029 boolean isRttSupported = isRttSupported(subscriptionId);
7030 boolean isUserRttSettingOn = Settings.Secure.getInt(
7031 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7032 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7033 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7034 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007038 }
7039
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007040 @Deprecated
7041 @Override
7042 public String getDeviceId(String callingPackage) {
7043 return getDeviceIdWithFeature(callingPackage, null);
7044 }
7045
Sanket Padawe7310cc72015-01-14 09:53:20 -08007046 /**
7047 * Returns the unique device ID of phone, for example, the IMEI for
7048 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7049 *
7050 * <p>Requires Permission:
7051 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7052 */
7053 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007054 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007055 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007056 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007057 return null;
7058 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007059 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007060 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007061 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007062 return null;
7063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 return phone.getDeviceId();
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007071 }
7072
Ping Sunc67b7c22016-03-02 19:16:45 +08007073 /**
7074 * {@hide}
7075 * Returns the IMS Registration Status on a particular subid
7076 *
7077 * @param subId
7078 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007079 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007080 Phone phone = getPhone(subId);
7081 if (phone != null) {
7082 return phone.isImsRegistered();
7083 } else {
7084 return false;
7085 }
7086 }
7087
Santos Cordon7a1885b2015-02-03 11:15:19 -08007088 @Override
7089 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
7095 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007096 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007097
Tyler Gunnf70ed162019-04-03 15:28:53 -07007098 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007099 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007100 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007102 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007103 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7104 }
7105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110 }
7111 }
7112
7113 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007114 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007115 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7116 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007117 final long identity = Binder.clearCallingIdentity();
7118 try {
7119 Phone phone = getPhone(subscriptionId);
7120 if (phone == null) {
7121 return null;
7122 }
7123 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 }
7128
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007129 /**
7130 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007131 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007132 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 Phone phone = getPhone(subId);
7136 if (phone != null) {
7137 return phone.isWifiCallingEnabled();
7138 } else {
7139 return false;
7140 }
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007143 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007144 }
7145
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007146 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007147 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007149 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 Phone phone = getPhone(subId);
7153 if (phone != null) {
7154 return phone.isVideoEnabled();
7155 } else {
7156 return false;
7157 }
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007160 }
7161 }
7162
7163 /**
7164 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7165 * defined in {@link ImsRegistrationImplBase}.
7166 */
7167 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 Phone phone = getPhone(subId);
7171 if (phone != null) {
7172 return phone.getImsRegistrationTech();
7173 } else {
7174 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7175 }
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007178 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007179 }
7180
Stuart Scott8eef64f2015-04-08 15:13:54 -07007181 @Override
7182 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007183 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007184 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7185 return;
7186 }
7187
Svet Ganovcc087f82015-05-12 20:35:54 -07007188 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007189
Svet Ganovcc087f82015-05-12 20:35:54 -07007190 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007191 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7192 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007193 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007194 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007195 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007196 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007197 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7198 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007199 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007200 // There has been issues when Sms raw table somehow stores orphan
7201 // fragments. They lead to garbled message when new fragments come
7202 // in and combined with those stale ones. In case this happens again,
7203 // user can reset all network settings which will clean up this table.
7204 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007205 // Clean up IMS settings as well here.
7206 int slotId = getSlotIndex(subId);
7207 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7208 ImsManager.getInstance(mApp, slotId).factoryReset();
7209 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007210
7211 // Erase modem config if erase modem on network setting is enabled.
7212 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7213 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7214 if (configValue != null && Boolean.parseBoolean(configValue)) {
7215 sendEraseModemConfig(getDefaultPhone());
7216 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007217 } finally {
7218 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007219 }
7220 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007221
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007222 private void cleanUpSmsRawTable(Context context) {
7223 ContentResolver resolver = context.getContentResolver();
7224 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7225 resolver.delete(uri, null, null);
7226 }
7227
Narayan Kamath1c496c22015-04-16 14:40:19 +01007228 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007229 public String getSimLocaleForSubscriber(int subId) {
7230 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7231 final Phone phone = getPhone(subId);
7232 if (phone == null) {
7233 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007234 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
chen xu5d3637b2019-01-21 23:31:38 -08007238 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007239 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007240 if (info == null) {
7241 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7242 return null;
7243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 // Try and fetch the locale from the carrier properties or from the SIM language
7245 // preferences (EF-PL and EF-LI)...
7246 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007248 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7249 if (localeFromDefaultSim != null) {
7250 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7251 if (DBG) log("Using locale from subId: " + subId + " locale: "
7252 + localeFromDefaultSim);
7253 return localeFromDefaultSim.toLanguageTag();
7254 } else {
7255 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 }
7257 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 // The SIM language preferences only store a language (e.g. fr = French), not an
7260 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7261 // the SIM and carrier preferences does not include a country we add the country
7262 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007263 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007265 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 return mccLocale.toLanguageTag();
7267 }
7268
7269 if (DBG) log("No locale found - returning null");
7270 return null;
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007274 }
7275
7276 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007277 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007278 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007279 }
7280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 /**
7282 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7283 */
7284 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007285 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007286 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007287 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007288
Chenjie Yu1ba97252018-01-11 18:16:20 -08007289 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007290 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007291
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007292 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007293 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7294 * representing the state of the modem.
7295 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007296 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7297 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007298 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007299 */
7300 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007301 public void requestModemActivityInfo(ResultReceiver result) {
7302 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
sqian1a1be542020-03-05 11:37:28 -08007307 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 } finally {
7309 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007310 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007311 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007312
Siddharth Rayb8114062018-06-17 15:02:38 -07007313 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7314 // less than total activity duration.
7315 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7316 if (info == null) {
7317 return false;
7318 }
7319 int activityDurationMs =
7320 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7321 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007322 int[] txTimeMs = info.getTransmitTimeMillis();
7323 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7324 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007325 }
7326 return (info.isValid()
7327 && (info.getSleepTimeMillis() <= activityDurationMs)
7328 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007329 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007330 && (totalTxTimeMs <= activityDurationMs));
7331 }
7332
Jack Yu85bd38a2015-11-09 11:34:32 -08007333 /**
7334 * {@hide}
7335 * Returns the service state information on specified subscription.
7336 */
7337 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007338 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7339 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007341 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007342 return null;
7343 }
7344
Hall Liuf19c44f2018-11-27 14:38:17 -08007345 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7346 LocationAccessPolicy.checkLocationPermission(mApp,
7347 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7348 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007349 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007350 .setCallingPid(Binder.getCallingPid())
7351 .setCallingUid(Binder.getCallingUid())
7352 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007353 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007354 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7355 .build());
7356
7357 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7358 LocationAccessPolicy.checkLocationPermission(mApp,
7359 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7360 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007361 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007362 .setCallingPid(Binder.getCallingPid())
7363 .setCallingUid(Binder.getCallingUid())
7364 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007365 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007366 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7367 .build());
7368 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7369 boolean hasFinePermission =
7370 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7371 boolean hasCoarsePermission =
7372 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 final long identity = Binder.clearCallingIdentity();
7375 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007376 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7377 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7378 Rlog.d(LOG_TAG,
7379 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7380 return null;
7381 }
7382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final Phone phone = getPhone(subId);
7384 if (phone == null) {
7385 return null;
7386 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007387
Hall Liuf19c44f2018-11-27 14:38:17 -08007388 ServiceState ss = phone.getServiceState();
7389
7390 // Scrub out the location info in ServiceState depending on what level of access
7391 // the caller has.
7392 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007393 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7394 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007398 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007399
7400 /**
7401 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7402 *
7403 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7404 * voicemail ringtone.
7405 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7406 * PhoneAccount.
7407 */
7408 @Override
7409 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7413 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007421 }
7422
7423 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007424 * Sets the per-account voicemail ringtone.
7425 *
7426 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7427 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7428 *
7429 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7430 * voicemail ringtone.
7431 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7432 * PhoneAccount.
7433 */
7434 @Override
7435 public void setVoicemailRingtoneUri(String callingPackage,
7436 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007437 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007439 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7440 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7442 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7443 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
7448 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7449 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 }
7452 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007455 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007456 }
7457
7458 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007459 * Returns whether vibration is set for voicemail notification in Phone settings.
7460 *
7461 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7462 * voicemail vibration setting.
7463 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7464 */
7465 @Override
7466 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7470 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007478 }
7479
Youhan Wange64578a2016-05-02 15:32:42 -07007480 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007481 * Sets the per-account voicemail vibration.
7482 *
7483 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7484 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7485 *
7486 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7487 * voicemail vibration setting.
7488 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7489 * specific PhoneAccount.
7490 */
7491 @Override
7492 public void setVoicemailVibrationEnabled(String callingPackage,
7493 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007494 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007495 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007496 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7497 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7499 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7500 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007501 }
7502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7506 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 }
7509 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007512 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007513 }
7514
7515 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007516 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7517 *
7518 * @throws SecurityException if the caller does not have the required permission
7519 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007520 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007521 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007522 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007523 }
7524
7525 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007526 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7527 * permission.
7528 *
7529 * @throws SecurityException if the caller does not have the required permission
7530 */
7531 private void enforceSendSmsPermission() {
7532 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7533 }
7534
7535 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007536 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007537 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007538 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007539 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007540 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 if (componentName == null) {
7546 throw new SecurityException(
7547 "Caller not current active visual voicemail package[null]");
7548 }
7549 String vvmPackage = componentName.getPackageName();
7550 if (!callingPackage.equals(vvmPackage)) {
7551 throw new SecurityException("Caller not current active visual voicemail package["
7552 + vvmPackage + "]");
7553 }
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007556 }
7557 }
7558
7559 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007560 * Return the application ID for the app type.
7561 *
7562 * @param subId the subscription ID that this request applies to.
7563 * @param appType the uicc app type.
7564 * @return Application ID for specificied app type, or null if no uicc.
7565 */
7566 @Override
7567 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007568 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007569 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570
7571 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007572 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 if (phone == null) {
7574 return null;
7575 }
7576 String aid = null;
7577 try {
7578 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7579 .getApplicationByType(appType).getAid();
7580 } catch (Exception e) {
7581 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7582 }
7583 return aid;
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007586 }
Youhan Wange64578a2016-05-02 15:32:42 -07007587 }
7588
Youhan Wang4001d252016-05-11 10:29:41 -07007589 /**
7590 * Return the Electronic Serial Number.
7591 *
7592 * @param subId the subscription ID that this request applies to.
7593 * @return ESN or null if error.
7594 */
7595 @Override
7596 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007597 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007598 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599
7600 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007601 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 if (phone == null) {
7603 return null;
7604 }
7605 String esn = null;
7606 try {
7607 esn = phone.getEsn();
7608 } catch (Exception e) {
7609 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7610 }
7611 return esn;
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007614 }
Youhan Wang4001d252016-05-11 10:29:41 -07007615 }
7616
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007617 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007618 * Return the Preferred Roaming List Version.
7619 *
7620 * @param subId the subscription ID that this request applies to.
7621 * @return PRLVersion or null if error.
7622 */
7623 @Override
7624 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007625 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007626 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627
7628 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007629 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 if (phone == null) {
7631 return null;
7632 }
7633 String cdmaPrlVersion = null;
7634 try {
7635 cdmaPrlVersion = phone.getCdmaPrlVersion();
7636 } catch (Exception e) {
7637 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7638 }
7639 return cdmaPrlVersion;
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007642 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007643 }
7644
7645 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007646 * Get snapshot of Telephony histograms
7647 * @return List of Telephony histograms
7648 * @hide
7649 */
7650 @Override
7651 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7653 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654
7655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 return RIL.getTelephonyRILTimingHistograms();
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007661 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007662
7663 /**
7664 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007665 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7666 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007667 * Require system privileges. In the future we may add this to carrier APIs.
7668 *
Michele Berionne482f8202018-11-27 18:57:59 -08007669 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007670 */
7671 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007672 @TelephonyManager.SetCarrierRestrictionResult
7673 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007674 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007675 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007676
Michele Berionne482f8202018-11-27 18:57:59 -08007677 if (carrierRestrictionRules == null) {
7678 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007679 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007683 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007684 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 } finally {
7686 Binder.restoreCallingIdentity(identity);
7687 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007688 }
7689
7690 /**
7691 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007692 * Get the allowed carrier list and the excluded carrier list, including the priority between
7693 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007694 * Require system privileges. In the future we may add this to carrier APIs.
7695 *
Michele Berionne482f8202018-11-27 18:57:59 -08007696 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007697 */
7698 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007699 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007700 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007701 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007705 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7706 if (response instanceof CarrierRestrictionRules) {
7707 return (CarrierRestrictionRules) response;
7708 }
7709 // Response is an Exception of some kind,
7710 // which is signalled to the user as a NULL retval
7711 return null;
7712 } catch (Exception e) {
7713 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7714 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007718 }
7719
fionaxu59545b42016-05-25 15:53:37 -07007720 /**
fionaxu59545b42016-05-25 15:53:37 -07007721 * Action set from carrier signalling broadcast receivers to enable/disable radio
7722 * @param subId the subscription ID that this action applies to.
7723 * @param enabled control enable or disable radio.
7724 * {@hide}
7725 */
7726 @Override
7727 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7728 enforceModifyPermission();
7729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730
7731 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007732 if (phone == null) {
7733 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7734 return;
7735 }
7736 try {
7737 phone.carrierActionSetRadioEnabled(enabled);
7738 } catch (Exception e) {
7739 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 } finally {
7741 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007742 }
7743 }
7744
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007745 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007746 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7747 * network status based on which carrier apps could apply actions accordingly,
7748 * enable/disable default url handler for example.
7749 *
7750 * @param subId the subscription ID that this action applies to.
7751 * @param report control start/stop reporting the default network status.
7752 * {@hide}
7753 */
7754 @Override
7755 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7756 enforceModifyPermission();
7757 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758
7759 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007760 if (phone == null) {
7761 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7762 return;
7763 }
7764 try {
7765 phone.carrierActionReportDefaultNetworkStatus(report);
7766 } catch (Exception e) {
7767 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 } finally {
7769 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007770 }
7771 }
7772
7773 /**
fionaxud9622282017-07-17 17:51:30 -07007774 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7775 * @param subId the subscription ID that this action applies to.
7776 * {@hide}
7777 */
7778 @Override
7779 public void carrierActionResetAll(int subId) {
7780 enforceModifyPermission();
7781 final Phone phone = getPhone(subId);
7782 if (phone == null) {
7783 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7784 return;
7785 }
7786 try {
7787 phone.carrierActionResetAll();
7788 } catch (Exception e) {
7789 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7790 }
7791 }
7792
7793 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007794 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7795 * bug report is being generated.
7796 */
7797 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007798 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007799 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7800 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007801 writer.println("Permission Denial: can't dump Phone from pid="
7802 + Binder.getCallingPid()
7803 + ", uid=" + Binder.getCallingUid()
7804 + "without permission "
7805 + android.Manifest.permission.DUMP);
7806 return;
7807 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007808 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007809 }
Jack Yueb89b242016-06-22 13:27:47 -07007810
Brad Ebingerdac2f002018-04-03 15:17:52 -07007811 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007812 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7813 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7814 @NonNull String[] args) {
7815 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7816 this, in.getFileDescriptor(), out.getFileDescriptor(),
7817 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007818 }
7819
Jack Yueb89b242016-06-22 13:27:47 -07007820 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007821 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007822 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007823 * @param reason the reason the data enable change is taking place
7824 * @param enabled True if enabling the data, otherwise disabling.
7825 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007826 */
7827 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007828 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007829 boolean enabled) {
7830 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7831 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7832 try {
7833 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007834 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007835 } catch (SecurityException se) {
7836 enforceModifyPermission();
7837 }
7838 } else {
7839 enforceModifyPermission();
7840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841
7842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 Phone phone = getPhone(subId);
7845 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007846 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7847 phone.carrierActionSetMeteredApnsEnabled(enabled);
7848 } else {
7849 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 }
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007854 }
7855 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007856
7857 /**
7858 * Get Client request stats
7859 * @return List of Client Request Stats
7860 * @hide
7861 */
7862 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007863 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7864 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007866 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007867 return null;
7868 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007869 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 if (phone != null) {
7874 return phone.getClientRequestStats();
7875 }
7876
7877 return null;
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007881 }
7882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007883 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007884 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007885 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007886 }
Jack Yueb4124c2017-02-16 15:32:43 -08007887
7888 /**
Grace Chen70990072017-03-24 17:21:30 -07007889 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007890 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007891 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007892 * @param state State of SIM (power down, power up, pass through)
7893 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7894 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7895 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007896 *
7897 **/
7898 @Override
Grace Chen70990072017-03-24 17:21:30 -07007899 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007900 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007901 Phone phone = PhoneFactory.getPhone(slotIndex);
7902
vagdeviaf9a5b92018-08-15 16:01:53 -07007903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007908 phone.setSimPowerState(state, null, workSource);
7909 }
7910 } finally {
7911 Binder.restoreCallingIdentity(identity);
7912 }
7913 }
7914
7915 /**
7916 * Set SIM card power state.
7917 *
7918 * @param slotIndex SIM slot id.
7919 * @param state State of SIM (power down, power up, pass through)
7920 * @param callback callback to trigger after success or failure
7921 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7922 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7923 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7924 *
7925 **/
7926 @Override
7927 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7928 IIntegerConsumer callback) {
7929 enforceModifyPermission();
7930 Phone phone = PhoneFactory.getPhone(slotIndex);
7931
7932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7933
7934 final long identity = Binder.clearCallingIdentity();
7935 try {
7936 if (phone != null) {
7937 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7938 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 }
7940 } finally {
7941 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007942 }
7943 }
Shuo Qiandd210312017-04-12 22:11:33 +00007944
Tyler Gunn65d45c22017-06-05 11:22:26 -07007945 private boolean isUssdApiAllowed(int subId) {
7946 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007947 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007948 if (configManager == null) {
7949 return false;
7950 }
7951 PersistableBundle pb = configManager.getConfigForSubId(subId);
7952 if (pb == null) {
7953 return false;
7954 }
7955 return pb.getBoolean(
7956 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7957 }
7958
Shuo Qiandd210312017-04-12 22:11:33 +00007959 /**
7960 * Check if phone is in emergency callback mode
7961 * @return true if phone is in emergency callback mode
7962 * @param subId sub id
7963 */
goneil9c5f4872017-12-05 14:07:56 -08007964 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007965 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007966 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968
7969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 if (phone != null) {
7972 return phone.isInEcm();
7973 } else {
7974 return false;
7975 }
7976 } finally {
7977 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007978 }
7979 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007980
7981 /**
7982 * Get the current signal strength information for the given subscription.
7983 * Because this information is not updated when the device is in a low power state
7984 * it should not be relied-upon to be current.
7985 * @param subId Subscription index
7986 * @return the most recent cached signal strength info from the modem
7987 */
7988 @Override
7989 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 Phone p = getPhone(subId);
7993 if (p == null) {
7994 return null;
7995 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 return p.getSignalStrength();
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008002
Pengquan Meng77b7f132018-08-22 14:49:57 -07008003 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008004 * Get the current modem radio state for the given slot.
8005 * @param slotIndex slot index.
8006 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008007 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008008 * @return the current radio power state from the modem
8009 */
8010 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008011 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008012 Phone phone = PhoneFactory.getPhone(slotIndex);
8013 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8015 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008016 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8017 }
8018
8019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 return phone.getRadioPowerState();
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
8025 }
8026 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8027 }
8028
8029 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008030 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8031 *
8032 * <p>Requires one of the following permissions:
8033 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8034 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8035 * privileges.
8036 *
8037 * @param subId subscription id
8038 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8039 * {@code false}.
8040 */
8041 @Override
8042 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008043 try {
8044 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8045 null);
8046 } catch (Exception e) {
8047 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8048 mApp, subId, "isDataRoamingEnabled");
8049 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008050
Pengquan Menga1bb6272018-09-06 09:59:22 -07008051 boolean isEnabled = false;
8052 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008053 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008054 Phone phone = getPhone(subId);
8055 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008058 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008059 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008060 }
8061
8062
8063 /**
8064 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8065 *
8066 * <p> Requires permission:
8067 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8068 * privileges.
8069 *
8070 * @param subId subscription id
8071 * @param isEnabled {@code true} means enable, {@code false} means disable.
8072 */
8073 @Override
8074 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8076 mApp, subId, "setDataRoamingEnabled");
8077
Pengquan Menga1bb6272018-09-06 09:59:22 -07008078 final long identity = Binder.clearCallingIdentity();
8079 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008080 Phone phone = getPhone(subId);
8081 if (phone != null) {
8082 phone.setDataRoamingEnabled(isEnabled);
8083 }
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008086 }
8087 }
8088
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008089 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008090 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008091 TelephonyPermissions
8092 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008093 mApp, subId, "isManualNetworkSelectionAllowed");
8094
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008095 boolean isAllowed = true;
8096 final long identity = Binder.clearCallingIdentity();
8097 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008098 Phone phone = getPhone(subId);
8099 if (phone != null) {
8100 isAllowed = phone.isCspPlmnEnabled();
8101 }
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
8105 return isAllowed;
8106 }
8107
8108 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008109 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008110 // Verify that tha callingPackage belongs to the calling UID
8111 mApp.getSystemService(AppOpsManager.class)
8112 .checkPackage(Binder.getCallingUid(), callingPackage);
8113
Jordan Liu1e142fc2019-04-22 15:10:43 -07008114 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008115 try {
8116 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008117 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008118 } catch (SecurityException e) {
8119 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8120 // has carrier privileges on an active UICC
8121 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8122 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008123 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008124 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008125 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008126
8127 final long identity = Binder.clearCallingIdentity();
8128 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008129 UiccController uiccController = UiccController.getInstance();
8130 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008131 if (hasReadPermission) {
8132 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008133 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008134
8135 // Remove private info if the caller doesn't have access
8136 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8137 for (UiccCardInfo cardInfo : cardInfos) {
8138 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8139 // is available
8140 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8141 if (card == null || card.getUiccProfile() == null) {
8142 // assume no access if the card or profile is unavailable
8143 filteredInfos.add(cardInfo.getUnprivileged());
8144 continue;
8145 }
8146 UiccProfile profile = card.getUiccProfile();
8147 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8148 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8149 filteredInfos.add(cardInfo);
8150 } else {
8151 filteredInfos.add(cardInfo.getUnprivileged());
8152 }
8153 }
8154 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
8158 }
8159
8160 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008161 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008162 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 final long identity = Binder.clearCallingIdentity();
8165 try {
8166 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8167 if (slots == null) {
8168 Rlog.i(LOG_TAG, "slots is null.");
8169 return null;
8170 }
8171
8172 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8173 for (int i = 0; i < slots.length; i++) {
8174 UiccSlot slot = slots[i];
8175 if (slot == null) {
8176 continue;
8177 }
8178
Jordan Liu7be7e652019-05-06 18:55:02 +00008179 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 UiccCard card = slot.getUiccCard();
8181 if (card != null) {
8182 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008183 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008184 cardId = slot.getEid();
8185 if (TextUtils.isEmpty(cardId)) {
8186 cardId = slot.getIccId();
8187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 }
8189
Jordan Liu857451f2019-05-09 16:35:35 -07008190 if (cardId != null) {
8191 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8192 // if cardId is an EID, it's all digits so this is fine
8193 cardId = IccUtils.stripTrailingFs(cardId);
8194 }
8195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 int cardState = 0;
8197 switch (slot.getCardState()) {
8198 case CARDSTATE_ABSENT:
8199 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8200 break;
8201 case CARDSTATE_PRESENT:
8202 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8203 break;
8204 case CARDSTATE_ERROR:
8205 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8206 break;
8207 case CARDSTATE_RESTRICTED:
8208 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8209 break;
8210 default:
8211 break;
8212
8213 }
8214
8215 infos[i] = new UiccSlotInfo(
8216 slot.isActive(),
8217 slot.isEuicc(),
8218 cardId,
8219 cardState,
8220 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008221 slot.isExtendedApduSupported(),
8222 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 }
8224 return infos;
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008227 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008228 }
8229
8230 @Override
8231 public boolean switchSlots(int[] physicalSlots) {
8232 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008240 }
Jack Yu4c988042018-02-27 15:30:01 -08008241
8242 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008243 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 return UiccController.getInstance().getCardIdForDefaultEuicc();
8247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
8250 }
8251
Pengquan Meng85728fb2018-03-12 16:31:21 -07008252 /**
goneil47ffb6e2018-04-06 15:40:58 -07008253 * A test API to reload the UICC profile.
8254 *
8255 * <p>Requires that the calling app has permission
8256 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8257 * @hide
8258 */
8259 @Override
8260 public void refreshUiccProfile(int subId) {
8261 enforceModifyPermission();
8262
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 Phone phone = getPhone(subId);
8266 if (phone == null) {
8267 return;
8268 }
8269 UiccCard uiccCard = phone.getUiccCard();
8270 if (uiccCard == null) {
8271 return;
8272 }
8273 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8274 if (uiccProfile == null) {
8275 return;
8276 }
8277 uiccProfile.refresh();
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
8281 }
8282
8283 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008284 * Returns false if the mobile data is disabled by default, otherwise return true.
8285 */
8286 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008287 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008288 }
8289
8290 /**
8291 * Returns true if the data roaming is enabled by default, i.e the system property
8292 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8293 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8294 */
8295 private boolean getDefaultDataRoamingEnabled(int subId) {
8296 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008297 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008298 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008299 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8300 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8301 return isDataRoamingEnabled;
8302 }
8303
8304 /**
8305 * Returns the default network type for the given {@code subId}, if the default network type is
8306 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8307 */
8308 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008309 List<Integer> list = TelephonyProperties.default_network();
8310 int phoneId = mSubscriptionController.getPhoneId(subId);
8311 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8312 return list.get(phoneId);
8313 }
8314 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008315 }
fionaxua13278b2018-03-21 00:08:13 -07008316
8317 @Override
8318 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008319 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008320 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321
8322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 final Phone phone = getPhone(subId);
8325 if (phone == null) {
8326 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8327 return;
8328 }
chen xueaba88a2019-03-15 13:15:10 -07008329 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8330 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008331 if (carrierPrivilegeRules == null) {
8332 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8333 } else {
8334 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 } finally {
8337 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008338 }
fionaxua13278b2018-03-21 00:08:13 -07008339 }
8340
8341 @Override
8342 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008343 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344
8345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 final Phone phone = getPhone(subId);
8348 if (phone == null) {
8349 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8350 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8351 }
8352 return phone.getCarrierIdListVersion();
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008355 }
fionaxua13278b2018-03-21 00:08:13 -07008356 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008357
8358 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008359 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8360 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008362 mApp, subId, callingPackage, callingFeatureId,
8363 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008364 return -1;
8365 }
8366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
8373 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008374
8375 @Override
8376 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008377 TelephonyPermissions
8378 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008379 mApp, subId, "getCdmaRoamingMode");
8380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
8388
8389 @Override
8390 public boolean setCdmaRoamingMode(int subId, int mode) {
8391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8392 mApp, subId, "setCdmaRoamingMode");
8393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
8400 }
8401
8402 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008403 public int getCdmaSubscriptionMode(int subId) {
8404 TelephonyPermissions
8405 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8406 mApp, subId, "getCdmaSubscriptionMode");
8407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
8416 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008417 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8419 mApp, subId, "setCdmaSubscriptionMode");
8420
8421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008428
sqianc5eccab2018-10-19 18:46:41 -07008429 @Override
sqian8c685422019-02-22 15:55:18 -08008430 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008431 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008433 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8434 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008435 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8436 }
8437 final long identity = Binder.clearCallingIdentity();
8438 try {
sqian854d44b2018-12-12 16:48:18 -08008439 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8440 for (Phone phone: PhoneFactory.getPhones()) {
8441 if (phone.getEmergencyNumberTracker() != null
8442 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8443 emergencyNumberListInternal.put(
8444 phone.getSubId(),
8445 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8446 }
sqian11b7a0e2018-12-05 18:48:28 -08008447 }
sqian854d44b2018-12-12 16:48:18 -08008448 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008449 } finally {
8450 Binder.restoreCallingIdentity(identity);
8451 }
sqianc5eccab2018-10-19 18:46:41 -07008452 }
8453
8454 @Override
sqian8c685422019-02-22 15:55:18 -08008455 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008456 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008457 if (!exactMatch) {
8458 TelephonyPermissions
8459 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008460 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008461 }
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
sqian854d44b2018-12-12 16:48:18 -08008464 for (Phone phone: PhoneFactory.getPhones()) {
8465 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008466 && phone.getEmergencyNumberTracker()
8467 .isEmergencyNumber(number, exactMatch)) {
8468 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008469 }
sqian11b7a0e2018-12-05 18:48:28 -08008470 }
8471 return false;
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 }
8476
sqianf4ca7ed2019-01-15 18:32:07 -08008477 /**
8478 * Update emergency number list for test mode.
8479 */
8480 @Override
8481 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8482 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8483 "updateEmergencyNumberListTestMode");
8484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 for (Phone phone: PhoneFactory.getPhones()) {
8488 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8489 if (tracker != null) {
8490 tracker.executeEmergencyNumberTestModeCommand(action, num);
8491 }
8492 }
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
8496 }
8497
8498 /**
8499 * Get the full emergency number list for test mode.
8500 */
8501 @Override
8502 public List<String> getEmergencyNumberListTestMode() {
8503 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8504 "getEmergencyNumberListTestMode");
8505
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 Set<String> emergencyNumbers = new HashSet<>();
8509 for (Phone phone: PhoneFactory.getPhones()) {
8510 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8511 if (tracker != null) {
8512 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8513 emergencyNumbers.add(num.getNumber());
8514 }
8515 }
8516 }
8517 return new ArrayList<>(emergencyNumbers);
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
chen xud6b45bd2018-10-30 22:27:10 -07008523 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008524 public int getEmergencyNumberDbVersion(int subId) {
8525 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 final Phone phone = getPhone(subId);
8530 if (phone == null) {
8531 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8532 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8533 }
8534 return phone.getEmergencyNumberDbVersion();
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
8539
8540 @Override
8541 public void notifyOtaEmergencyNumberDbInstalled() {
8542 enforceModifyPermission();
8543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 for (Phone phone: PhoneFactory.getPhones()) {
8547 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8548 if (tracker != null) {
8549 tracker.updateOtaEmergencyNumberDatabase();
8550 }
8551 }
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
8557 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008558 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008559 enforceActiveEmergencySessionPermission();
8560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 for (Phone phone: PhoneFactory.getPhones()) {
8564 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8565 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008566 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8567 }
8568 }
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
8573
8574 @Override
8575 public void resetOtaEmergencyNumberDbFilePath() {
8576 enforceActiveEmergencySessionPermission();
8577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 for (Phone phone: PhoneFactory.getPhones()) {
8581 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8582 if (tracker != null) {
8583 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008584 }
8585 }
8586 } finally {
8587 Binder.restoreCallingIdentity(identity);
8588 }
8589 }
8590
8591 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008592 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8593 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8594 Phone phone = getPhone(subId);
8595 if (phone == null) {
8596 return null;
8597 }
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 UiccProfile profile = UiccController.getInstance()
8601 .getUiccProfileForPhone(phone.getPhoneId());
8602 if (profile != null) {
8603 return profile.getCertsFromCarrierPrivilegeAccessRules();
8604 }
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
8608 return null;
8609 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008610
8611 /**
8612 * Enable or disable a modem stack.
8613 */
8614 @Override
8615 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8616 enforceModifyPermission();
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 Phone phone = PhoneFactory.getPhone(slotIndex);
8621 if (phone == null) {
8622 return false;
8623 } else {
8624 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8625 }
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
Michelecea4cf22018-12-21 15:00:11 -08008630
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008631 /**
8632 * Whether a modem stack is enabled or not.
8633 */
8634 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008635 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8636 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008637 Phone phone = PhoneFactory.getPhone(slotIndex);
8638 if (phone == null) return false;
8639
8640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008641 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8642 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008643 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8644 }
8645
8646 final long identity = Binder.clearCallingIdentity();
8647 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008648 try {
8649 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8650 } catch (NoSuchElementException ex) {
8651 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8652 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
8656 }
8657
Michelecea4cf22018-12-21 15:00:11 -08008658 @Override
Michele0ea7d782019-03-19 14:58:42 -07008659 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008660 enforceModifyPermission();
8661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008665 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008666 .commit();
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 }
8671
8672 @Override
Michele0ea7d782019-03-19 14:58:42 -07008673 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008674 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008676 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8677 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008678 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008679 }
Michelecea4cf22018-12-21 15:00:11 -08008680
8681 final long identity = Binder.clearCallingIdentity();
8682 try {
Michele0ea7d782019-03-19 14:58:42 -07008683 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008684 } finally {
8685 Binder.restoreCallingIdentity(identity);
8686 }
8687 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008688
Michele0ea7d782019-03-19 14:58:42 -07008689 @TelephonyManager.IsMultiSimSupportedResult
8690 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008691 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8692 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8693 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008694 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8695 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008696 }
8697 // Check if the hardware supports multisim functionality. If usage of multisim is not
8698 // supported by the modem, indicate that it is restricted.
8699 PhoneCapability staticCapability =
8700 mPhoneConfigurationManager.getStaticPhoneCapability();
8701 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008702 loge("isMultiSimSupportedInternal: no static configuration available");
8703 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008704 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008705 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008706 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8707 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008708 }
8709 // Check if support of multiple SIMs is restricted by carrier
8710 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008711 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008712 }
8713
Michele0ea7d782019-03-19 14:58:42 -07008714 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008715 }
8716
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008717 /**
8718 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008719 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8720 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8721 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008722 * @param numOfSims number of active sims we want to switch to
8723 */
8724 @Override
8725 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008726 if (numOfSims == 1) {
8727 enforceModifyPermission();
8728 } else {
8729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8730 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8731 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008732 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008733
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008734 try {
Michele30b57b22019-03-01 12:01:14 -08008735 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008736 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008737 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8738 return;
8739 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008740 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8741 } finally {
8742 Binder.restoreCallingIdentity(identity);
8743 }
8744 }
8745
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008746 @Override
8747 public boolean isApplicationOnUicc(int subId, int appType) {
8748 enforceReadPrivilegedPermission("isApplicationOnUicc");
8749 Phone phone = getPhone(subId);
8750 if (phone == null) {
8751 return false;
8752 }
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
8755 UiccCard uiccCard = phone.getUiccCard();
8756 if (uiccCard == null) {
8757 return false;
8758 }
8759 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8760 if (uiccProfile == null) {
8761 return false;
8762 }
8763 if (TelephonyManager.APPTYPE_SIM <= appType
8764 && appType <= TelephonyManager.APPTYPE_ISIM) {
8765 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8766 }
8767 return false;
8768 } finally {
8769 Binder.restoreCallingIdentity(identity);
8770 }
8771 }
8772
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008773 /**
chen xub4baa772019-04-03 10:23:41 -07008774 * Get whether making changes to modem configurations will trigger reboot.
8775 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008776 */
8777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008778 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8779 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008781 mApp, subId, callingPackage, callingFeatureId,
8782 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008783 return false;
8784 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
8792
Nathan Harold29f5f052019-02-15 13:41:57 -08008793 private void updateModemStateMetrics() {
8794 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8795 // TODO: check the state for each modem if the api is ready.
8796 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8797 }
8798
Pengquan Meng3889a572019-01-23 11:16:29 -08008799 @Override
8800 public int[] getSlotsMapping() {
8801 enforceReadPrivilegedPermission("getSlotsMapping");
8802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8806 // All logical slots should have a mapping to a physical slot.
8807 int[] logicalSlotsMapping = new int[phoneCount];
8808 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8809 for (int i = 0; i < slotInfos.length; i++) {
8810 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8811 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8812 }
8813 }
8814 return logicalSlotsMapping;
8815 } finally {
8816 Binder.restoreCallingIdentity(identity);
8817 }
8818 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008819
8820 /**
8821 * Get the IRadio HAL Version
8822 */
8823 @Override
8824 public int getRadioHalVersion() {
8825 Phone phone = getDefaultPhone();
8826 if (phone == null) return -1;
8827 HalVersion hv = phone.getHalVersion();
8828 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8829 return hv.major * 100 + hv.minor;
8830 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008831
8832 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008833 * Get the current calling package name.
8834 * @return the current calling package name
8835 */
8836 @Override
8837 public String getCurrentPackageName() {
8838 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8839 }
8840
8841 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008842 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8843 * corresponding network requests on a subId.
8844 *
8845 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008846 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008847 * 2) APN is un-metered for this subscription, or
8848 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008849 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008850 *
8851 * @return whether data is allowed for a apn type.
8852 *
8853 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008854 */
8855 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008856 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008857 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8858 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008859
8860 // Now that all security checks passes, perform the operation as ourselves.
8861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 Phone phone = getPhone(subId);
8864 if (phone == null) return false;
8865
Jack Yu41407ee2019-05-13 16:54:09 -07008866 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008867 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8868 } finally {
8869 Binder.restoreCallingIdentity(identity);
8870 }
8871 }
8872
8873 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008874 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008875 enforceReadPrivilegedPermission("isApnMetered");
8876
8877 // Now that all security checks passes, perform the operation as ourselves.
8878 final long identity = Binder.clearCallingIdentity();
8879 try {
8880 Phone phone = getPhone(subId);
8881 if (phone == null) return true; // By default return true.
8882
Jack Yu41407ee2019-05-13 16:54:09 -07008883 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008888
8889 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008890 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8891 int subscriptionId, IBooleanConsumer resultCallback) {
8892 enforceModifyPermission();
8893 long token = Binder.clearCallingIdentity();
8894 try {
8895 Phone phone = getPhone(subscriptionId);
8896 if (phone == null) {
8897 try {
8898 if (resultCallback != null) {
8899 resultCallback.accept(false);
8900 }
8901 } catch (RemoteException e) {
8902 // ignore
8903 }
8904 return;
8905 }
8906 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8907 Pair.create(specifiers, (x) -> {
8908 try {
8909 if (resultCallback != null) {
8910 resultCallback.accept(x);
8911 }
8912 } catch (RemoteException e) {
8913 // ignore
8914 }
8915 });
8916 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8917 } finally {
8918 Binder.restoreCallingIdentity(token);
8919 }
8920 }
8921
8922 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008923 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8924 TelephonyPermissions
8925 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8926 mApp, subId, "getSystemSelectionChannels");
8927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
8930 List<RadioAccessSpecifier> specifiers =
8931 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8932 null, subId, workSource);
8933 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8934 return specifiers;
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
8940 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008941 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008942 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008943 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8944 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8945 if (iccRecords == null) {
8946 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8947 return false;
8948 }
8949 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8950 }
8951
8952 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008953 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8954 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008955 if (callingPackage == null) {
8956 callingPackage = getCurrentPackageName();
8957 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008958 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8959 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008960 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8961 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008962 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8963 }
8964 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8965 Intent intent = new Intent();
8966 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8967 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8968 // Bring up choose default SMS subscription dialog right now
8969 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8970 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8971 mApp.startActivity(intent);
8972 }
chen xud5ca2d52019-05-28 15:20:57 -07008973
8974 @Override
8975 public String getMmsUAProfUrl(int subId) {
8976 //TODO investigate if this API should require proper permission check in R b/133791609
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008979 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8980 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8981 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8982 return carrierUAProfUrl;
8983 }
chen xud5ca2d52019-05-28 15:20:57 -07008984 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8985 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
8989 }
8990
8991 @Override
8992 public String getMmsUserAgent(int subId) {
8993 //TODO investigate if this API should require proper permission check in R b/133791609
8994 final long identity = Binder.clearCallingIdentity();
8995 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008996 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8997 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8998 if (!TextUtils.isEmpty(carrierUserAgent)) {
8999 return carrierUserAgent;
9000 }
chen xud5ca2d52019-05-28 15:20:57 -07009001 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9002 .getString(com.android.internal.R.string.config_mms_user_agent);
9003 } finally {
9004 Binder.restoreCallingIdentity(identity);
9005 }
9006 }
Jack Yub07d4972019-05-28 16:12:25 -07009007
9008 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009009 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9010 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9011
9012 final long identity = Binder.clearCallingIdentity();
9013 try {
9014 Phone phone = getPhone(subscriptionId);
9015 if (phone == null) return false;
9016
9017 switch (policy) {
9018 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9019 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9020 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9021 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9022 default:
9023 throw new IllegalArgumentException(policy + " is not a valid policy");
9024 }
9025 } finally {
9026 Binder.restoreCallingIdentity(identity);
9027 }
9028 }
9029
9030 @Override
9031 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9032 boolean enabled) {
9033 enforceModifyPermission();
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Phone phone = getPhone(subscriptionId);
9038 if (phone == null) return;
9039
9040 switch (policy) {
9041 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9042 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9043 break;
9044 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9045 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9046 break;
9047 default:
9048 throw new IllegalArgumentException(policy + " is not a valid policy");
9049 }
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009055 /**
Hall Liub48cf452020-09-25 11:13:49 -07009056 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009057 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9058 * otherwise.
9059 */
9060 @Override
9061 public void setCepEnabled(boolean isCepEnabled) {
9062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9063
9064 final long identity = Binder.clearCallingIdentity();
9065 try {
9066 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9067 for (Phone phone : PhoneFactory.getPhones()) {
9068 Phone defaultPhone = phone.getImsPhone();
9069 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9070 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9071 ImsPhoneCallTracker imsPhoneCallTracker =
9072 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9073 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9074 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9075 + imsPhone.getMsisdn());
9076 }
9077 }
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
9080 }
9081 }
allenwtsu46dcc572020-01-08 18:24:03 +08009082
9083 /**
9084 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9085 *
9086 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9087 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9088 * before being read.
9089 */
9090 @Override
9091 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9092 isCompressed) {
9093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9094 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009095 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9096 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9097 }
9098 if (!isImsAvailableOnDevice()) {
9099 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9100 "IMS not available on device.");
9101 }
9102
9103 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009104 try {
Hui Wang068ab862020-10-31 05:12:53 +00009105 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009108 }
9109 }
zoey chenf95ca592019-12-30 16:11:23 +08009110
9111 @Override
9112 public boolean isIccLockEnabled(int subId) {
9113 enforceReadPrivilegedPermission("isIccLockEnabled");
9114
9115 // Now that all security checks passes, perform the operation as ourselves.
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
9118 Phone phone = getPhone(subId);
9119 if (phone != null && phone.getIccCard() != null) {
9120 return phone.getIccCard().getIccLockEnabled();
9121 } else {
9122 return false;
9123 }
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
9128
9129 /**
zoey chene02881a2019-12-30 16:11:23 +08009130 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009131 *
zoey chene02881a2019-12-30 16:11:23 +08009132 * @return an integer representing the status of IccLock enabled or disabled in the following
9133 * three cases:
9134 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9135 * successfully.
9136 * - Positive number and zero for remaining password attempts.
9137 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009138 *
9139 */
9140 @Override
9141 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9142 enforceModifyPermission();
9143
9144 Phone phone = getPhone(subId);
9145 if (phone == null) {
9146 return 0;
9147 }
9148 // Now that all security checks passes, perform the operation as ourselves.
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
9151 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9152 new Pair<Boolean, String>(enabled, password), phone, null);
9153 return attemptsRemaining;
9154
9155 } catch (Exception e) {
9156 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 return 0;
9161 }
9162
9163 /**
9164 * Change the ICC password used in ICC pin lock.
9165 *
zoey chene02881a2019-12-30 16:11:23 +08009166 * @return an integer representing the status of IccLock changed in the following three cases:
9167 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9168 * - Positive number and zero for remaining password attempts.
9169 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009170 *
9171 */
9172 @Override
9173 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9174 enforceModifyPermission();
9175
9176 Phone phone = getPhone(subId);
9177 if (phone == null) {
9178 return 0;
9179 }
9180 // Now that all security checks passes, perform the operation as ourselves.
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9184 new Pair<String, String>(oldPassword, newPassword), phone, null);
9185 return attemptsRemaining;
9186
9187 } catch (Exception e) {
9188 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 return 0;
9193 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009194
Peter Wangdafb9ac2020-01-15 14:13:38 -08009195 /**
9196 * Request for receiving user activity notification
9197 */
9198 @Override
9199 public void requestUserActivityNotification() {
9200 if (!mNotifyUserActivity.get()
9201 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9202 mNotifyUserActivity.set(true);
9203 }
9204 }
9205
9206 /**
9207 * Called when userActivity is signalled in the power manager.
9208 * This is safe to call from any thread, with any window manager locks held or not.
9209 */
9210 @Override
9211 public void userActivity() {
9212 // ***************************************
9213 // * Inherited from PhoneWindowManager *
9214 // ***************************************
9215 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9216 // WITH ITS LOCKS HELD.
9217 //
9218 // This code must be VERY careful about the locks
9219 // it acquires.
9220 // In fact, the current code acquires way too many,
9221 // and probably has lurking deadlocks.
9222
9223 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9224 throw new SecurityException("Only the OS may call notifyUserActivity()");
9225 }
9226
9227 if (mNotifyUserActivity.getAndSet(false)) {
9228 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9229 USER_ACTIVITY_NOTIFICATION_DELAY);
9230 }
9231 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009232
Malcolm Chen884180b2020-04-13 11:59:40 -07009233 @Override
9234 public boolean canConnectTo5GInDsdsMode() {
9235 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9236 }
Jack Yud10cdd42020-09-28 20:28:01 -07009237
9238 @Override
9239 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9240 String callingFeatureId) {
9241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9242 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9243 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9244 }
9245
9246 Phone phone = getPhone(subId);
9247 if (phone == null) {
9248 throw new RuntimeException("phone is not available");
9249 }
9250 // Now that all security checks passes, perform the operation as ourselves.
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 return phone.getEquivalentHomePlmns();
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009258
Hui Wang0866fcc2020-10-12 12:14:23 -07009259 @Override
9260 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9261 UaSecurityProtocolIdentifier securityProtocol,
9262 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9263 throws RemoteException {
9264 enforceModifyPermission();
9265 if (DBG) {
9266 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9267 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9268 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9269 }
9270
9271 if (!SubscriptionManager.isValidSubscriptionId(subId)
9272 || appType < TelephonyManager.APPTYPE_UNKNOWN
9273 || appType > TelephonyManager.APPTYPE_ISIM
9274 || nafUrl == null || securityProtocol == null || callback == null) {
9275 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9276 if (callback != null) {
9277 try {
9278 callback.onAuthenticationFailure(
9279 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9280 } catch (RemoteException exception) {
9281 log("Fail to notify onAuthenticationFailure due to " + exception);
9282 }
9283 return;
9284 }
9285 }
9286
9287 final long token = Binder.clearCallingIdentity();
9288 try {
9289 getGbaManager(subId).bootstrapAuthenticationRequest(
9290 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9291 forceBootStrapping, callback));
9292 } finally {
9293 Binder.restoreCallingIdentity(token);
9294 }
9295 }
9296
Jack Nudelman24d51a52020-11-24 12:08:04 -08009297 /**
9298 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9299 * requested radio power state will actually be set. See {@link
9300 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9301 *
9302 * @param subId the subscription ID of the phone requesting to set the radio power state.
9303 * @param enable {@code true} if trying to turn radio on.
9304 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9305 * false}.
9306 */
9307 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9308 Phone phone = getPhone(subId);
9309 if (phone != null) {
9310 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9311 return true;
9312 }
9313 return false;
9314 }
9315
9316 private int handleDataThrottlingRequest(int subId,
9317 DataThrottlingRequest dataThrottlingRequest) {
9318 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9319 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9320 if (!setRadioPowerForThermal(subId, true)) {
9321 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9322 }
9323
9324 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9325
9326 int thermalMitigationResult =
9327 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9328 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9329 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9330 }
9331 return thermalMitigationResult;
9332 }
9333
9334 /**
9335 * Thermal mitigation request to control functionalities at modem.
9336 *
9337 * @param subId the id of the subscription.
9338 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9339 *
9340 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9341 */
9342 @Override
9343 @ThermalMitigationResult
9344 public int sendThermalMitigationRequest(
9345 int subId,
9346 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9347 enforceModifyPermission();
9348
9349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9350 final long identity = Binder.clearCallingIdentity();
9351
9352 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9353 try {
9354 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9355 switch (thermalMitigationAction) {
9356 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9357 thermalMitigationResult =
9358 handleDataThrottlingRequest(subId,
9359 thermalMitigationRequest.getDataThrottlingRequest());
9360 break;
9361 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9362 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9363 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9364 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9365 }
9366
9367 // Ensure that radio is on. If not able to power on due to phone being
9368 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9369 if (!setRadioPowerForThermal(subId, true)) {
9370 thermalMitigationResult =
9371 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9372 break;
9373 }
9374
9375 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9376 false);
9377 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9378 break;
9379 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9380 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9381 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9382 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9383 }
9384
9385 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9386 if (registry != null) {
9387 TelephonyConnectionService service =
9388 registry.getTelephonyConnectionService();
9389 Phone phone = getPhone(subId);
9390 if (phone == null) {
9391 thermalMitigationResult =
9392 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9393 break;
9394 }
9395
9396 if (PhoneConstantConversions.convertCallState(phone.getState())
9397 != TelephonyManager.CALL_STATE_IDLE
9398 || phone.isInEmergencySmsMode() || phone.isInEcm()
9399 || (service != null && service.isEmergencyCallPending())) {
9400 String errorMessage = "Phone state is not valid. call state = "
9401 + PhoneConstantConversions.convertCallState(phone.getState())
9402 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9403 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9404 errorMessage += service == null
9405 ? " TelephonyConnectionService is null"
9406 : " isEmergencyCallPending = "
9407 + service.isEmergencyCallPending();
9408 Log.e(LOG_TAG, errorMessage);
9409 thermalMitigationResult =
9410 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9411 break;
9412 }
9413 } else {
9414 thermalMitigationResult =
9415 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9416 break;
9417 }
9418
9419 // Turn radio off. If not able to power off due to phone being unavailable,
9420 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9421 if (!setRadioPowerForThermal(subId, false)) {
9422 thermalMitigationResult =
9423 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9424 break;
9425 }
9426 thermalMitigationResult =
9427 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9428 break;
9429 default:
9430 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9431 + "not exist. Requested action: " + thermalMitigationAction);
9432 }
9433 } catch (IllegalArgumentException e) {
9434 throw e;
9435 } catch (Exception e) {
9436 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9437 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441
9442 if (DBG) {
9443 log("thermalMitigationRequest returning with thermalMitigationResult: "
9444 + thermalMitigationResult);
9445 }
9446
9447 return thermalMitigationResult;
9448 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009449
9450 /**
9451 * Set the GbaService Package Name that Telephony will bind to.
9452 *
9453 * @param subId The sim that the GbaService is associated with.
9454 * @param packageName The name of the package to be replaced with.
9455 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9456 */
9457 @Override
9458 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9459 enforceModifyPermission();
9460
9461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 return getGbaManager(subId).overrideServicePackage(packageName);
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
9469 /**
9470 * Return the package name of the currently bound GbaService.
9471 *
9472 * @param subId The sim that the GbaService is associated with.
9473 * @return the package name of the GbaService configuration, null if GBA is not supported.
9474 */
9475 @Override
9476 public String getBoundGbaService(int subId) {
9477 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9478
9479 final long identity = Binder.clearCallingIdentity();
9480 try {
9481 return getGbaManager(subId).getServicePackage();
9482 } finally {
9483 Binder.restoreCallingIdentity(identity);
9484 }
9485 }
9486
9487 /**
9488 * Set the release time for telephony to unbind GbaService.
9489 *
9490 * @param subId The sim that the GbaService is associated with.
9491 * @param interval The release time to unbind GbaService by millisecond.
9492 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9493 */
9494 @Override
9495 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9496 enforceModifyPermission();
9497
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 return getGbaManager(subId).overrideReleaseTime(interval);
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
9503 }
9504 }
9505
9506 /**
9507 * Return the release time for telephony to unbind GbaService.
9508 *
9509 * @param subId The sim that the GbaService is associated with.
9510 * @return The release time to unbind GbaService by millisecond.
9511 */
9512 @Override
9513 public int getGbaReleaseTime(int subId) {
9514 enforceReadPrivilegedPermission("getGbaReleaseTime");
9515
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
9518 return getGbaManager(subId).getReleaseTime();
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
9523
9524 private GbaManager getGbaManager(int subId) {
9525 GbaManager instance = GbaManager.getInstance(subId);
9526 if (instance == null) {
9527 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9528 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9529 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9530 }
9531 return instance;
9532 }
Hui Wang068ab862020-10-31 05:12:53 +00009533
9534 /**
9535 * indicate whether the device and the carrier can support
9536 * RCS VoLTE single registration.
9537 */
9538 @Override
9539 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9540 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9541
9542 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9543 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9544 }
9545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9549 if (rpm != null) {
9550 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9551 }
9552 return false;
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 /**
9559 * Register RCS provisioning callback.
9560 */
9561 @Override
9562 public void registerRcsProvisioningChangedCallback(int subId,
9563 IRcsConfigCallback callback) {
9564 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9565
9566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9567 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9568 }
9569 if (!isImsAvailableOnDevice()) {
9570 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9571 "IMS not available on device.");
9572 }
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9577 .addRcsProvisioningCallbackForSubscription(callback, subId);
9578 } catch (ImsException e) {
9579 throw new ServiceSpecificException(e.getCode());
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
9585 /**
9586 * Unregister RCS provisioning callback.
9587 */
9588 @Override
9589 public void unregisterRcsProvisioningChangedCallback(int subId,
9590 IRcsConfigCallback callback) {
9591 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9592
9593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9594 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9595 }
9596 if (!isImsAvailableOnDevice()) {
9597 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9598 "IMS not available on device.");
9599 }
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9604 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9605 } catch (ImsException e) {
9606 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9607 + "is inactive, ignoring unregister.");
9608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
9611 }
9612
9613 /**
9614 * trigger RCS reconfiguration.
9615 */
9616 public void triggerRcsReconfiguration(int subId) {
9617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9618 mApp, subId, "triggerRcsReconfiguration");
9619
9620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9621 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9622 }
9623 if (!isImsAvailableOnDevice()) {
9624 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9625 "IMS not available on device.");
9626 }
9627
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
9630 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
9635
9636 /**
9637 * Provide the client configuration parameters of the RCS application.
9638 */
9639 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9641 mApp, subId, "setRcsClientConfiguration");
9642
9643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9644 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9645 }
9646 if (!isImsAvailableOnDevice()) {
9647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9648 "IMS not available on device.");
9649 }
9650
9651 final long identity = Binder.clearCallingIdentity();
9652
9653 try {
9654 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9655 if (configBinder == null) {
9656 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9657 } else {
9658 configBinder.setRcsClientConfiguration(rcc);
9659 }
9660 } catch (RemoteException e) {
9661 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 /**
9668 * Overrides the config of RCS VoLTE single registration enabled for the device.
9669 */
9670 @Override
9671 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9673 "setDeviceSingleRegistrationEnabledOverride");
9674 enforceModifyPermission();
9675
9676 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9677 : Boolean.parseBoolean(enabledStr);
9678 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9679 }
9680
9681 /**
9682 * Gets the config of RCS VoLTE single registration enabled for the device.
9683 */
9684 @Override
9685 public boolean getDeviceSingleRegistrationEnabled() {
9686 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9687 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9688 }
9689
9690 /**
9691 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9692 */
9693 @Override
9694 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9696 "setCarrierSingleRegistrationEnabledOverride");
9697 enforceModifyPermission();
9698
9699 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9700 : Boolean.parseBoolean(enabledStr);
9701 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9702 subId, enabled);
9703 }
9704
9705 /**
9706 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9707 */
9708 @Override
9709 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9710 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9711 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9712 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009713
9714 /**
9715 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9716 * their mobile plan.
9717 */
9718 @Override
9719 public String getMobileProvisioningUrl() {
9720 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
9723 return getDefaultPhone().getMobileProvisioningUrl();
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009728}