blob: 4316705e64d62a0b10584159a2e1c5fa671cacde [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
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;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080092import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700117import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700134import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700175import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800176import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800179import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700180import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700181import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800182import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800183
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700184import java.io.FileDescriptor;
185import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800188import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800190import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100191import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700193import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800195import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800196import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198/**
199 * Implementation of the ITelephony interface.
200 */
Santos Cordon117fee72014-05-16 17:56:12 -0700201public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 private static final String LOG_TAG = "PhoneInterfaceManager";
203 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
204 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
207 // Message codes used with mMainThreadHandler
208 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700209 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
210 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700211 private static final int CMD_OPEN_CHANNEL = 9;
212 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
213 private static final int CMD_CLOSE_CHANNEL = 11;
214 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800215 private static final int CMD_NV_READ_ITEM = 13;
216 private static final int EVENT_NV_READ_ITEM_DONE = 14;
217 private static final int CMD_NV_WRITE_ITEM = 15;
218 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
219 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
220 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700221 private static final int CMD_RESET_MODEM_CONFIG = 19;
222 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800223 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
224 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
225 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
226 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800227 private static final int CMD_SEND_ENVELOPE = 25;
228 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000229 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
230 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700231 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
232 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
233 private static final int CMD_EXCHANGE_SIM_IO = 31;
234 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800235 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
236 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700237 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700239 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
240 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700241 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
242 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
243 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
244 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700245 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
246 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
247 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
248 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700249 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800250 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
251 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000252 private static final int CMD_SWITCH_SLOTS = 50;
253 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700254 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
255 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
256 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
257 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
258 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
259 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
260 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
261 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700262 private static final int CMD_GET_ALL_CELL_INFO = 60;
263 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
264 private static final int CMD_GET_CELL_LOCATION = 62;
265 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_MODEM_REBOOT = 64;
267 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700268 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
269 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800270 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
271 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700272 private static final int CMD_GET_MODEM_STATUS = 70;
273 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700274 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
275 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700276 private static final int CMD_ERASE_MODEM_CONFIG = 74;
277 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800278 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
279 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
280 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
281 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800282 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
283 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800284 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800285 private static final int CMD_GET_CALL_FORWARDING = 83;
286 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
287 private static final int CMD_SET_CALL_FORWARDING = 85;
288 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
289 private static final int CMD_GET_CALL_WAITING = 87;
290 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
291 private static final int CMD_SET_CALL_WAITING = 89;
292 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700293 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
294 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
295 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
296 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700297 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
298 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800300 // Parameters of select command.
301 private static final int SELECT_COMMAND = 0xA4;
302 private static final int SELECT_P1 = 0x04;
303 private static final int SELECT_P2 = 0;
304 private static final int SELECT_P3 = 0x10;
305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 /** The singleton instance. */
307 private static PhoneInterfaceManager sInstance;
308
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800311 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700312 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800313 private AppOpsManager mAppOps;
314 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800315 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800316 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700317 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318
Peter Wangdafb9ac2020-01-15 14:13:38 -0800319 /** User Activity */
320 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800321 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
322
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700323 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
324
Derek Tan97ebb422014-09-05 16:55:38 -0700325 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
326 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800327 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800328 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700329
Michelecea4cf22018-12-21 15:00:11 -0800330 // String to store multi SIM allowed
331 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
332
Derek Tan740e1672017-06-27 14:56:27 -0700333 // The AID of ISD-R.
334 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
335
yinxub1bed742017-04-17 11:45:04 -0700336 private NetworkScanRequestTracker mNetworkScanRequestTracker;
337
David Kelly5e06a7f2018-03-12 14:10:59 +0000338 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
339 private static final int MANUFACTURER_CODE_LENGTH = 8;
340
Derek Tan89e89d42014-07-08 17:00:10 -0700341 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700342 * Experiment flag to enable erase modem config on reset network, default value is false
343 */
344 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
345 "reset_network_erase_modem_config_enabled";
346
347 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700348 * A request object to use for transmitting data to an ICC.
349 */
350 private static final class IccAPDUArgument {
351 public int channel, cla, command, p1, p2, p3;
352 public String data;
353
354 public IccAPDUArgument(int channel, int cla, int command,
355 int p1, int p2, int p3, String data) {
356 this.channel = channel;
357 this.cla = cla;
358 this.command = command;
359 this.p1 = p1;
360 this.p2 = p2;
361 this.p3 = p3;
362 this.data = data;
363 }
364 }
365
366 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700367 * A request object to use for transmitting data to an ICC.
368 */
369 private static final class ManualNetworkSelectionArgument {
370 public OperatorInfo operatorInfo;
371 public boolean persistSelection;
372
373 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
374 this.operatorInfo = operatorInfo;
375 this.persistSelection = persistSelection;
376 }
377 }
378
379 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
381 * request after sending. The main thread will notify the request when it is complete.
382 */
383 private static final class MainThreadRequest {
384 /** The argument to use for the request */
385 public Object argument;
386 /** The result of the request that is run on the main thread */
387 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800388 // The subscriber id that this request applies to. Defaults to
389 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
390 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 // In cases where subId is unavailable, the caller needs to specify the phone.
393 public Phone phone;
394
vagdeviaf9a5b92018-08-15 16:01:53 -0700395 public WorkSource workSource;
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 public MainThreadRequest(Object argument) {
398 this.argument = argument;
399 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400
Nathan Harold92bed182018-10-12 18:16:49 -0700401 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
402 this.argument = argument;
403 if (phone != null) {
404 this.phone = phone;
405 }
406 this.workSource = workSource;
407 }
408
vagdeviaf9a5b92018-08-15 16:01:53 -0700409 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800410 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800411 if (subId != null) {
412 this.subId = subId;
413 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700414 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 }
417
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800418 private static final class IncomingThirdPartyCallArgs {
419 public final ComponentName component;
420 public final String callId;
421 public final String callerDisplayName;
422
423 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
424 String callerDisplayName) {
425 this.component = component;
426 this.callId = callId;
427 this.callerDisplayName = callerDisplayName;
428 }
429 }
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 /**
432 * A handler that processes messages on the main thread in the phone process. Since many
433 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
434 * inbound binder threads to the main thread in the phone process. The Binder thread
435 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
436 * on, which will be notified when the operation completes and will contain the result of the
437 * request.
438 *
439 * <p>If a MainThreadRequest object is provided in the msg.obj field,
440 * note that request.result must be set to something non-null for the calling thread to
441 * unblock.
442 */
443 private final class MainThreadHandler extends Handler {
444 @Override
445 public void handleMessage(Message msg) {
446 MainThreadRequest request;
447 Message onCompleted;
448 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800451 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
453 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 case CMD_HANDLE_USSD_REQUEST: {
455 request = (MainThreadRequest) msg.obj;
456 final Phone phone = getPhoneFromRequest(request);
457 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
458 String ussdRequest = ussdObject.first;
459 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700460
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 if (!isUssdApiAllowed(request.subId)) {
462 // Carrier does not support use of this API, return failure.
463 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
464 UssdResponse response = new UssdResponse(ussdRequest, null);
465 Bundle returnData = new Bundle();
466 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
467 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700468
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 request.result = true;
470 notifyRequester(request);
471 return;
472 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700473
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 try {
475 request.result = phone != null
476 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
477 } catch (CallStateException cse) {
478 request.result = false;
479 }
480 // Wake up the requesting thread
481 notifyRequester(request);
482 break;
pkanwar32d516d2016-10-14 19:37:38 -0700483 }
484
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 final Phone phone = getPhoneFromRequest(request);
488 request.result = phone != null ?
489 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
490 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduLogicalChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
506 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700507 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 iccArgument.channel, iccArgument.cla, iccArgument.command,
509 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 break;
513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800523 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800525 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 } else {
527 loge("iccTransmitApduLogicalChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 break;
532
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccTransmitApduBasicChannel: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
543 request);
544 uiccCard.iccTransmitApduBasicChannel(
545 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
546 iccArgument.p3, iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("iccTransmitApduBasicChannel: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("iccTransmitApduBasicChannel: CommandException: " +
561 ar.exception);
562 } else {
563 loge("iccTransmitApduBasicChannel: Unknown exception");
564 }
565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 break;
568
569 case CMD_EXCHANGE_SIM_IO:
570 request = (MainThreadRequest) msg.obj;
571 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 if (uiccCard == null) {
574 loge("iccExchangeSimIO: No UICC");
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 } else {
578 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
579 request);
580 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
581 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
582 iccArgument.data, onCompleted);
583 }
584 break;
585
586 case EVENT_EXCHANGE_SIM_IO_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
589 if (ar.exception == null && ar.result != null) {
590 request.result = ar.result;
591 } else {
592 request.result = new IccIoResult(0x6f, 0, (byte[])null);
593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 break;
596
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 case CMD_SEND_ENVELOPE:
598 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800599 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 if (uiccCard == null) {
601 loge("sendEnvelopeWithStatus: No UICC");
602 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
606 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
607 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 break;
609
610 case EVENT_SEND_ENVELOPE_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700613 if (ar.exception == null && ar.result != null) {
614 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
617 if (ar.result == null) {
618 loge("sendEnvelopeWithStatus: Empty response");
619 } else if (ar.exception instanceof CommandException) {
620 loge("sendEnvelopeWithStatus: CommandException: " +
621 ar.exception);
622 } else {
623 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
624 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 break;
628
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 case CMD_OPEN_CHANNEL:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800632 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 if (uiccCard == null) {
634 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800635 request.result = new IccOpenLogicalChannelResponse(-1,
636 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800640 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
641 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case EVENT_OPEN_CHANNEL_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 int[] result = (int[]) ar.result;
651 int channelId = result[0];
652 byte[] selectResponse = null;
653 if (result.length > 1) {
654 selectResponse = new byte[result.length - 1];
655 for (int i = 1; i < result.length; ++i) {
656 selectResponse[i - 1] = (byte) result[i];
657 }
658 }
659 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 if (ar.result == null) {
663 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 if (ar.exception != null) {
666 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
667 }
668
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700670 if (ar.exception instanceof CommandException) {
671 CommandException.Error error =
672 ((CommandException) (ar.exception)).getCommandError();
673 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700674 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700675 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700676 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 }
678 }
679 openChannelResp = new IccOpenLogicalChannelResponse(
680 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700682 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
686 case CMD_CLOSE_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 if (uiccCard == null) {
690 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900691 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 } else {
694 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
695 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
699 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800700 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
701 break;
702
703 case CMD_NV_READ_ITEM:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
707 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 request.result = "";
717 if (ar.result == null) {
718 loge("nvReadItem: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("nvReadItem: CommandException: " +
721 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800723 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
725 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
Jake Hambye994d462014-02-03 13:10:13 -0800729 case CMD_NV_WRITE_ITEM:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
732 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700734 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_ITEM_DONE:
738 handleNullReturnEvent(msg, "nvWriteItem");
739 break;
740
741 case CMD_NV_WRITE_CDMA_PRL:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
747 case EVENT_NV_WRITE_CDMA_PRL_DONE:
748 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
749 break;
750
chen xu6dac5ab2018-10-26 17:39:23 -0700751 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800752 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700753 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800754 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800755 break;
756
chen xu6dac5ab2018-10-26 17:39:23 -0700757 case EVENT_RESET_MODEM_CONFIG_DONE:
758 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800759 break;
760
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700761 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
764 request);
765 Phone phone = getPhoneFromRequest(request);
766 if (phone != null) {
767 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
768 } else {
769 loge("isNRDualConnectivityEnabled: No phone object");
770 request.result = false;
771 notifyRequester(request);
772 }
773 break;
774 }
775
776 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
781 } else {
782 // request.result must be set to something non-null
783 // for the calling thread to unblock
784 if (request.result != null) {
785 request.result = ar.result;
786 } else {
787 request.result = false;
788 }
789 if (ar.result == null) {
790 loge("isNRDualConnectivityEnabled: Empty response");
791 } else if (ar.exception instanceof CommandException) {
792 loge("isNRDualConnectivityEnabled: CommandException: "
793 + ar.exception);
794 } else {
795 loge("isNRDualConnectivityEnabled: Unknown exception");
796 }
797 }
798 notifyRequester(request);
799 break;
800
801 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
804 Phone phone = getPhoneFromRequest(request);
805 if (phone != null) {
806 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
807 request.workSource);
808 } else {
809 loge("enableNrDualConnectivity: No phone object");
810 request.result =
811 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
812 notifyRequester(request);
813 }
814 break;
815 }
816
817 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null) {
821 request.result =
822 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
823 } else {
824 request.result =
825 TelephonyManager
826 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
827 if (ar.exception instanceof CommandException) {
828 CommandException.Error error =
829 ((CommandException) (ar.exception)).getCommandError();
830 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
831 request.result =
832 TelephonyManager
833 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
834 }
835 loge("enableNrDualConnectivity" + ": CommandException: "
836 + ar.exception);
837 } else {
838 loge("enableNrDualConnectivity" + ": Unknown exception");
839 }
840 }
841 notifyRequester(request);
842 break;
843 }
844
Jake Hamby7c27be32014-03-03 13:25:59 -0800845 case CMD_GET_PREFERRED_NETWORK_TYPE:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700848 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800849 break;
850
851 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result; // Integer
856 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530857 // request.result must be set to something non-null
858 // for the calling thread to unblock
859 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800860 if (ar.result == null) {
861 loge("getPreferredNetworkType: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("getPreferredNetworkType: CommandException: " +
864 ar.exception);
865 } else {
866 loge("getPreferredNetworkType: Unknown exception");
867 }
868 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800870 break;
871
872 case CMD_SET_PREFERRED_NETWORK_TYPE:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
875 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700876 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 break;
878
879 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
880 handleNullReturnEvent(msg, "setPreferredNetworkType");
881 break;
882
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000883 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
884 request = (MainThreadRequest)msg.obj;
885 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000887 break;
888
889 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
890 ar = (AsyncResult)msg.obj;
891 request = (MainThreadRequest)ar.userObj;
892 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700893 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000894 break;
895
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800896 case CMD_SET_VOICEMAIL_NUMBER:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
899 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800900 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
901 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800902 break;
903
904 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
905 handleNullReturnEvent(msg, "setVoicemailNumber");
906 break;
907
Stuart Scott54788802015-03-30 13:18:01 -0700908 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
911 request);
912 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
913 break;
914
915 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
916 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
917 break;
918
Shishir Agrawal302c8692015-06-19 13:49:39 -0700919 case CMD_PERFORM_NETWORK_SCAN:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
922 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
923 break;
924
Hall Liua1acea22020-09-18 19:04:59 -0700925 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700928 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
929 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
930 request.argument;
931 int callForwardingReason = args.first;
932 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800933 break;
Hall Liua1acea22020-09-18 19:04:59 -0700934 }
935 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700938 TelephonyManager.CallForwardingInfoCallback callback =
939 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
940 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800941 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700942 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800943 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
944 for (CallForwardInfo callForwardInfo : callForwardInfos) {
945 // Service Class is a bit mask per 3gpp 27.007. Search for
946 // any service for voice call.
947 if ((callForwardInfo.serviceClass
948 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700949 callForwardingInfo = new CallForwardingInfo(true,
950 callForwardInfo.reason,
951 callForwardInfo.number,
952 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800953 break;
954 }
955 }
956 // Didn't find a call forward info for voice call.
957 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700958 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
959 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800960 }
Hall Liua1acea22020-09-18 19:04:59 -0700961 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800962 } else {
963 if (ar.result == null) {
964 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
965 }
966 if (ar.exception != null) {
967 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
968 }
Hall Liuae527aa2020-09-29 17:10:18 -0700969 int errorCode = TelephonyManager
970 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700975 errorCode = TelephonyManager
976 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800977 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700978 errorCode = TelephonyManager
979 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800980 }
981 }
Hall Liua1acea22020-09-18 19:04:59 -0700982 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800983 }
sqian80370722020-01-29 15:02:51 -0800984 break;
Hall Liua1acea22020-09-18 19:04:59 -0700985 }
sqian80370722020-01-29 15:02:51 -0800986
Hall Liua1acea22020-09-18 19:04:59 -0700987 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700990 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800991 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -0700992 ((Pair<CallForwardingInfo, Consumer<Integer>>)
993 request.argument).first;
994 request.phone.setCallForwardingOption(
995 callForwardingInfoToSet.isEnabled()
996 ? CommandsInterface.CF_ACTION_ENABLE
997 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -0800998 callForwardingInfoToSet.getReason(),
999 callForwardingInfoToSet.getNumber(),
1000 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1001 break;
Hall Liua1acea22020-09-18 19:04:59 -07001002 }
sqian80370722020-01-29 15:02:51 -08001003
Hall Liua1acea22020-09-18 19:04:59 -07001004 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001007 Consumer<Integer> callback =
1008 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1009 request.argument).second;
1010 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001011 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001012 int errorCode = TelephonyManager.CallForwardingInfoCallback
1013 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001014 if (ar.exception instanceof CommandException) {
1015 CommandException.Error error =
1016 ((CommandException) (ar.exception)).getCommandError();
1017 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager.CallForwardingInfoCallback
1019 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001020 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001021 errorCode = TelephonyManager.CallForwardingInfoCallback
1022 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001023 }
1024 }
1025 callback.accept(errorCode);
1026 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001027 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001028 }
sqian80370722020-01-29 15:02:51 -08001029 break;
Hall Liua1acea22020-09-18 19:04:59 -07001030 }
sqian80370722020-01-29 15:02:51 -08001031
Hall Liua1acea22020-09-18 19:04:59 -07001032 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001033 request = (MainThreadRequest) msg.obj;
1034 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1035 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1036 break;
Hall Liua1acea22020-09-18 19:04:59 -07001037 }
sqian80370722020-01-29 15:02:51 -08001038
Hall Liua1acea22020-09-18 19:04:59 -07001039 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001042 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001043 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1044 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001045 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001046 // Service Class is a bit mask per 3gpp 27.007.
1047 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001048 if (callForwardResults.length > 1
1049 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001050 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001051 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001052 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1053 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001054 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001055 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001056 }
1057 } else {
1058 if (ar.result == null) {
1059 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1060 }
1061 if (ar.exception != null) {
1062 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1063 }
1064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1068 callForwardingStatus =
1069 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1070 }
1071 }
1072 }
Hall Liua1acea22020-09-18 19:04:59 -07001073 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001074 break;
Hall Liua1acea22020-09-18 19:04:59 -07001075 }
sqian80370722020-01-29 15:02:51 -08001076
Hall Liua1acea22020-09-18 19:04:59 -07001077 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001080 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1081 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001082 break;
Hall Liua1acea22020-09-18 19:04:59 -07001083 }
sqian80370722020-01-29 15:02:51 -08001084
Hall Liua1acea22020-09-18 19:04:59 -07001085 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001088 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1089 Consumer<Integer> callback =
1090 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1091 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001092 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001093 if (ar.exception instanceof CommandException) {
1094 CommandException.Error error =
1095 ((CommandException) (ar.exception)).getCommandError();
1096 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1097 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1098 } else {
1099 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1100 }
1101 } else {
1102 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1103 }
1104 } else {
1105 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1106 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001107 }
sqian80370722020-01-29 15:02:51 -08001108 break;
Hall Liua1acea22020-09-18 19:04:59 -07001109 }
sqian80370722020-01-29 15:02:51 -08001110
Shishir Agrawal302c8692015-06-19 13:49:39 -07001111 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 CellNetworkScanResult cellScanResult;
1115 if (ar.exception == null && ar.result != null) {
1116 cellScanResult = new CellNetworkScanResult(
1117 CellNetworkScanResult.STATUS_SUCCESS,
1118 (List<OperatorInfo>) ar.result);
1119 } else {
1120 if (ar.result == null) {
1121 loge("getCellNetworkScanResults: Empty response");
1122 }
1123 if (ar.exception != null) {
1124 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1125 }
1126 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1131 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1132 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1133 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1134 }
1135 }
1136 cellScanResult = new CellNetworkScanResult(errorCode, null);
1137 }
1138 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001140 break;
1141
1142 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1143 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001144 ManualNetworkSelectionArgument selArg =
1145 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001146 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1147 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001148 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1149 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001150 break;
1151
1152 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 if (ar.exception == null) {
1156 request.result = true;
1157 } else {
1158 request.result = false;
1159 loge("setNetworkSelectionModeManual " + ar.exception);
1160 }
1161 notifyRequester(request);
1162 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001163 break;
1164
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001165 case CMD_GET_MODEM_ACTIVITY_INFO:
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001168 if (defaultPhone != null) {
1169 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001170 } else {
1171 ResultReceiver result = (ResultReceiver) request.argument;
1172 Bundle bundle = new Bundle();
1173 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1174 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1175 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001176 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001177 break;
1178
1179 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001182 ResultReceiver result = (ResultReceiver) request.argument;
1183
1184 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001185 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001186 // Update the last modem activity info and the result of the request.
1187 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1188 if (isModemActivityInfoValid(info)) {
1189 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1190 int[] txTimeMs = info.getTransmitTimeMillis();
1191 int[] lastModemTxTimeMs = mLastModemActivityInfo
1192 .getTransmitTimeMillis();
1193 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1194 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1195 }
1196 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1197 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1198 + mLastModemActivityInfo.getSleepTimeMillis());
1199 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1200 + mLastModemActivityInfo.getIdleTimeMillis());
1201 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1202 mLastModemActivityInfo.setReceiveTimeMillis(
1203 info.getReceiveTimeMillis()
1204 + mLastModemActivityInfo.getReceiveTimeMillis());
1205 }
1206 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1207 mLastModemActivityInfo.getSleepTimeMillis(),
1208 mLastModemActivityInfo.getIdleTimeMillis(),
1209 mLastModemActivityInfo.getTransmitTimeMillis(),
1210 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001211 } else {
1212 if (ar.result == null) {
1213 loge("queryModemActivityInfo: Empty response");
1214 } else if (ar.exception instanceof CommandException) {
1215 loge("queryModemActivityInfo: CommandException: " +
1216 ar.exception);
1217 } else {
1218 loge("queryModemActivityInfo: Unknown exception");
1219 }
1220 }
sqian1a1be542020-03-05 11:37:28 -08001221 Bundle bundle = new Bundle();
1222 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1223 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 break;
1226
Meng Wang1a7c35a2016-05-05 20:56:15 -07001227 case CMD_SET_ALLOWED_CARRIERS:
1228 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001229 CarrierRestrictionRules argument =
1230 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001231 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001232 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001233 break;
1234
1235 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
1238 if (ar.exception == null && ar.result != null) {
1239 request.result = ar.result;
1240 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001241 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1242 if (ar.exception instanceof CommandException) {
1243 loge("setAllowedCarriers: CommandException: " + ar.exception);
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1247 request.result =
1248 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1249 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001250 } else {
1251 loge("setAllowedCarriers: Unknown exception");
1252 }
1253 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001254 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001255 break;
1256
1257 case CMD_GET_ALLOWED_CARRIERS:
1258 request = (MainThreadRequest) msg.obj;
1259 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001260 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 break;
1262
1263 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
1266 if (ar.exception == null && ar.result != null) {
1267 request.result = ar.result;
1268 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001269 request.result = new IllegalStateException(
1270 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001271 if (ar.result == null) {
1272 loge("getAllowedCarriers: Empty response");
1273 } else if (ar.exception instanceof CommandException) {
1274 loge("getAllowedCarriers: CommandException: " +
1275 ar.exception);
1276 } else {
1277 loge("getAllowedCarriers: Unknown exception");
1278 }
1279 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001280 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 break;
1282
Nathan Haroldb3014052017-01-25 15:57:32 -08001283 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 if (ar.exception == null && ar.result != null) {
1287 request.result = ar.result;
1288 } else {
1289 request.result = new IllegalArgumentException(
1290 "Failed to retrieve Forbidden Plmns");
1291 if (ar.result == null) {
1292 loge("getForbiddenPlmns: Empty response");
1293 } else {
1294 loge("getForbiddenPlmns: Unknown exception");
1295 }
1296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001298 break;
1299
1300 case CMD_GET_FORBIDDEN_PLMNS:
1301 request = (MainThreadRequest) msg.obj;
1302 uiccCard = getUiccCardFromRequest(request);
1303 if (uiccCard == null) {
1304 loge("getForbiddenPlmns() UiccCard is null");
1305 request.result = new IllegalArgumentException(
1306 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001307 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001308 break;
1309 }
1310 Integer appType = (Integer) request.argument;
1311 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1312 if (uiccApp == null) {
1313 loge("getForbiddenPlmns() no app with specified type -- "
1314 + appType);
1315 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001317 break;
1318 } else {
1319 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1320 + " specified type -- " + appType);
1321 }
1322 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1323 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1324 onCompleted);
1325 break;
1326
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001327 case CMD_SWITCH_SLOTS:
1328 request = (MainThreadRequest) msg.obj;
1329 int[] physicalSlots = (int[]) request.argument;
1330 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1331 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1332 break;
1333
1334 case EVENT_SWITCH_SLOTS_DONE:
1335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
1337 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001338 notifyRequester(request);
1339 break;
1340 case CMD_GET_NETWORK_SELECTION_MODE:
1341 request = (MainThreadRequest) msg.obj;
1342 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1343 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1344 break;
1345
1346 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1347 ar = (AsyncResult) msg.obj;
1348 request = (MainThreadRequest) ar.userObj;
1349 if (ar.exception != null) {
1350 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1351 } else {
1352 int mode = ((int[]) ar.result)[0];
1353 if (mode == 0) {
1354 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1355 } else {
1356 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1357 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001358 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
1360 break;
1361 case CMD_GET_CDMA_ROAMING_MODE:
1362 request = (MainThreadRequest) msg.obj;
1363 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1364 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1365 break;
1366 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 if (ar.exception != null) {
1370 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1371 } else {
1372 request.result = ((int[]) ar.result)[0];
1373 }
1374 notifyRequester(request);
1375 break;
1376 case CMD_SET_CDMA_ROAMING_MODE:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1379 int mode = (int) request.argument;
1380 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1381 break;
1382 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 request.result = ar.exception == null;
1386 notifyRequester(request);
1387 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001388 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1389 request = (MainThreadRequest) msg.obj;
1390 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1391 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1392 break;
1393 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 if (ar.exception != null) {
1397 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1398 } else {
1399 request.result = ((int[]) ar.result)[0];
1400 }
1401 notifyRequester(request);
1402 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001403 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1406 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001407 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1408 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 break;
1410 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1411 ar = (AsyncResult) msg.obj;
1412 request = (MainThreadRequest) ar.userObj;
1413 request.result = ar.exception == null;
1414 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001415 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001416 case CMD_GET_ALL_CELL_INFO:
1417 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001418 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001419 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001420 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001421 case EVENT_GET_ALL_CELL_INFO_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001424 // If a timeout occurs, the response will be null
1425 request.result = (ar.exception == null && ar.result != null)
1426 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001427 synchronized (request) {
1428 request.notifyAll();
1429 }
1430 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001431 case CMD_REQUEST_CELL_INFO_UPDATE:
1432 request = (MainThreadRequest) msg.obj;
1433 request.phone.requestCellInfoUpdate(request.workSource,
1434 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1435 break;
1436 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1440 try {
1441 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001442 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001443 cb.onError(
1444 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1445 ar.exception.getClass().getName(),
1446 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001447 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001448 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001449 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001450 } else {
1451 // use the result as returned
1452 cb.onCellInfo((List<CellInfo>) ar.result);
1453 }
1454 } catch (RemoteException re) {
1455 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1456 }
1457 break;
1458 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 request = (MainThreadRequest) msg.obj;
1460 WorkSource ws = (WorkSource) request.argument;
1461 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001462 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001464 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
1467 if (ar.exception == null) {
1468 request.result = ar.result;
1469 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001470 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001472 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 }
1474
1475 synchronized (request) {
1476 request.notifyAll();
1477 }
1478 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001479 case CMD_MODEM_REBOOT:
1480 request = (MainThreadRequest) msg.obj;
1481 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001482 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001483 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001484 case EVENT_CMD_MODEM_REBOOT_DONE:
1485 handleNullReturnEvent(msg, "rebootModem");
1486 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001487 case CMD_REQUEST_ENABLE_MODEM:
1488 request = (MainThreadRequest) msg.obj;
1489 boolean enable = (boolean) request.argument;
1490 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001491 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001492 PhoneConfigurationManager.getInstance()
1493 .enablePhone(request.phone, enable, onCompleted);
1494 break;
1495 case EVENT_ENABLE_MODEM_DONE:
1496 ar = (AsyncResult) msg.obj;
1497 request = (MainThreadRequest) ar.userObj;
1498 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001499 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001500 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001501 if ((boolean) request.result) {
1502 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1503 updateModemStateMetrics();
1504 } else {
1505 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1506 + ar.exception);
1507 }
1508 notifyRequester(request);
1509 break;
1510 case CMD_GET_MODEM_STATUS:
1511 request = (MainThreadRequest) msg.obj;
1512 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1513 PhoneConfigurationManager.getInstance()
1514 .getPhoneStatusFromModem(request.phone, onCompleted);
1515 break;
1516 case EVENT_GET_MODEM_STATUS_DONE:
1517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 int id = request.phone.getPhoneId();
1520 if (ar.exception == null && ar.result != null) {
1521 request.result = ar.result;
1522 //update the cache as modem status has changed
1523 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1524 (boolean) request.result);
1525 } else {
1526 // Return true if modem status cannot be retrieved. For most cases,
1527 // modem status is on. And for older version modems, GET_MODEM_STATUS
1528 // and disable modem are not supported. Modem is always on.
1529 // TODO: this should be fixed in R to support a third
1530 // status UNKNOWN b/131631629
1531 request.result = true;
1532 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1533 + ar.exception);
1534 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001535 notifyRequester(request);
1536 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001537 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1538 request = (MainThreadRequest) msg.obj;
1539 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1540 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1541 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1542 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1543 break;
1544 }
1545 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1549 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1550 args.second.accept(ar.exception == null);
1551 notifyRequester(request);
1552 break;
1553 }
yincheng zhaod698b842019-09-06 17:06:54 -07001554 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 if (ar.exception == null && ar.result != null) {
1558 request.result = ar.result;
1559 } else {
1560 request.result = -1;
1561 loge("Failed to set Forbidden Plmns");
1562 if (ar.result == null) {
1563 loge("setForbidenPlmns: Empty response");
1564 } else if (ar.exception != null) {
1565 loge("setForbiddenPlmns: Exception: " + ar.exception);
1566 request.result = -1;
1567 } else {
1568 loge("setForbiddenPlmns: Unknown exception");
1569 }
1570 }
1571 notifyRequester(request);
1572 break;
1573 case CMD_SET_FORBIDDEN_PLMNS:
1574 request = (MainThreadRequest) msg.obj;
1575 uiccCard = getUiccCardFromRequest(request);
1576 if (uiccCard == null) {
1577 loge("setForbiddenPlmns: UiccCard is null");
1578 request.result = -1;
1579 notifyRequester(request);
1580 break;
1581 }
1582 Pair<Integer, List<String>> setFplmnsArgs =
1583 (Pair<Integer, List<String>>) request.argument;
1584 appType = setFplmnsArgs.first;
1585 List<String> fplmns = setFplmnsArgs.second;
1586 uiccApp = uiccCard.getApplicationByType(appType);
1587 if (uiccApp == null) {
1588 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1589 request.result = -1;
1590 loge("Failed to get UICC App");
1591 notifyRequester(request);
1592 } else {
1593 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1594 ((SIMRecords) uiccApp.getIccRecords())
1595 .setForbiddenPlmns(onCompleted, fplmns);
1596 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001597 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001598 case CMD_ERASE_MODEM_CONFIG:
1599 request = (MainThreadRequest) msg.obj;
1600 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1601 defaultPhone.eraseModemConfig(onCompleted);
1602 break;
1603 case EVENT_ERASE_MODEM_CONFIG_DONE:
1604 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001605 break;
zoey chenf95ca592019-12-30 16:11:23 +08001606
1607 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1610 Pair<String, String> changed = (Pair<String, String>) request.argument;
1611 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1612 changed.first, changed.second, onCompleted);
1613 break;
1614 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null) {
1618 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1619 } else {
1620 request.result = msg.arg1;
1621 }
1622 notifyRequester(request);
1623 break;
1624
1625 case CMD_SET_ICC_LOCK_ENABLED:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1628 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1629 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1630 enabled.first, enabled.second, onCompleted);
1631 break;
1632 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 if (ar.exception == null) {
1636 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1637 } else {
1638 request.result = msg.arg1;
1639 }
1640 notifyRequester(request);
1641 break;
1642
Peter Wangdafb9ac2020-01-15 14:13:38 -08001643 case MSG_NOTIFY_USER_ACTIVITY:
1644 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001645 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001646 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1647 getDefaultPhone().getContext().sendBroadcastAsUser(
1648 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1649 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 default:
1651 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1652 break;
1653 }
1654 }
Jake Hambye994d462014-02-03 13:10:13 -08001655
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 private void notifyRequester(MainThreadRequest request) {
1657 synchronized (request) {
1658 request.notifyAll();
1659 }
1660 }
1661
Jake Hambye994d462014-02-03 13:10:13 -08001662 private void handleNullReturnEvent(Message msg, String command) {
1663 AsyncResult ar = (AsyncResult) msg.obj;
1664 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1665 if (ar.exception == null) {
1666 request.result = true;
1667 } else {
1668 request.result = false;
1669 if (ar.exception instanceof CommandException) {
1670 loge(command + ": CommandException: " + ar.exception);
1671 } else {
1672 loge(command + ": Unknown exception");
1673 }
1674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001675 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 }
1678
1679 /**
1680 * Posts the specified command to be executed on the main thread,
1681 * waits for the request to complete, and returns the result.
1682 * @see #sendRequestAsync
1683 */
1684 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001685 return sendRequest(
1686 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001687 }
1688
1689 /**
1690 * Posts the specified command to be executed on the main thread,
1691 * waits for the request to complete, and returns the result.
1692 * @see #sendRequestAsync
1693 */
1694 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1695 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001696 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
1699 /**
1700 * Posts the specified command to be executed on the main thread,
1701 * waits for the request to complete, and returns the result.
1702 * @see #sendRequestAsync
1703 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001704 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001705 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001706 }
1707
1708 /**
1709 * Posts the specified command to be executed on the main thread,
1710 * waits for the request to complete, and returns the result.
1711 * @see #sendRequestAsync
1712 */
Nathan Harold92bed182018-10-12 18:16:49 -07001713 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1714 return sendRequest(command, argument, subId, null, workSource);
1715 }
1716
1717 /**
1718 * Posts the specified command to be executed on the main thread,
1719 * waits for the request to complete, and returns the result.
1720 * @see #sendRequestAsync
1721 */
1722 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1723 return sendRequest(
1724 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1725 }
1726
1727 /**
1728 * Posts the specified command to be executed on the main thread,
1729 * waits for the request to complete, and returns the result.
1730 * @see #sendRequestAsync
1731 */
1732 private Object sendRequest(
1733 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1735 throw new RuntimeException("This method will deadlock if called from the main thread.");
1736 }
1737
Nathan Harold92bed182018-10-12 18:16:49 -07001738 MainThreadRequest request = null;
1739 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1740 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1741 } else if (phone != null) {
1742 request = new MainThreadRequest(argument, phone, workSource);
1743 } else {
1744 request = new MainThreadRequest(argument, subId, workSource);
1745 }
1746
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 Message msg = mMainThreadHandler.obtainMessage(command, request);
1748 msg.sendToTarget();
1749
1750 // Wait for the request to complete
1751 synchronized (request) {
1752 while (request.result == null) {
1753 try {
1754 request.wait();
1755 } catch (InterruptedException e) {
1756 // Do nothing, go back and wait until the request is complete
1757 }
1758 }
1759 }
1760 return request.result;
1761 }
1762
1763 /**
1764 * Asynchronous ("fire and forget") version of sendRequest():
1765 * Posts the specified command to be executed on the main thread, and
1766 * returns immediately.
1767 * @see #sendRequest
1768 */
1769 private void sendRequestAsync(int command) {
1770 mMainThreadHandler.sendEmptyMessage(command);
1771 }
1772
1773 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001774 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001775 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001776 */
1777 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 sendRequestAsync(command, argument, null, null);
1779 }
1780
1781 /**
1782 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1783 * @see {@link #sendRequest(int,Object)}
1784 */
1785 private void sendRequestAsync(
1786 int command, Object argument, Phone phone, WorkSource workSource) {
1787 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001788 Message msg = mMainThreadHandler.obtainMessage(command, request);
1789 msg.sendToTarget();
1790 }
1791
1792 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 * Initialize the singleton PhoneInterfaceManager instance.
1794 * This is only done once, at startup, from PhoneApp.onCreate().
1795 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001796 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 synchronized (PhoneInterfaceManager.class) {
1798 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001799 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 } else {
1801 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1802 }
1803 return sInstance;
1804 }
1805 }
1806
1807 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001808 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001811 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001812 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1814 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001815 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001816 mTelephonySharedPreferences =
1817 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001818 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001819 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001820 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001821
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 publish();
1823 }
1824
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001825 private Phone getDefaultPhone() {
1826 Phone thePhone = getPhone(getDefaultSubscription());
1827 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1828 }
1829
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 private void publish() {
1831 if (DBG) log("publish: " + this);
1832
Peter Wangc035ce42020-01-08 21:00:22 -08001833 TelephonyFrameworkInitializer
1834 .getTelephonyServiceManager()
1835 .getTelephonyServiceRegisterer()
1836 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
Stuart Scott584921c2015-01-15 17:10:34 -08001839 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001840 if (request.phone != null) {
1841 return request.phone;
1842 } else {
1843 return getPhoneFromSubId(request.subId);
1844 }
1845 }
1846
1847 private Phone getPhoneFromSubId(int subId) {
1848 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1849 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001850 }
1851
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001852 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1853 Phone phone = getPhoneFromRequest(request);
1854 return phone == null ? null :
1855 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1856 }
1857
Wink Saville36469e72014-06-11 15:17:00 -07001858 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001859 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001860 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001863 private void sendEraseModemConfig(Phone phone) {
1864 if (phone != null) {
1865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1866 mApp, phone.getSubId(), "eraseModemConfig");
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
1869 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1870 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
1873 }
1874 }
1875 }
1876
Peter Wang050bb052020-01-13 23:33:09 -08001877 private boolean isImsAvailableOnDevice() {
1878 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1879 if (pm == null) {
1880 // For some reason package manger is not available.. This will fail internally anyway,
1881 // so do not throw error and allow.
1882 return true;
1883 }
1884 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1885 }
1886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001888 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001889 }
1890
Wink Savilleb564aae2014-10-23 10:18:09 -07001891 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 if (DBG) log("dial: " + number);
1893 // No permission check needed here: This is just a wrapper around the
1894 // ACTION_DIAL intent, which is available to any app since it puts up
1895 // the UI before it does anything.
1896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 String url = createTelUrl(number);
1900 if (url == null) {
1901 return;
1902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001904 // PENDING: should we just silently fail if phone is offhook or ringing?
1905 PhoneConstants.State state = mCM.getState(subId);
1906 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1907 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1908 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1909 mApp.startActivity(intent);
1910 }
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914 }
1915
1916 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001917 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001918 }
1919
Wink Savilleb564aae2014-10-23 10:18:09 -07001920 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 if (DBG) log("call: " + number);
1922
1923 // This is just a wrapper around the ACTION_CALL intent, but we still
1924 // need to do a permission check since we're calling startActivity()
1925 // from the context of the phone app.
1926 enforceCallPermission();
1927
Jordan Liu1617b712019-07-10 15:06:26 -07001928 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 != AppOpsManager.MODE_ALLOWED) {
1930 return;
1931 }
1932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 String url = createTelUrl(number);
1936 if (url == null) {
1937 return;
1938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001940 boolean isValid = false;
1941 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1942 if (slist != null) {
1943 for (SubscriptionInfo subInfoRecord : slist) {
1944 if (subInfoRecord.getSubscriptionId() == subId) {
1945 isValid = true;
1946 break;
1947 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001948 }
Wink Saville08874612014-08-31 19:19:58 -07001949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001950 if (!isValid) {
1951 return;
1952 }
Wink Saville08874612014-08-31 19:19:58 -07001953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1955 intent.putExtra(SUBSCRIPTION_KEY, subId);
1956 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1957 mApp.startActivity(intent);
1958 } finally {
1959 Binder.restoreCallingIdentity(identity);
1960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Wink Savilleb564aae2014-10-23 10:18:09 -07001963 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001964 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001965 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1966 }
1967
Wink Savilleb564aae2014-10-23 10:18:09 -07001968 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001969 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001970 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1971 }
1972
Wink Savilleb564aae2014-10-23 10:18:09 -07001973 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975
1976 final long identity = Binder.clearCallingIdentity();
1977 try {
1978 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1979 checkSimPin.start();
1980 return checkSimPin.unlockSim(null, pin);
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Wink Savilleb564aae2014-10-23 10:18:09 -07001986 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988
1989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1992 checkSimPuk.start();
1993 return checkSimPuk.unlockSim(puk, pin);
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002000 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 * a synchronous one.
2002 */
2003 private static class UnlockSim extends Thread {
2004
2005 private final IccCard mSimCard;
2006
2007 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002008 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2009 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010
2011 // For replies from SimCard interface
2012 private Handler mHandler;
2013
2014 // For async handler to identify request type
2015 private static final int SUPPLY_PIN_COMPLETE = 100;
2016
2017 public UnlockSim(IccCard simCard) {
2018 mSimCard = simCard;
2019 }
2020
2021 @Override
2022 public void run() {
2023 Looper.prepare();
2024 synchronized (UnlockSim.this) {
2025 mHandler = new Handler() {
2026 @Override
2027 public void handleMessage(Message msg) {
2028 AsyncResult ar = (AsyncResult) msg.obj;
2029 switch (msg.what) {
2030 case SUPPLY_PIN_COMPLETE:
2031 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2032 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002033 mRetryCount = msg.arg1;
2034 if (ar.exception != null) {
2035 if (ar.exception instanceof CommandException &&
2036 ((CommandException)(ar.exception)).getCommandError()
2037 == CommandException.Error.PASSWORD_INCORRECT) {
2038 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002039 } //When UiccCardApp dispose,handle message and return exception
2040 else if (ar.exception instanceof CommandException &&
2041 ((CommandException) (ar.exception)).getCommandError()
2042 == CommandException.Error.ABORTED) {
2043 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002044 } else {
2045 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2046 }
2047 } else {
2048 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 mDone = true;
2051 UnlockSim.this.notifyAll();
2052 }
2053 break;
2054 }
2055 }
2056 };
2057 UnlockSim.this.notifyAll();
2058 }
2059 Looper.loop();
2060 }
2061
2062 /*
2063 * Use PIN or PUK to unlock SIM card
2064 *
2065 * If PUK is null, unlock SIM card with PIN
2066 *
2067 * If PUK is not null, unlock SIM card with PUK and set PIN code
2068 */
Wink Saville9de0f752013-10-22 19:04:03 -07002069 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070
2071 while (mHandler == null) {
2072 try {
2073 wait();
2074 } catch (InterruptedException e) {
2075 Thread.currentThread().interrupt();
2076 }
2077 }
2078 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2079
2080 if (puk == null) {
2081 mSimCard.supplyPin(pin, callback);
2082 } else {
2083 mSimCard.supplyPuk(puk, pin, callback);
2084 }
2085
2086 while (!mDone) {
2087 try {
2088 Log.d(LOG_TAG, "wait for done");
2089 wait();
2090 } catch (InterruptedException e) {
2091 // Restore the interrupted status
2092 Thread.currentThread().interrupt();
2093 }
2094 }
2095 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002096 int[] resultArray = new int[2];
2097 resultArray[0] = mResult;
2098 resultArray[1] = mRetryCount;
2099 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 }
2101 }
2102
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002103 /**
2104 * This method has been removed due to privacy and stability concerns.
2105 */
2106 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002108 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2109 return;
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
Nathan Harold1f889d82020-06-04 17:05:26 -07002112 @Override
2113 public void updateServiceLocationWithPackageName(String callingPackage) {
2114 mApp.getSystemService(AppOpsManager.class)
2115 .checkPackage(Binder.getCallingUid(), callingPackage);
2116
2117 final int targetSdk = getTargetSdk(callingPackage);
2118 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2119 // Callers targeting S have no business invoking this method.
2120 return;
2121 }
2122
2123 LocationAccessPolicy.LocationPermissionResult locationResult =
2124 LocationAccessPolicy.checkLocationPermission(mApp,
2125 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2126 .setCallingPackage(callingPackage)
2127 .setCallingFeatureId(null)
2128 .setCallingPid(Binder.getCallingPid())
2129 .setCallingUid(Binder.getCallingUid())
2130 .setMethod("updateServiceLocation")
2131 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2132 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2133 .build());
2134 // Apps that lack location permission have no business calling this method;
2135 // however, because no permission was declared in the public API, denials must
2136 // all be "soft".
2137 switch (locationResult) {
2138 case DENIED_HARD: /* fall through */
2139 case DENIED_SOFT:
2140 return;
2141 }
2142
2143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002144 final long identity = Binder.clearCallingIdentity();
2145 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002146 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002148 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 }
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 }
2154
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002155 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002156 @Override
2157 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002158 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002159 }
2160
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002161
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002162 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002163 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2164 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2165 callingFeatureId);
2166 }
2167
2168 @Deprecated
2169 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002171 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2172 }
2173
2174 @Override
2175 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2176 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002178 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002179 return false;
2180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 return isRadioOnForSubscriber(subId);
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002188 }
2189
2190 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 final Phone phone = getPhone(subId);
2194 if (phone != null) {
2195 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2196 } else {
2197 return false;
2198 }
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203
2204 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002205 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 }
Wink Saville36469e72014-06-11 15:17:00 -07002207
Wink Savilleb564aae2014-10-23 10:18:09 -07002208 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 if (phone != null) {
2215 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2216 }
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 }
Wink Saville36469e72014-06-11 15:17:00 -07002220 }
2221
2222 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002223 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
Wink Savilleb564aae2014-10-23 10:18:09 -07002226 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002227 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228
2229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
2232 if (phone == null) {
2233 return false;
2234 }
2235 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2236 toggleRadioOnOffForSubscriber(subId);
2237 }
2238 return true;
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
Wink Saville36469e72014-06-11 15:17:00 -07002243
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002244 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002245 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002246 /*
2247 * If any of the Radios are available, it will need to be
2248 * shutdown. So return true if any Radio is available.
2249 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 final long identity = Binder.clearCallingIdentity();
2251 try {
2252 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2253 Phone phone = PhoneFactory.getPhone(i);
2254 if (phone != null && phone.isRadioAvailable()) return true;
2255 }
2256 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2257 return false;
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002260 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002261 }
2262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002264 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265 enforceModifyPermission();
2266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2270 logv("Shutting down Phone " + i);
2271 shutdownRadioUsingPhoneId(i);
2272 }
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002275 }
2276 }
2277
2278 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002279 Phone phone = PhoneFactory.getPhone(phoneId);
2280 if (phone != null && phone.isRadioAvailable()) {
2281 phone.shutdownRadio();
2282 }
2283 }
2284
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2291 if (defaultPhone != null) {
2292 defaultPhone.setRadioPower(turnOn);
2293 return true;
2294 } else {
2295 loge("There's no default phone.");
2296 return false;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002300 }
Wink Saville36469e72014-06-11 15:17:00 -07002301 }
2302
Wink Savilleb564aae2014-10-23 10:18:09 -07002303 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 final Phone phone = getPhone(subId);
2309 if (phone != null) {
2310 phone.setRadioPower(turnOn);
2311 return true;
2312 } else {
2313 return false;
2314 }
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
Wink Saville36469e72014-06-11 15:17:00 -07002320 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 public boolean enableDataConnectivity() {
2323 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 int subId = mSubscriptionController.getDefaultDataSubId();
2328 final Phone phone = getPhone(subId);
2329 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002330 phone.getDataEnabledSettings().setDataEnabled(
2331 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332 return true;
2333 } else {
2334 return false;
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Wink Saville36469e72014-06-11 15:17:00 -07002341 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 public boolean disableDataConnectivity() {
2344 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 int subId = mSubscriptionController.getDefaultDataSubId();
2349 final Phone phone = getPhone(subId);
2350 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002351 phone.getDataEnabledSettings().setDataEnabled(
2352 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353 return true;
2354 } else {
2355 return false;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002363 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 final Phone phone = getPhone(subId);
2367 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002368 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 } else {
2370 return false;
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376
2377 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002378 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
pkanwarae03a6b2016-11-06 20:37:09 -08002381 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 enforceCallPermission();
2383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2387 return;
2388 }
2389 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2390 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
pkanwar32d516d2016-10-14 19:37:38 -07002394 };
2395
Wink Savilleb564aae2014-10-23 10:18:09 -07002396 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398
2399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2402 return false;
2403 }
2404 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002411 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002412 }
2413
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002414 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 Phone phone = PhoneFactory.getPhone(slotIndex);
2418 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2419 PhoneConstantConversions.convertCallState(phone.getState());
2420 } finally {
2421 Binder.restoreCallingIdentity(identity);
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
Sanket Padawe356d7632015-06-22 14:03:32 -07002425 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002426 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002427 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2428 }
2429
2430 @Override
2431 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 final long identity = Binder.clearCallingIdentity();
2433 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 if (phone != null) {
2436 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2437 } else {
2438 return PhoneConstantConversions.convertDataState(
2439 PhoneConstants.DataState.DISCONNECTED);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Sanket Padawe356d7632015-06-22 14:03:32 -07002446 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002447 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002448 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2449 }
2450
2451 @Override
2452 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 final long identity = Binder.clearCallingIdentity();
2454 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002455 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 if (phone != null) {
2457 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2458 } else {
2459 return TelephonyManager.DATA_ACTIVITY_NONE;
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002467 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002468 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002469 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002470
2471 LocationAccessPolicy.LocationPermissionResult locationResult =
2472 LocationAccessPolicy.checkLocationPermission(mApp,
2473 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2474 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002475 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002476 .setCallingPid(Binder.getCallingPid())
2477 .setCallingUid(Binder.getCallingUid())
2478 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002479 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002480 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2481 .build());
2482 switch (locationResult) {
2483 case DENIED_HARD:
2484 throw new SecurityException("Not allowed to access cell location");
2485 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002486 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2487 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002494 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002495 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 } finally {
2497 Binder.restoreCallingIdentity(identity);
2498 }
Svetoslav64fad262015-04-14 14:35:21 -07002499 }
2500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 @Override
Jack Yu01425032020-02-22 19:38:58 -08002502 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002503 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2504 // registered cell info, so return a NULL country instead.
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002507 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2508 // Get default phone in this case.
2509 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2510 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002511 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002513 if (phone == null) return "";
2514 ServiceStateTracker sst = phone.getServiceStateTracker();
2515 if (sst == null) return "";
2516 LocaleTracker lt = sst.getLocaleTracker();
2517 if (lt == null) return "";
2518 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2519 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2520 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002524 }
2525
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002526 /**
2527 * This method was removed due to potential issues caused by performing partial
2528 * updates of service state, and lack of a credible use case.
2529 *
2530 * This has the ability to break the telephony implementation by disabling notification of
2531 * changes in device connectivity. DO NOT USE THIS!
2532 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002533 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 public void enableLocationUpdates() {
2535 mApp.enforceCallingOrSelfPermission(
2536 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002539 /**
2540 * This method was removed due to potential issues caused by performing partial
2541 * updates of service state, and lack of a credible use case.
2542 *
2543 * This has the ability to break the telephony implementation by disabling notification of
2544 * changes in device connectivity. DO NOT USE THIS!
2545 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 @Override
2547 public void disableLocationUpdates() {
2548 mApp.enforceCallingOrSelfPermission(
2549 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
Nathan Harold31d7ff32018-10-15 20:20:30 -07002552 /**
2553 * Returns the target SDK version number for a given package name.
2554 *
Nathan Haroldec184742019-07-10 17:04:16 -07002555 * This call MUST be invoked before clearing the calling UID.
2556 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002557 * @return target SDK if the package is found or INT_MAX.
2558 */
2559 private int getTargetSdk(String packageName) {
2560 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002561 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002562 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002563 if (ai != null) return ai.targetSdkVersion;
2564 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002565 loge("Failed to get package info for pkg="
2566 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002567 }
2568 return Integer.MAX_VALUE;
2569 }
2570
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 @Override
2572 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002573 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2574 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002575 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002576 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2577 throw new SecurityException(
2578 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2579 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002580
Jordan Liu1617b712019-07-10 15:06:26 -07002581 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2583 return null;
2584 }
Svetoslav64fad262015-04-14 14:35:21 -07002585
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002586 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002588 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002589 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590
Nathan Haroldf180aac2018-06-01 18:43:55 -07002591 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2592 for (CellInfo ci : info) {
2593 if (ci instanceof CellInfoGsm) {
2594 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2595 } else if (ci instanceof CellInfoWcdma) {
2596 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002599 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 }
2601
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002602 private List<CellInfo> getCachedCellInfo() {
2603 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2604 for (Phone phone : PhoneFactory.getPhones()) {
2605 List<CellInfo> info = phone.getAllCellInfo();
2606 if (info != null) cellInfos.addAll(info);
2607 }
2608 return cellInfos;
2609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610
2611 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002612 public List<CellInfo> getAllCellInfo(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("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -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 info");
2630 case DENIED_SOFT:
2631 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002634 final int targetSdk = getTargetSdk(callingPackage);
2635 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2636 return getCachedCellInfo();
2637 }
2638
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002639 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2644 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002645 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002646 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 if (info != null) cellInfos.addAll(info);
2648 }
2649 return cellInfos;
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653 }
2654
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002655 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002656 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2657 String callingFeatureId) {
2658 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2659 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002660 }
2661
2662 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002663 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2664 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002665 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002666 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002667 }
2668
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002669 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2670 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002671 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002672 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002673
2674 LocationAccessPolicy.LocationPermissionResult locationResult =
2675 LocationAccessPolicy.checkLocationPermission(mApp,
2676 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2677 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002678 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002679 .setCallingPid(Binder.getCallingPid())
2680 .setCallingUid(Binder.getCallingUid())
2681 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002682 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2683 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002684 .build());
2685 switch (locationResult) {
2686 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002687 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2688 // Safetynet logging for b/154934934
2689 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2690 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002691 throw new SecurityException("Not allowed to access cell info");
2692 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002693 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2694 // Safetynet logging for b/154934934
2695 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2696 }
Nathan Harold5320c422019-05-09 10:26:08 -07002697 try {
2698 cb.onCellInfo(new ArrayList<CellInfo>());
2699 } catch (RemoteException re) {
2700 // Drop without consequences
2701 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002702 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002703 }
2704
Nathan Harolda939a962019-05-09 10:13:47 -07002705
2706 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002707 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2708
2709 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2710 }
2711
2712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002714 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002715 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Shishir Agrawala9f32182016-04-12 12:00:16 -07002725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002726 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002727 Phone phone = PhoneFactory.getPhone(slotIndex);
2728 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002729 return null;
2730 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002731 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002732 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002733 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002734 return null;
2735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736
2737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 return phone.getImei();
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002743 }
2744
2745 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002746 public String getTypeAllocationCodeForSlot(int slotIndex) {
2747 Phone phone = PhoneFactory.getPhone(slotIndex);
2748 String tac = null;
2749 if (phone != null) {
2750 String imei = phone.getImei();
2751 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2752 }
2753 return tac;
2754 }
2755
2756 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002757 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002758 Phone phone = PhoneFactory.getPhone(slotIndex);
2759 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002760 return null;
2761 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002762
Jeff Davidson913390f2018-02-23 17:11:49 -08002763 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002764 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002766 return null;
2767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768
2769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 return phone.getMeid();
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Jack Yu2af8d712017-03-15 17:14:14 -07002775 }
2776
2777 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002778 public String getManufacturerCodeForSlot(int slotIndex) {
2779 Phone phone = PhoneFactory.getPhone(slotIndex);
2780 String manufacturerCode = null;
2781 if (phone != null) {
2782 String meid = phone.getMeid();
2783 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2784 }
2785 return manufacturerCode;
2786 }
2787
2788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002789 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2790 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002791 Phone phone = PhoneFactory.getPhone(slotIndex);
2792 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 return null;
2794 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002795 int subId = phone.getSubId();
2796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002797 mApp, subId, callingPackage, callingFeatureId,
2798 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002799 return null;
2800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 return phone.getDeviceSvn();
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002808 }
2809
fionaxu43304da2017-11-27 22:51:16 -08002810 @Override
2811 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 final Phone phone = getPhone(subId);
2815 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
fionaxu43304da2017-11-27 22:51:16 -08002819 }
2820
2821 @Override
2822 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 return phone == null ? null : phone.getCarrierName();
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
fionaxu43304da2017-11-27 22:51:16 -08002830 }
2831
calvinpanffe225e2018-11-01 19:43:06 +08002832 @Override
chen xu0026ca62019-03-06 15:28:50 -08002833 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = getPhone(subId);
2837 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002838 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002839 } finally {
2840 Binder.restoreCallingIdentity(identity);
2841 }
2842 }
2843
2844 @Override
chen xu0026ca62019-03-06 15:28:50 -08002845 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002849 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 }
2854
chen xu651eec72018-11-11 19:03:44 -08002855 @Override
chen xu864e11c2018-12-06 22:10:03 -08002856 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2857 if (!isSubscriptionMccMnc) {
2858 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2859 }
chen xu651eec72018-11-11 19:03:44 -08002860 final Phone phone = PhoneFactory.getPhone(slotIndex);
2861 if (phone == null) {
2862 return TelephonyManager.UNKNOWN_CARRIER_ID;
2863 }
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 //
2873 // Internal helper methods.
2874 //
2875
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002876 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2878 *
2879 * @throws SecurityException if the caller does not have the required permission
2880 */
2881 private void enforceModifyPermission() {
2882 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2883 }
2884
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002885 /**
2886 * Make sure the caller is system.
2887 *
2888 * @throws SecurityException if the caller is not system.
2889 */
2890 private void enforceSystemCaller() {
2891 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2892 throw new SecurityException("Caller must be system");
2893 }
2894 }
2895
Shuo Qianf2b2df42019-11-13 17:43:31 -08002896 private void enforceActiveEmergencySessionPermission() {
2897 mApp.enforceCallingOrSelfPermission(
2898 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2899 }
2900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 /**
2902 * Make sure the caller has the CALL_PHONE permission.
2903 *
2904 * @throws SecurityException if the caller does not have the required permission
2905 */
2906 private void enforceCallPermission() {
2907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2908 }
2909
paulhu423b5f22019-08-23 19:17:33 +08002910 private void enforceSettingsPermission() {
2911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002912 }
2913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 private String createTelUrl(String number) {
2915 if (TextUtils.isEmpty(number)) {
2916 return null;
2917 }
2918
Jake Hambye994d462014-02-03 13:10:13 -08002919 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Ihab Awadf9e92732013-12-05 18:02:52 -08002922 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2924 }
2925
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002926 private static void logv(String msg) {
2927 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2928 }
2929
Ihab Awadf9e92732013-12-05 18:02:52 -08002930 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2932 }
2933
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002934 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002936 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002937 }
2938
Sanket Padawe356d7632015-06-22 14:03:32 -07002939 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002940 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 final Phone phone = PhoneFactory.getPhone(slotIndex);
2944 if (phone == null) {
2945 return PhoneConstants.PHONE_TYPE_NONE;
2946 } else {
2947 return phone.getPhoneType();
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 /**
2955 * Returns the CDMA ERI icon index to display
2956 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002957 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002958 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2959 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2960 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002961 }
2962
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002964 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2965 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002967 mApp, subId, callingPackage, callingFeatureId,
2968 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002969 return -1;
2970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = getPhone(subId);
2975 if (phone != null) {
2976 return phone.getCdmaEriIconIndex();
2977 } else {
2978 return -1;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
2985 /**
2986 * Returns the CDMA ERI icon mode,
2987 * 0 - ON
2988 * 1 - FLASHING
2989 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2992 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2993 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002994 }
2995
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003000 mApp, subId, callingPackage, callingFeatureId,
3001 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 return -1;
3003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
3005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 final Phone phone = getPhone(subId);
3008 if (phone != null) {
3009 return phone.getCdmaEriIconMode();
3010 } else {
3011 return -1;
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
3018 /**
3019 * Returns the CDMA ERI text,
3020 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003021 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003022 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3023 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3024 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003025 }
3026
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003028 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3029 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003031 mApp, subId, callingPackage, callingFeatureId,
3032 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003033 return null;
3034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 final Phone phone = getPhone(subId);
3039 if (phone != null) {
3040 return phone.getCdmaEriText();
3041 } else {
3042 return null;
3043 }
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 }
3048
3049 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003050 * Returns the CDMA MDN.
3051 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003052 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003053 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3055 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003060 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 return phone.getLine1Number();
3062 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 return null;
3065 }
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003068 }
3069 }
3070
3071 /**
3072 * Returns the CDMA MIN.
3073 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003074 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003075 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3077 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078
3079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 final Phone phone = getPhone(subId);
3082 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3083 return phone.getCdmaMin();
3084 } else {
3085 return null;
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003089 }
3090 }
3091
Hall Liud892bec2018-11-30 14:51:45 -08003092 @Override
3093 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3094 INumberVerificationCallback callback, String callingPackage) {
3095 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3096 != PERMISSION_GRANTED) {
3097 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3098 }
3099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3100
3101 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3102 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3103 throw new SecurityException("Calling package must be configured in the device config");
3104 }
3105
3106 if (range == null) {
3107 throw new NullPointerException("Range must be non-null");
3108 }
3109
3110 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003111 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003112
3113 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3114 }
3115
Junda Liuca05d5d2014-08-14 22:36:34 -07003116 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 * Returns true if CDMA provisioning needs to run.
3118 */
3119 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 final long identity = Binder.clearCallingIdentity();
3121 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003122 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
3128 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003129 * Sets the voice mail number of a given subId.
3130 */
3131 @Override
3132 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003133 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3134 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3139 new Pair<String, String>(alphaTag, number), new Integer(subId));
3140 return success;
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003144 }
3145
Ta-wei Yen87c49842016-05-13 21:19:52 -07003146 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003147 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003149 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3150 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003151 if (!TextUtils.equals(callingPackage, systemDialer)) {
3152 throw new SecurityException("caller must be system dialer");
3153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154
3155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3158 if (phoneAccountHandle == null) {
3159 return null;
3160 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 } finally {
3163 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003164 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003165 }
3166
3167 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003168 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3169 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003170 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003172 mApp, subId, callingPackage, callingFeatureId,
3173 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003174 return null;
3175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003177 final long identity = Binder.clearCallingIdentity();
3178 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003179 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003183 }
3184
3185 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003186 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3187 VisualVoicemailSmsFilterSettings settings) {
3188 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003197 }
3198
3199 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003200 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3201 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003210 }
3211
3212 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003213 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3214 String callingPackage, int subId) {
3215 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003220 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003224 }
3225
3226 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003227 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003237 }
3238
3239 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003240 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3241 String callingAttributionTag, int subId, String number, int port, String text,
3242 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003244 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003245 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003246 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003247 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3248 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003249 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003250
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003251 /**
fionaxu0152e512016-11-14 13:36:14 -08003252 * Sets the voice activation state of a given subId.
3253 */
3254 @Override
3255 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3257 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258
3259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 final Phone phone = getPhone(subId);
3262 if (phone != null) {
3263 phone.setVoiceActivationState(activationState);
3264 } else {
3265 loge("setVoiceActivationState fails with invalid subId: " + subId);
3266 }
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003269 }
3270 }
3271
3272 /**
3273 * Sets the data activation state of a given subId.
3274 */
3275 @Override
3276 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3278 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 final Phone phone = getPhone(subId);
3283 if (phone != null) {
3284 phone.setDataActivationState(activationState);
3285 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003286 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287 }
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003290 }
3291 }
3292
3293 /**
3294 * Returns the voice activation state of a given subId.
3295 */
3296 @Override
3297 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
fionaxu0152e512016-11-14 13:36:14 -08003300 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 if (phone != null) {
3304 return phone.getVoiceActivationState();
3305 } else {
3306 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3307 }
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003310 }
3311 }
3312
3313 /**
3314 * Returns the data activation state of a given subId.
3315 */
3316 @Override
3317 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
fionaxu0152e512016-11-14 13:36:14 -08003320 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 if (phone != null) {
3324 return phone.getDataActivationState();
3325 } else {
3326 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3327 }
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003330 }
3331 }
3332
3333 /**
Wink Saville36469e72014-06-11 15:17:00 -07003334 * Returns the unread count of voicemails for a subId
3335 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003336 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003337 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3338 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003340 mApp, subId, callingPackage, callingFeatureId,
3341 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003342 return 0;
3343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 final Phone phone = getPhone(subId);
3347 if (phone != null) {
3348 return phone.getVoiceMessageCount();
3349 } else {
3350 return 0;
3351 }
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356
3357 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003358 * returns true, if the device is in a state where both voice and data
3359 * are supported simultaneously. This can change based on location or network condition.
3360 */
3361 @Override
3362 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
3366 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003370 }
3371
3372 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003373 * Send the dialer code if called from the current default dialer or the caller has
3374 * carrier privilege.
3375 * @param inputCode The dialer code to send
3376 */
3377 @Override
3378 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003381 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3382 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003383 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003384 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003385 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
fionaxu235cc5e2017-03-06 22:25:57 -08003394 }
3395
Pengquan Menga1bb6272018-09-06 09:59:22 -07003396 @Override
3397 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003398 TelephonyPermissions
3399 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3400 mApp, subId, "getNetworkSelectionMode");
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 if (!isActiveSubscription(subId)) {
3404 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3405 }
3406 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003409 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003410 }
3411
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003413 public boolean isInEmergencySmsMode() {
3414 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 for (Phone phone : PhoneFactory.getPhones()) {
3418 if (phone.isInEmergencySmsMode()) {
3419 return true;
3420 }
3421 }
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 return false;
3426 }
3427
shilu366312e2019-12-17 09:28:10 -08003428 /**
3429 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3430 * @param subId The subscription to use to check the configuration.
3431 * @param c The callback that will be used to send the result.
3432 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003433 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003434 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3435 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003436 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3437 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003438
Brad Ebinger77b832e2019-10-17 17:03:22 -07003439 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3440 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3441 "IMS not available on device.");
3442 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 final long token = Binder.clearCallingIdentity();
3444 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003445 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003446 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003448 } catch (ImsException e) {
3449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 } finally {
3451 Binder.restoreCallingIdentity(token);
3452 }
3453 }
3454
shilu366312e2019-12-17 09:28:10 -08003455 /**
3456 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3457 * @param subId The subscription to use to check the configuration.
3458 * @param c The callback that will be used to send the result.
3459 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003461 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003462 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3463 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003464 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3465 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3466 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003467 final long token = Binder.clearCallingIdentity();
3468 try {
3469 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3470 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3471 .removeRegistrationCallbackForSubscription(c, subId);
3472 } catch (ImsException e) {
3473 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3474 + "is inactive, ignoring unregister.");
3475 // If the subscription is no longer active, just return, since the callback
3476 // will already have been removed internally.
3477 } finally {
3478 Binder.restoreCallingIdentity(token);
3479 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 }
3481
Brad Ebinger774ba362019-10-22 17:36:18 -07003482 /**
3483 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3484 */
3485 @Override
3486 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3487 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3488 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3490 "IMS not available on device.");
3491 }
3492 final long token = Binder.clearCallingIdentity();
3493 try {
3494 Phone phone = getPhone(subId);
3495 if (phone == null) {
3496 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3497 + subId + "'");
3498 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3499 }
3500 phone.getImsRegistrationState(regState -> {
3501 try {
3502 consumer.accept((regState == null)
3503 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3504 } catch (RemoteException e) {
3505 // Ignore if the remote process is no longer available to call back.
3506 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3507 }
3508 });
3509 } finally {
3510 Binder.restoreCallingIdentity(token);
3511 }
3512 }
3513
3514 /**
3515 * Get the transport type for the IMS service registration state.
3516 */
3517 @Override
3518 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003519 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3520 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003521 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3523 "IMS not available on device.");
3524 }
3525 final long token = Binder.clearCallingIdentity();
3526 try {
3527 Phone phone = getPhone(subId);
3528 if (phone == null) {
3529 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3530 + subId + "'");
3531 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3532 }
3533 phone.getImsRegistrationTech(regTech -> {
3534 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3535 int regTechConverted = (regTech == null)
3536 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3537 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3538 regTechConverted);
3539 try {
3540 consumer.accept(regTechConverted);
3541 } catch (RemoteException e) {
3542 // Ignore if the remote process is no longer available to call back.
3543 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3544 }
3545 });
3546 } finally {
3547 Binder.restoreCallingIdentity(token);
3548 }
3549 }
3550
shilu366312e2019-12-17 09:28:10 -08003551 /**
3552 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3553 * @param subId The subscription to use to check the configuration.
3554 * @param c The callback that will be used to send the result.
3555 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003557 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3558 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003559 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3560 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003561 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3562 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3563 "IMS not available on device.");
3564 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3566 final long token = Binder.clearCallingIdentity();
3567 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003570 } catch (ImsException e) {
3571 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 } finally {
3573 Binder.restoreCallingIdentity(token);
3574 }
3575 }
3576
shilu366312e2019-12-17 09:28:10 -08003577 /**
3578 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3579 * @param subId The subscription to use to check the configuration.
3580 * @param c The callback that will be used to send the result.
3581 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003583 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003584 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3585 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003586 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3587 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3588 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003589
3590 final long token = Binder.clearCallingIdentity();
3591 try {
3592 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3593 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003594 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003595 } catch (ImsException e) {
3596 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3597 + "is inactive, ignoring unregister.");
3598 // If the subscription is no longer active, just return, since the callback
3599 // will already have been removed internally.
3600 } finally {
3601 Binder.restoreCallingIdentity(token);
3602 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 }
3604
3605 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003606 public boolean isCapable(int subId, int capability, int regTech) {
3607 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3609 final long token = Binder.clearCallingIdentity();
3610 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003613 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3615 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003616 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003617 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3618 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 } finally {
3620 Binder.restoreCallingIdentity(token);
3621 }
3622 }
3623
3624 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003625 public boolean isAvailable(int subId, int capability, int regTech) {
3626 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 final long token = Binder.clearCallingIdentity();
3628 try {
3629 Phone phone = getPhone(subId);
3630 if (phone == null) return false;
3631 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003632 } catch (com.android.ims.ImsException e) {
3633 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3634 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 } finally {
3636 Binder.restoreCallingIdentity(token);
3637 }
3638 }
3639
Brad Ebinger77b832e2019-10-17 17:03:22 -07003640 /**
3641 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3642 * subscription.
3643 * @param subId The subscription to use to check the configuration.
3644 * @param callback The callback that will be used to send the result.
3645 * @param capability The MmTelFeature capability that will be used to send the result.
3646 * @param transportType The transport type of the MmTelFeature capability.
3647 */
3648 @Override
3649 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3650 int transportType) {
3651 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3652 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3653 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3654 "IMS not available on device.");
3655 }
3656 final long token = Binder.clearCallingIdentity();
3657 try {
3658 int slotId = getSlotIndex(subId);
3659 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3660 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3661 + subId + "'");
3662 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3663 }
3664 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3665 transportType, aBoolean -> {
3666 try {
3667 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3668 } catch (RemoteException e) {
3669 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3670 + "running. Ignore");
3671 }
3672 });
3673 } finally {
3674 Binder.restoreCallingIdentity(token);
3675 }
3676 }
3677
shilu366312e2019-12-17 09:28:10 -08003678 /**
3679 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3680 * @param subId The subscription to use to check the configuration.
3681 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 @Override
3683 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003684 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3685 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003686
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3688 final long token = Binder.clearCallingIdentity();
3689 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003692 } catch (ImsException e) {
3693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 } finally {
3695 Binder.restoreCallingIdentity(token);
3696 }
3697 }
3698
3699 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003700 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003702 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
shilu366312e2019-12-17 09:28:10 -08003715 /**
3716 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3717 * @param subId The subscription to use to check the configuration.
3718 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003720 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003721 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3722 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3727 } catch (ImsException e) {
3728 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
3732 }
3733
3734 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003735 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003737 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
shilu366312e2019-12-17 09:28:10 -08003749 /**
3750 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3751 * @param subId The subscription to use to check the configuration.
3752 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 @Override
3754 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003755 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3756 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 }
3768
3769 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003770 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003772 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003777 } catch (ImsException e) {
3778 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
3782 }
3783
shilu366312e2019-12-17 09:28:10 -08003784 /**
3785 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3786 * @param subId The subscription to use to check the configuration.
3787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 @Override
3789 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003790 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3791 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003796 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 } catch (ImsException e) {
3798 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
3802 }
3803
3804 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003805 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003807 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003813 } catch (ImsException e) {
3814 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
3818 }
3819
3820 @Override
3821 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3823 "setVoWiFiNonPersistent");
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003828 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003829 } catch (ImsException e) {
3830 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
3834 }
3835
shilu366312e2019-12-17 09:28:10 -08003836 /**
3837 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3838 * @param subId The subscription to use to check the configuration.
3839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 @Override
3841 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003842 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3843 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003847 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003849 } catch (ImsException e) {
3850 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 } finally {
3852 Binder.restoreCallingIdentity(identity);
3853 }
3854 }
3855
3856 @Override
3857 public void setVoWiFiModeSetting(int subId, int mode) {
3858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3859 "setVoWiFiModeSetting");
3860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003863 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003865 } catch (ImsException e) {
3866 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 } finally {
3868 Binder.restoreCallingIdentity(identity);
3869 }
3870 }
3871
3872 @Override
3873 public int getVoWiFiRoamingModeSetting(int subId) {
3874 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003878 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003880 } catch (ImsException e) {
3881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
3887 @Override
3888 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3890 "setVoWiFiRoamingModeSetting");
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003894 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003896 } catch (ImsException e) {
3897 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 } finally {
3899 Binder.restoreCallingIdentity(identity);
3900 }
3901 }
3902
3903 @Override
3904 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3906 "setRttCapabilityEnabled");
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003910 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916 }
3917
shilu366312e2019-12-17 09:28:10 -08003918 /**
3919 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3920 * @param subId The subscription to use to check the configuration.
3921 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 @Override
3923 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003924 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3925 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003929 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003931 } catch (ImsException e) {
3932 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
3936 }
3937
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003938 @Override
3939 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3940 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003943 if (!isImsAvailableOnDevice()) {
3944 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3945 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003946 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003949 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (ImsException e) {
3951 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
3955 }
3956
3957 @Override
3958 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3959 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3960 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3963 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003964 try {
3965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003967 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003968 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003969 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3970 + "is inactive, ignoring unregister.");
3971 // If the subscription is no longer active, just return, since the callback will already
3972 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
3976 }
3977
allenwtsu99c623b2020-01-03 18:24:23 +08003978
3979 private void checkModifyPhoneStatePermission(int subId, String message) {
3980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3981 message);
3982 }
3983
3984 private boolean isImsProvisioningRequired(int subId, int capability,
3985 boolean isMmtelCapability) {
3986 Phone phone = getPhone(subId);
3987 if (phone == null) {
3988 loge("phone instance null for subid " + subId);
3989 return false;
3990 }
3991 if (isMmtelCapability) {
3992 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3993 return false;
3994 }
3995 } else {
3996 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3997 return false;
3998 }
3999 }
4000 return true;
4001 }
4002
4003 @Override
4004 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4005 boolean isProvisioned) {
4006 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4011 if (!isImsProvisioningRequired(subId, capability, false)) {
4012 return;
4013 }
4014
4015 // this capability requires provisioning, route to the correct API.
4016 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4017 switch (capability) {
4018 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4019 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4020 ims.setEabProvisioned(isProvisioned);
4021 break;
4022 default: {
4023 throw new IllegalArgumentException("Tried to set provisioning for "
4024 + "rcs capability '" + capability + "', which does not require "
4025 + "provisioning.");
4026 }
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031
4032 }
4033
4034
4035 @Override
4036 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4037 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4041 if (!isImsProvisioningRequired(subId, capability, false)) {
4042 return true;
4043 }
4044
4045 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4046 switch (capability) {
4047 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4048 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4049 return ims.isEabProvisionedOnDevice();
4050
4051 default: {
4052 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4053 + "capability '" + capability + "', which does not require "
4054 + "provisioning.");
4055 }
4056 }
4057
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004063 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004064 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4065 boolean isProvisioned) {
4066 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4067 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4068 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4069 }
allenwtsu99c623b2020-01-03 18:24:23 +08004070 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004074 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004075 return;
4076 }
4077
4078 // this capability requires provisioning, route to the correct API.
4079 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4080 switch (capability) {
4081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4082 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4083 ims.setVolteProvisioned(isProvisioned);
4084 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4085 ims.setWfcProvisioned(isProvisioned);
4086 }
4087 break;
4088 }
4089 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4090 // There is currently no difference in VT provisioning type.
4091 ims.setVtProvisioned(isProvisioned);
4092 break;
4093 }
4094 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4095 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4096 // change the capability of the feature instead if needed.
4097 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4098 == isProvisioned) {
4099 // No change in provisioning.
4100 return;
4101 }
4102 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4103 try {
4104 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004105 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004106 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4107 + ", Exception" + e.getMessage());
4108 }
4109 break;
4110 }
4111 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004112 throw new IllegalArgumentException("Tried to set provisioning for "
4113 + "MmTel capability '" + capability + "', which does not require "
4114 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004115 }
4116 }
4117
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122
4123 @Override
4124 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4125 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4126 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4127 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4128 }
4129 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004133 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 return true;
4135 }
4136
4137 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4138 switch (capability) {
4139 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4140 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4141 return ims.isVolteProvisionedOnDevice();
4142 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4143 return ims.isWfcProvisionedOnDevice();
4144 }
4145 // This should never happen, since we are checking tech above to make sure it
4146 // is either LTE or IWLAN.
4147 throw new IllegalArgumentException("Invalid radio technology for voice "
4148 + "capability.");
4149 }
4150 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4151 // There is currently no difference in VT provisioning type.
4152 return ims.isVtProvisionedOnDevice();
4153 }
4154 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4155 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4156 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4157 }
4158 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004159 throw new IllegalArgumentException(
4160 "Tried to get provisioning for MmTel capability '" + capability
4161 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 }
4163 }
4164
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
4170 @Override
4171 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4172 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4173 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4174 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4175 }
4176 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4177 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4178 return (provisionedBits & capability) > 0;
4179 }
4180
4181 @Override
4182 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4183 boolean isProvisioned) {
4184 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4185 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4186 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4187 }
4188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4189 "setProvisioningStatusForCapability");
4190 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4191 // If the current provisioning status for capability already matches isProvisioned,
4192 // do nothing.
4193 if (((provisionedBits & capability) > 0) == isProvisioned) {
4194 return;
4195 }
4196 if (isProvisioned) {
4197 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4198 } else {
4199 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4200 }
4201 }
4202
4203 /**
4204 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4205 * technology. The bitfield should mirror the bitfield defined by
4206 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4207 */
4208 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4209 String key = getMmTelProvisioningKey(subId, tech);
4210 // Default is no capabilities are provisioned.
4211 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4212 }
4213
4214 /**
4215 * Sets the MmTel capability provisioning bitfield (defined by
4216 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4217 * technology specified.
4218 *
4219 * Note: This is a synchronous command and should not be called on UI thread.
4220 */
4221 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4222 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4223 String key = getMmTelProvisioningKey(subId, tech);
4224 editor.putInt(key, newField);
4225 editor.commit();
4226 }
4227
4228 private static String getMmTelProvisioningKey(int subId, int tech) {
4229 // resulting key is provision_ims_mmtel_{subId}_{tech}
4230 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4231 }
4232
4233 /**
4234 * Query CarrierConfig to see if the specified capability requires provisioning for the
4235 * carrier associated with the subscription id.
4236 */
4237 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4238 int capability) {
4239 CarrierConfigManager configManager = new CarrierConfigManager(context);
4240 PersistableBundle c = configManager.getConfigForSubId(subId);
4241 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004242 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004243 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4244 false);
4245 boolean requireVoiceVtProvisioning = c.getBoolean(
4246 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4247
4248 // First check to make sure that the capability requires provisioning.
4249 switch (capability) {
4250 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4251 // intentional fallthrough
4252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4253 if (requireVoiceVtProvisioning) {
4254 // Voice and Video requires provisioning
4255 return true;
4256 }
4257 break;
4258 }
4259 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4260 if (requireUtProvisioning) {
4261 // UT requires provisioning
4262 return true;
4263 }
4264 break;
4265 }
4266 }
4267 return false;
4268 }
4269
allenwtsu99c623b2020-01-03 18:24:23 +08004270 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4271 int capability) {
4272 CarrierConfigManager configManager = new CarrierConfigManager(context);
4273 PersistableBundle c = configManager.getConfigForSubId(subId);
4274
4275 boolean requireRcsProvisioning = c.getBoolean(
4276 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4277
4278 // First check to make sure that the capability requires provisioning.
4279 switch (capability) {
4280 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4281 // intentional fallthrough
4282 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4283 if (requireRcsProvisioning) {
4284 // OPTION or PRESENCE requires provisioning
4285 return true;
4286 }
4287 break;
4288 }
4289 }
4290 return false;
4291 }
4292
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004293 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004294 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4296 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4297 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004298 enforceReadPrivilegedPermission("getImsProvisioningInt");
4299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004302 int slotId = getSlotIndex(subId);
4303 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4304 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4305 + subId + "' for key:" + key);
4306 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4307 }
4308 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004309 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004310 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4311 + subId + "' for key:" + key);
4312 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
4318 @Override
4319 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004320 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4321 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4322 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004323 enforceReadPrivilegedPermission("getImsProvisioningString");
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004327 int slotId = getSlotIndex(subId);
4328 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4329 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4330 + subId + "' for key:" + key);
4331 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4332 }
4333 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004334 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4336 + subId + "' for key:" + key);
4337 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
4343 @Override
4344 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004345 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4346 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4347 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4349 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 int slotId = getSlotIndex(subId);
4354 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4355 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4356 + subId + "' for key:" + key);
4357 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4358 }
4359 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4362 + "' for key:" + key);
4363 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
4370 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4372 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4373 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4375 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004379 int slotId = getSlotIndex(subId);
4380 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4381 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4382 + subId + "' for key:" + key);
4383 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4384 }
4385 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004386 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004387 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4388 + "' for key:" + key);
4389 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
4393 }
4394
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 int slotId = SubscriptionManager.getSlotIndex(subId);
4397 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4399 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004400 }
4401 return slotId;
4402 }
4403
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004404 private int getSlotIndex(int subId) {
4405 int slotId = SubscriptionManager.getSlotIndex(subId);
4406 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4407 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4408 }
4409 return slotId;
4410 }
4411
Wink Saville36469e72014-06-11 15:17:00 -07004412 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004413 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004414 */
4415 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004416 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4417 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004418 final int targetSdk = getTargetSdk(callingPackage);
4419 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004420 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004421 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004422 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004423 mApp, subId, callingPackage, callingFeatureId,
4424 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004425 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4426 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 final Phone phone = getPhone(subId);
4431 if (phone != null) {
4432 return phone.getServiceState().getDataNetworkType();
4433 } else {
4434 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4435 }
4436 } finally {
4437 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004439 }
4440
4441 /**
4442 * Returns the data network type
4443 */
4444 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004445 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4446 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4447 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004448 }
4449
4450 /**
4451 * Returns the data network type for a subId
4452 */
4453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004454 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4455 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004457 mApp, subId, callingPackage, callingFeatureId,
4458 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004459 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4460 }
4461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 final Phone phone = getPhone(subId);
4465 if (phone != null) {
4466 return phone.getServiceState().getDataNetworkType();
4467 } else {
4468 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4469 }
4470 } finally {
4471 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004473 }
4474
4475 /**
Wink Saville36469e72014-06-11 15:17:00 -07004476 * Returns the Voice network type for a subId
4477 */
4478 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004479 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4480 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004482 mApp, subId, callingPackage, callingFeatureId,
4483 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004484 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4485 }
4486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
4489 final Phone phone = getPhone(subId);
4490 if (phone != null) {
4491 return phone.getServiceState().getVoiceNetworkType();
4492 } else {
4493 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4494 }
4495 } finally {
4496 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004498 }
4499
4500 /**
4501 * @return true if a ICC card is present
4502 */
4503 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004504 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004505 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4506 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004507 }
4508
4509 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004510 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004511 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004512 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004513 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
4516 final Phone phone = PhoneFactory.getPhone(slotIndex);
4517 if (phone != null) {
4518 return phone.getIccCard().hasIccCard();
4519 } else {
4520 return false;
4521 }
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004525 }
4526
4527 /**
4528 * Return if the current radio is LTE on CDMA. This
4529 * is a tri-state return value as for a period of time
4530 * the mode may be unknown.
4531 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004532 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004533 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004534 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004535 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004536 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004537 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4538 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4539 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004540 }
4541
Sanket Padawe356d7632015-06-22 14:03:32 -07004542 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004543 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4544 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004545 try {
4546 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4547 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004548 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4549 }
4550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 final Phone phone = getPhone(subId);
4554 if (phone == null) {
4555 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4556 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004557 return TelephonyProperties.lte_on_cdma_device()
4558 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 }
4560 } finally {
4561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004562 }
Wink Saville36469e72014-06-11 15:17:00 -07004563 }
4564
Wink Saville36469e72014-06-11 15:17:00 -07004565 /**
4566 * {@hide}
4567 * Returns Default subId, 0 in the case of single standby.
4568 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004569 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004570 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004571 }
4572
Shishir Agrawala9f32182016-04-12 12:00:16 -07004573 private int getSlotForDefaultSubscription() {
4574 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4575 }
4576
Wink Savilleb564aae2014-10-23 10:18:09 -07004577 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004578 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004579 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004580
Pengquan Menge92a50d2018-09-21 15:54:48 -07004581 private boolean isActiveSubscription(int subId) {
4582 return mSubscriptionController.isActiveSubId(subId);
4583 }
4584
Ihab Awadf2177b72013-11-25 13:33:23 -08004585 /**
4586 * @see android.telephony.TelephonyManager.WifiCallingChoices
4587 */
4588 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004591 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4593 getWhenToMakeWifiCallsDefaultPreference());
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004597 }
4598
4599 /**
4600 * @see android.telephony.TelephonyManager.WifiCallingChoices
4601 */
4602 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 final long identity = Binder.clearCallingIdentity();
4604 try {
4605 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004606 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004611 }
4612
Sailesh Nepald1e68152013-12-12 19:08:02 -08004613 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004614 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004615 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004616 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004617
Jordan Liu4c733742019-02-28 12:03:40 -08004618 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4619 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4620 if (phoneId == -1) {
4621 throw new IllegalArgumentException("Given slot index: " + slotIndex
4622 + " does not correspond to an active phone");
4623 }
4624 return PhoneFactory.getPhone(phoneId);
4625 }
4626
Shishir Agrawal566b7612013-10-28 14:41:00 -07004627 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004628 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4629 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4631 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004633 if (DBG) {
4634 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4635 }
4636 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4637 p2);
4638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004639
Jordan Liu4c733742019-02-28 12:03:40 -08004640
4641 @Override
4642 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4643 int slotIndex, String callingPackage, String aid, int p2) {
4644 enforceModifyPermission();
4645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4646 if (DBG) {
4647 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4648 }
4649 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4650 callingPackage, aid, p2);
4651 }
4652
4653 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4654 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 if (TextUtils.equals(ISDR_AID, aid)) {
4658 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004659 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4660 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 if (bestComponent == null
4662 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4663 loge("The calling package is not allowed to access ISD-R.");
4664 throw new SecurityException(
4665 "The calling package is not allowed to access ISD-R.");
4666 }
Derek Tan740e1672017-06-27 14:56:27 -07004667 }
Derek Tan740e1672017-06-27 14:56:27 -07004668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004670 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4671 null /* workSource */);
4672 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 return response;
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004677 }
4678
4679 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004680 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4682 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004683 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4684 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004686
Jordan Liu4c733742019-02-28 12:03:40 -08004687 @Override
4688 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4689 enforceModifyPermission();
4690 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4691 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4692 channel);
4693 }
4694
4695 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 final long identity = Binder.clearCallingIdentity();
4697 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 if (channel < 0) {
4699 return false;
4700 }
Jordan Liu4c733742019-02-28 12:03:40 -08004701 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4702 null /* workSource */);
4703 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 return success;
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004707 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004708 }
4709
4710 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004711 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004712 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4714 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004715 if (DBG) {
4716 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4717 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4718 + p3 + " data=" + data);
4719 }
4720 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4721 command, p1, p2, p3, data);
4722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004723
Jordan Liu4c733742019-02-28 12:03:40 -08004724 @Override
4725 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4726 int command, int p1, int p2, int p3, String data) {
4727 enforceModifyPermission();
4728 if (DBG) {
4729 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4730 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4731 + p3 + " data=" + data);
4732 }
4733 return iccTransmitApduLogicalChannelWithPermission(
4734 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4735 data);
4736 }
4737
4738 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4739 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004742 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 return "";
4744 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004747 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4748 null /* workSource */);
4749 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 // Append the returned status code to the end of the response payload.
4752 String s = Integer.toHexString(
4753 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4754 if (response.payload != null) {
4755 s = IccUtils.bytesToHexString(response.payload) + s;
4756 }
4757 return s;
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004760 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004761 }
Jake Hambye994d462014-02-03 13:10:13 -08004762
Evan Charltonc66da362014-05-16 14:06:40 -07004763 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004764 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4765 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4767 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004769 if (DBG) {
4770 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4771 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4772 }
4773 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4774 cla, command, p1, p2, p3, data);
4775 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004776
Jordan Liu4c733742019-02-28 12:03:40 -08004777 @Override
4778 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4779 int command, int p1, int p2, int p3, String data) {
4780 enforceModifyPermission();
4781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4782 if (DBG) {
4783 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4784 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4785 + " data=" + data);
4786 }
4787
4788 return iccTransmitApduBasicChannelWithPermission(
4789 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4790 p2, p3, data);
4791 }
4792
4793 // open APDU basic channel assuming the caller has sufficient permissions
4794 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4795 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4799 && TextUtils.equals(ISDR_AID, data)) {
4800 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004801 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4802 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 if (bestComponent == null
4804 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4805 loge("The calling package is not allowed to select ISD-R.");
4806 throw new SecurityException(
4807 "The calling package is not allowed to select ISD-R.");
4808 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004809 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004812 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4813 null /* workSource */);
4814 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 // Append the returned status code to the end of the response payload.
4817 String s = Integer.toHexString(
4818 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4819 if (response.payload != null) {
4820 s = IccUtils.bytesToHexString(response.payload) + s;
4821 }
4822 return s;
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004825 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004826 }
4827
4828 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004829 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004830 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4832 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 if (DBG) {
4837 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4838 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4839 }
4840
4841 IccIoResult response =
4842 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4843 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4844 subId);
4845
4846 if (DBG) {
4847 log("Exchange SIM_IO [R]" + response);
4848 }
4849
4850 byte[] result = null;
4851 int length = 2;
4852 if (response.payload != null) {
4853 length = 2 + response.payload.length;
4854 result = new byte[length];
4855 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4856 } else {
4857 result = new byte[length];
4858 }
4859
4860 result[length - 1] = (byte) response.sw2;
4861 result[length - 2] = (byte) response.sw1;
4862 return result;
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004865 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004866 }
4867
Nathan Haroldb3014052017-01-25 15:57:32 -08004868 /**
4869 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4870 * on a particular subscription
4871 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004872 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4873 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004875 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004876 return null;
4877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878
4879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 if (appType != TelephonyManager.APPTYPE_USIM
4882 && appType != TelephonyManager.APPTYPE_SIM) {
4883 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4884 return null;
4885 }
4886 Object response = sendRequest(
4887 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4888 if (response instanceof String[]) {
4889 return (String[]) response;
4890 }
yincheng zhaod698b842019-09-06 17:06:54 -07004891 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004893 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004896 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004897 }
4898
yincheng zhaod698b842019-09-06 17:06:54 -07004899 /**
4900 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4901 * subscription.
4902 *
4903 * @param subId the id of the subscription.
4904 * @param appType the uicc app type, must be USIM or SIM.
4905 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4906 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004907 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004908 * @return number of fplmns that is successfully written to the SIM.
4909 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004910 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4911 String callingFeatureId) {
4912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4913 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004914 if (DBG) logv("no permissions for setForbiddenplmns");
4915 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4916 }
4917 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4918 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4919 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4920 }
4921 if (fplmns == null) {
4922 throw new IllegalArgumentException("Fplmn List provided is null");
4923 }
4924 for (String fplmn : fplmns) {
4925 if (!CellIdentity.isValidPlmn(fplmn)) {
4926 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4927 }
4928 }
4929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 Object response = sendRequest(
4932 CMD_SET_FORBIDDEN_PLMNS,
4933 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4934 subId);
4935 return (int) response;
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
4939 }
4940
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004941 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004942 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4944 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4949 if (response.payload == null) {
4950 return "";
4951 }
Evan Charltonc66da362014-05-16 14:06:40 -07004952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 // Append the returned status code to the end of the response payload.
4954 String s = Integer.toHexString(
4955 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4956 s = IccUtils.bytesToHexString(response.payload) + s;
4957 return s;
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
Evan Charltonc66da362014-05-16 14:06:40 -07004961 }
4962
Jake Hambye994d462014-02-03 13:10:13 -08004963 /**
4964 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4965 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4966 *
4967 * @param itemID the ID of the item to read
4968 * @return the NV item as a String, or null on error.
4969 */
4970 @Override
4971 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004979 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4981 return value;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
Jake Hambye994d462014-02-03 13:10:13 -08004985 }
4986
4987 /**
4988 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4989 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4990 *
4991 * @param itemID the ID of the item to read
4992 * @param itemValue the value to write, as a String
4993 * @return true on success; false on any failure
4994 */
4995 @Override
4996 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4999 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000
5001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5004 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005005 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5007 return success;
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Jake Hambye994d462014-02-03 13:10:13 -08005011 }
5012
5013 /**
5014 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5015 * Used for device configuration by some CDMA operators.
5016 *
5017 * @param preferredRoamingList byte array containing the new PRL
5018 * @return true on success; false on any failure
5019 */
5020 @Override
5021 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5028 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5029 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5030 return success;
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Jake Hambye994d462014-02-03 13:10:13 -08005034 }
5035
5036 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005037 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005038 * Used for device configuration by some CDMA operators.
5039 *
chen xu6dac5ab2018-10-26 17:39:23 -07005040 * @param slotIndex - device slot.
5041 *
Jake Hambye994d462014-02-03 13:10:13 -08005042 * @return true on success; false on any failure
5043 */
5044 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005045 public boolean resetModemConfig(int slotIndex) {
5046 Phone phone = PhoneFactory.getPhone(slotIndex);
5047 if (phone != null) {
5048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5049 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050
chen xu6dac5ab2018-10-26 17:39:23 -07005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5054 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5055 return success;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 }
chen xu6dac5ab2018-10-26 17:39:23 -07005060 return false;
5061 }
5062
5063 /**
5064 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5065 *
5066 * @param slotIndex - device slot.
5067 *
5068 * @return true on success; false on any failure
5069 */
5070 @Override
5071 public boolean rebootModem(int slotIndex) {
5072 Phone phone = PhoneFactory.getPhone(slotIndex);
5073 if (phone != null) {
5074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5075 mApp, phone.getSubId(), "rebootModem");
5076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5080 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5081 return success;
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
5085 }
5086 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005087 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005088
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005089 public String[] getPcscfAddress(String apnType, String callingPackage,
5090 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005091 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5093 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005094 return new String[0];
5095 }
5096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005099 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Wink Saville36469e72014-06-11 15:17:00 -07005103 }
5104
Brad Ebinger51f743a2017-01-23 13:50:20 -08005105 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005106 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5107 * {@link #disableIms(int)}.
5108 * @param slotIndex device slot.
5109 */
5110 public void resetIms(int slotIndex) {
5111 enforceModifyPermission();
5112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 if (mImsResolver == null) {
5116 // may happen if the does not support IMS.
5117 return;
5118 }
5119 mImsResolver.disableIms(slotIndex);
5120 mImsResolver.enableIms(slotIndex);
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
5124 }
5125
5126 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005127 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5128 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005129 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005130 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
5134 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005135 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005136 // may happen if the device does not support IMS.
5137 return;
5138 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005139 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005143 }
5144
5145 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005146 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5147 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005148 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005149 public void disableIms(int slotId) {
5150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151
5152 final long identity = Binder.clearCallingIdentity();
5153 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005154 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005155 // may happen if the device does not support IMS.
5156 return;
5157 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005158 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005162 }
5163
5164 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005165 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5166 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005167 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005168 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005169 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
5173 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005174 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005175 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5176 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005177 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005178 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005182 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005183 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005184 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5185 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005186 @Override
5187 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005188 enforceModifyPermission();
5189
5190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005193 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
5197 }
5198
5199 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005200 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005201 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005202 */
5203 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005208 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005209 // may happen if the device does not support IMS.
5210 return null;
5211 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005212 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005216 }
5217
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005218 /**
5219 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005220 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005221 */
5222 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005227 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005228 // may happen if the device does not support IMS.
5229 return null;
5230 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005231 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005235 }
5236
Brad Ebinger884c07b2018-02-15 16:17:40 -08005237 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005238 * Sets the ImsService Package Name that Telephony will bind to.
5239 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005240 * @param slotIndex the slot ID that the ImsService should bind for.
5241 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005242 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005243 * @param featureTypes An integer array of feature types associated with a packageName.
5244 * @param packageName The name of the package that the current configuration will be replaced
5245 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005246 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005247 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005248 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5249 int[] featureTypes, String packageName) {
5250 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5253 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005254 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 final long identity = Binder.clearCallingIdentity();
5257 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005258 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005259 // may happen if the device does not support IMS.
5260 return false;
5261 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005262 Map<Integer, String> featureConfig = new HashMap<>();
5263 for (int featureType : featureTypes) {
5264 featureConfig.put(featureType, packageName);
5265 }
5266 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5267 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005271 }
5272
5273 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005274 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005275 *
5276 * @param slotId The slot that the ImsService is associated with.
5277 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5278 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005279 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005280 * @return the package name of the ImsService configuration.
5281 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005282 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5283 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005284 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005285 TelephonyPermissions
5286 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5287 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5288 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005292 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005293 // may happen if the device does not support IMS.
5294 return "";
5295 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005296 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005297 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5298 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005302 }
5303
Brad Ebinger77b832e2019-10-17 17:03:22 -07005304 /**
5305 * Get the MmTelFeature state associated with the requested subscription id.
5306 * @param subId The subscription that the MmTelFeature is associated with.
5307 * @param callback A callback with an integer containing the
5308 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5309 */
5310 @Override
5311 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5312 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5313 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5315 "IMS not available on device.");
5316 }
5317 final long token = Binder.clearCallingIdentity();
5318 try {
5319 int slotId = getSlotIndex(subId);
5320 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5321 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5322 + subId + "'");
5323 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5324 }
5325 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5326 try {
5327 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5328 } catch (RemoteException e) {
5329 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5330 + "Ignore");
5331 }
5332 });
5333 } finally {
5334 Binder.restoreCallingIdentity(token);
5335 }
5336 }
5337
Wink Saville36469e72014-06-11 15:17:00 -07005338 public void setImsRegistrationState(boolean registered) {
5339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340
5341 final long identity = Binder.clearCallingIdentity();
5342 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005343 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 } finally {
5345 Binder.restoreCallingIdentity(identity);
5346 }
Wink Saville36469e72014-06-11 15:17:00 -07005347 }
5348
5349 /**
Stuart Scott54788802015-03-30 13:18:01 -07005350 * Set the network selection mode to automatic.
5351 *
5352 */
5353 @Override
5354 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5356 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357
5358 final long identity = Binder.clearCallingIdentity();
5359 try {
shilufc958392020-01-20 11:36:01 -08005360 if (!isActiveSubscription(subId)) {
5361 return;
5362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5364 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
Stuart Scott54788802015-03-30 13:18:01 -07005368 }
5369
Jack Yud10cdd42020-09-28 20:28:01 -07005370 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005371 * Ask the radio to connect to the input network and change selection mode to manual.
5372 *
5373 * @param subId the id of the subscription.
5374 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5375 * the operator to attach to.
5376 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5377 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5378 * normal network selection next time.
5379 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005380 */
5381 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005382 public boolean setNetworkSelectionModeManual(
5383 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5385 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005386
5387 if (!isActiveSubscription(subId)) {
5388 return false;
5389 }
5390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005393 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005395 if (DBG) {
5396 log("setNetworkSelectionModeManual: subId: " + subId
5397 + " operator: " + operatorInfo);
5398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005403 }
shilu84f6e8b2019-12-19 13:58:01 -08005404 /**
5405 * Get the manual network selection
5406 *
5407 * @param subId the id of the subscription.
5408 *
5409 * @return the previously saved user selected PLMN
5410 */
5411 @Override
5412 public String getManualNetworkSelectionPlmn(int subId) {
5413 TelephonyPermissions
5414 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5415 mApp, subId, "getManualNetworkSelectionPlmn");
5416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 if (!isActiveSubscription(subId)) {
5420 return "";
5421 }
5422
5423 final Phone phone = getPhone(subId);
5424 if (phone == null) {
5425 return "";
5426 }
5427 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5428 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5429 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
5432 }
5433 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005434
5435 /**
5436 * Scans for available networks.
5437 */
5438 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005439 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5440 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5442 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005443 LocationAccessPolicy.LocationPermissionResult locationResult =
5444 LocationAccessPolicy.checkLocationPermission(mApp,
5445 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5446 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005447 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005448 .setCallingPid(Binder.getCallingPid())
5449 .setCallingUid(Binder.getCallingUid())
5450 .setMethod("getCellNetworkScanResults")
5451 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5452 .build());
5453 switch (locationResult) {
5454 case DENIED_HARD:
5455 throw new SecurityException("Not allowed to access scan results -- location");
5456 case DENIED_SOFT:
5457 return null;
5458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
Pengquan Menga1bb6272018-09-06 09:59:22 -07005460 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 try {
5462 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005463 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005468 }
5469
5470 /**
sqian80370722020-01-29 15:02:51 -08005471 * Get the call forwarding info, given the call forwarding reason.
5472 */
5473 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005474 public void getCallForwarding(int subId, int callForwardingReason,
5475 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005476 enforceReadPrivilegedPermission("getCallForwarding");
5477 long identity = Binder.clearCallingIdentity();
5478 try {
5479 if (DBG) {
5480 log("getCallForwarding: subId " + subId
5481 + " callForwardingReason" + callForwardingReason);
5482 }
Hall Liua1acea22020-09-18 19:04:59 -07005483
5484 Phone phone = getPhone(subId);
5485 if (phone == null) {
5486 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005487 callback.onError(
5488 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005489 } catch (RemoteException e) {
5490 // ignore
5491 }
5492 return;
5493 }
5494
5495 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5496 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5497 @Override
5498 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5499 try {
5500 callback.onCallForwardingInfoAvailable(info);
5501 } catch (RemoteException e) {
5502 // ignore
5503 }
5504 }
5505
5506 @Override
5507 public void onError(int error) {
5508 try {
5509 callback.onError(error);
5510 } catch (RemoteException e) {
5511 // ignore
5512 }
5513 }
5514 });
5515 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
5519 }
5520
5521 /**
5522 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5523 * reason, the number to forward, and the timeout before the forwarding is attempted.
5524 */
5525 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005526 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5527 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005528 enforceModifyPermission();
5529 long identity = Binder.clearCallingIdentity();
5530 try {
5531 if (DBG) {
5532 log("setCallForwarding: subId " + subId
5533 + " callForwardingInfo" + callForwardingInfo);
5534 }
Hall Liua1acea22020-09-18 19:04:59 -07005535
5536 Phone phone = getPhone(subId);
5537 if (phone == null) {
5538 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005539 callback.accept(
5540 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005541 } catch (RemoteException e) {
5542 // ignore
5543 }
5544 return;
5545 }
5546
5547 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5548 FunctionalUtils.ignoreRemoteException(callback::accept));
5549
5550 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
5554 }
5555
5556 /**
Hall Liua1acea22020-09-18 19:04:59 -07005557 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005558 */
5559 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005560 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005561 enforceReadPrivilegedPermission("getCallForwarding");
5562 long identity = Binder.clearCallingIdentity();
5563 try {
Hall Liua1acea22020-09-18 19:04:59 -07005564
5565 Phone phone = getPhone(subId);
5566 if (phone == null) {
5567 try {
5568 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5569 } catch (RemoteException e) {
5570 // ignore
5571 }
5572 return;
5573 }
5574
5575 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5576
sqian80370722020-01-29 15:02:51 -08005577 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005578 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
5582 }
5583
5584 /**
Hall Liua1acea22020-09-18 19:04:59 -07005585 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005586 */
5587 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005588 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005589 enforceModifyPermission();
5590 long identity = Binder.clearCallingIdentity();
5591 try {
Hall Liua1acea22020-09-18 19:04:59 -07005592 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5593
5594 Phone phone = getPhone(subId);
5595 if (phone == null) {
5596 try {
5597 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5598 } catch (RemoteException e) {
5599 // ignore
5600 }
5601 return;
5602 }
5603
5604 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5605 FunctionalUtils.ignoreRemoteException(callback::accept));
5606
5607 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
5611 }
5612
5613 /**
yinxub1bed742017-04-17 11:45:04 -07005614 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005615 *
yinxub1bed742017-04-17 11:45:04 -07005616 * @param subId id of the subscription
5617 * @param request contains the radio access networks with bands/channels to scan
5618 * @param messenger callback messenger for scan results or errors
5619 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005620 * @return the id of the requested scan which can be used to stop the scan.
5621 */
5622 @Override
5623 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005624 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005627 LocationAccessPolicy.LocationPermissionResult locationResult =
5628 LocationAccessPolicy.checkLocationPermission(mApp,
5629 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5630 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005631 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005632 .setCallingPid(Binder.getCallingPid())
5633 .setCallingUid(Binder.getCallingUid())
5634 .setMethod("requestNetworkScan")
5635 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5636 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005637 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005638 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5639 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005640 if (e != null) {
5641 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5642 throw e;
5643 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005644 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005645 return TelephonyScanManager.INVALID_SCAN_ID;
5646 }
5647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 }
Hall Liu912dfd32019-04-25 14:02:26 -07005649 int callingUid = Binder.getCallingUid();
5650 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005651 final long identity = Binder.clearCallingIdentity();
5652 try {
5653 return mNetworkScanRequestTracker.startNetworkScan(
5654 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005655 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
yinxu504e1392017-04-12 16:03:22 -07005659 }
5660
Hall Liub2ac8ef2019-02-28 15:56:23 -08005661 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005662 NetworkScanRequest request, int subId, String callingPackage) {
5663 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005664 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5665 boolean hasNetworkScanPermission =
5666 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5667 == PERMISSION_GRANTED;
5668
5669 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5670 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5671 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005672 }
5673
5674 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5675 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005676 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5677 return new SecurityException("Specific channels must not be"
5678 + " scanned without location access.");
5679 }
5680 }
5681 }
5682
Hall Liub2ac8ef2019-02-28 15:56:23 -08005683 return null;
5684 }
5685
yinxu504e1392017-04-12 16:03:22 -07005686 /**
5687 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005688 *
5689 * @param subId id of the subscription
5690 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005691 */
5692 @Override
5693 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
Hall Liu912dfd32019-04-25 14:02:26 -07005697 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 final long identity = Binder.clearCallingIdentity();
5699 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005700 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
yinxu504e1392017-04-12 16:03:22 -07005704 }
5705
5706 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005707 * Get the calculated preferred network type.
5708 * Used for debugging incorrect network type.
5709 *
5710 * @return the preferred network type, defined in RILConstants.java.
5711 */
5712 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005713 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 final Phone defaultPhone = getDefaultPhone();
5715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005716 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005717 return RILConstants.PREFERRED_NETWORK_MODE;
5718 }
5719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Junda Liu84d15a22014-07-02 11:21:04 -07005727 }
5728
5729 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005730 * Get the preferred network type.
5731 * Used for device configuration by some CDMA operators.
5732 *
5733 * @return the preferred network type, defined in RILConstants.java.
5734 */
5735 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005736 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005737 TelephonyPermissions
5738 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5739 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 if (DBG) log("getPreferredNetworkType");
5744 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5745 int networkType = (result != null ? result[0] : -1);
5746 if (DBG) log("getPreferredNetworkType: " + networkType);
5747 return networkType;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005751 }
5752
5753 /**
5754 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005755 *
5756 * @param networkType the preferred network type, defined in RILConstants.java.
5757 * @return true on success; false on any failure.
5758 */
5759 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005760 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5762 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005766 Settings.Global.putInt(mApp.getContentResolver(),
5767 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005768
5769 Boolean success = (Boolean) sendRequest(
5770 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5771 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5772 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005775 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005776 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005777
5778 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005779 * Get the allowed network types that store in the telephony provider.
5780 *
5781 * @param subId the id of the subscription.
5782 * @return allowedNetworkTypes the allowed network types.
5783 */
5784 @Override
5785 public long getAllowedNetworkTypes(int subId) {
5786 TelephonyPermissions
5787 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5788 mApp, subId, "getAllowedNetworkTypes");
5789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 return SubscriptionManager.getLongSubscriptionProperty(
5793 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
5797 }
5798
5799 /**
5800 * Set the allowed network types.
5801 *
5802 * @param subId the id of the subscription.
5803 * @param allowedNetworkTypes the allowed network types.
5804 * @return true on success; false on any failure.
5805 */
5806 @Override
5807 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5809 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005810
calvinpan089c2a62020-03-12 14:17:55 +08005811 SubscriptionManager.setSubscriptionProperty(subId,
5812 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5813 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005814
calvinpan089c2a62020-03-12 14:17:55 +08005815 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5816 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5817 RILConstants.PREFERRED_NETWORK_MODE);
5818 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005819 }
5820
5821 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005822 * Get the allowed network types for certain reason.
5823 *
5824 * @param subId the id of the subscription.
5825 * @param reason the reason the allowed network type change is taking place
5826 * @return the allowed network types.
5827 */
5828 @Override
5829 public long getAllowedNetworkTypesForReason(int subId,
5830 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5831 TelephonyPermissions
5832 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5833 mApp, subId, "getAllowedNetworkTypesForReason");
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
5840 }
5841
5842 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005843 * Enable/Disable E-UTRA-NR Dual Connectivity
5844 * @param subId subscription id of the sim card
5845 * @param nrDualConnectivityState expected NR dual connectivity state
5846 * This can be passed following states
5847 * <ol>
5848 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5849 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5850 * <li>Disable NR dual connectivity and force secondary cell to be released
5851 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5852 * </ol>
5853 * @return operation result.
5854 */
5855 @Override
5856 public int setNrDualConnectivityState(int subId,
5857 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5859 mApp, subId, "enableNRDualConnectivity");
5860 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
5863 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5864 nrDualConnectivityState, subId,
5865 workSource);
5866 if (DBG) log("enableNRDualConnectivity result: " + result);
5867 return result;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 /**
5874 * Is E-UTRA-NR Dual Connectivity enabled
5875 * @return true if dual connectivity is enabled else false
5876 */
5877 @Override
5878 public boolean isNrDualConnectivityEnabled(int subId) {
5879 TelephonyPermissions
5880 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5881 mApp, subId, "isNRDualConnectivityEnabled");
5882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5886 null, subId, workSource);
5887 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5888 return isEnabled;
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
5892 }
5893
5894 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07005895 * get carrier bandwidth per primary and secondary carrier
5896 * @param subId subscription id of the sim card
5897 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5898 */
5899 @Override
5900 public CarrierBandwidth getCarrierBandwidth(int subId) {
5901 TelephonyPermissions
5902 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5903 mApp, subId, "isNRDualConnectivityEnabled");
5904 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 CarrierBandwidth carrierBandwidth =
5908 getPhoneFromSubId(subId).getCarrierBandwidth();
5909 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5910 return carrierBandwidth;
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
5914 }
5915
5916 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005917 * Get the effective allowed network types on the device.
5918 * This API will return an intersection of allowed network types for all reasons,
5919 * including the configuration done through setAllowedNetworkTypes
5920 *
5921 * @param subId the id of the subscription.
5922 * @return the allowed network types
5923 */
5924 @Override
5925 public long getEffectiveAllowedNetworkTypes(int subId) {
5926 TelephonyPermissions
5927 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5928 mApp, subId, "getEffectiveAllowedNetworkTypes");
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
5935 }
5936
5937 /**
5938 * Set the allowed network types of the device and
5939 * provide the reason triggering the allowed network change.
5940 *
5941 * @param subId the id of the subscription.
5942 * @param reason the reason the allowed network type change is taking place
5943 * @param allowedNetworkTypes the allowed network types.
5944 * @return true on success; false on any failure.
5945 */
5946 @Override
5947 public boolean setAllowedNetworkTypesForReason(int subId,
5948 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5950 mApp, subId, "setAllowedNetworkTypesForReason");
5951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5954 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5955 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5956 RILConstants.PREFERRED_NETWORK_MODE);
5957 return setPreferredNetworkType(subId, preferredNetworkMode);
5958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
5961 }
5962
5963 /**
Miaoa84611c2019-03-15 09:21:10 +08005964 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005965 *
Miaoa84611c2019-03-15 09:21:10 +08005966 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005967 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005968 * @hide
5969 */
5970 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005971 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005972 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005974 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 try {
Miaoa84611c2019-03-15 09:21:10 +08005976 if (phone != null) {
5977 return phone.hasMatchedTetherApnSetting();
5978 } else {
5979 return false;
5980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005983 }
Junda Liu475951f2014-11-07 16:45:03 -08005984 }
5985
5986 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005987 * Enable or disable always reporting signal strength changes from radio.
5988 *
5989 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5990 */
5991 @Override
5992 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5993 enforceModifyPermission();
5994 enforceSystemCaller();
5995
5996 final long identity = Binder.clearCallingIdentity();
5997 final Phone phone = getPhone(subId);
5998 try {
5999 if (phone != null) {
6000 if (DBG) {
6001 log("setAlwaysReportSignalStrength: subId=" + subId
6002 + " isEnable=" + isEnable);
6003 }
6004 phone.setAlwaysReportSignalStrength(isEnable);
6005 } else {
6006 loge("setAlwaysReportSignalStrength: no phone found for subId="
6007 + subId);
6008 }
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
6012 }
6013
6014 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006015 * Get the user enabled state of Mobile Data.
6016 *
6017 * TODO: remove and use isUserDataEnabled.
6018 * This can't be removed now because some vendor codes
6019 * calls through ITelephony directly while they should
6020 * use TelephonyManager.
6021 *
6022 * @return true on enabled
6023 */
6024 @Override
6025 public boolean getDataEnabled(int subId) {
6026 return isUserDataEnabled(subId);
6027 }
6028
6029 /**
6030 * Get whether mobile data is enabled per user setting.
6031 *
6032 * There are other factors deciding whether mobile data is actually enabled, but they are
6033 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006034 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006035 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006036 *
6037 * @return {@code true} if data is enabled else {@code false}
6038 */
6039 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006040 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006041 try {
6042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6043 null);
6044 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6046 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 int phoneId = mSubscriptionController.getPhoneId(subId);
6052 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6053 Phone phone = PhoneFactory.getPhone(phoneId);
6054 if (phone != null) {
6055 boolean retVal = phone.isUserDataEnabled();
6056 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6057 return retVal;
6058 } else {
6059 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6060 return false;
6061 }
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006064 }
6065 }
6066
6067 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006068 * Checks if the device is capable of mobile data by considering whether whether the
6069 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6070 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006071 *
Shuo Qian985d1232020-01-08 14:30:06 -08006072 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006073 */
6074 @Override
6075 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006076 try {
6077 try {
6078 mApp.enforceCallingOrSelfPermission(
6079 android.Manifest.permission.ACCESS_NETWORK_STATE,
6080 null);
6081 } catch (Exception e) {
6082 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6083 "isDataEnabled");
6084 }
6085 } catch (Exception e) {
6086 enforceReadPrivilegedPermission("isDataEnabled");
6087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 int phoneId = mSubscriptionController.getPhoneId(subId);
6092 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6093 Phone phone = PhoneFactory.getPhone(phoneId);
6094 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006095 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6097 return retVal;
6098 } else {
6099 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6100 return false;
6101 }
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006104 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006105 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006106
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006107 /**
6108 * Check if data is enabled for a specific reason
6109 * @param subId Subscription index
6110 * @param reason the reason the data enable change is taking place
6111 * @return {@code true} if the overall data is enabled; {@code false} if not.
6112 */
6113 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006114 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006115 @TelephonyManager.DataEnabledReason int reason) {
6116 try {
6117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6118 null);
6119 } catch (Exception e) {
6120 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006121 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006122 }
6123
6124
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 int phoneId = mSubscriptionController.getPhoneId(subId);
6128 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006129 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006130 + " reason=" + reason);
6131 }
6132 Phone phone = PhoneFactory.getPhone(phoneId);
6133 if (phone != null) {
6134 boolean retVal;
6135 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6136 retVal = phone.isUserDataEnabled();
6137 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006138 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006139 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006140 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006141 return retVal;
6142 } else {
6143 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006144 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006145 + subId + " retVal=false");
6146 }
6147 return false;
6148 }
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
6152 }
6153
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006154 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006155 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006156 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6157 // Skip the check if it's one of these special uids
6158 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6159 }
6160
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006161 //load access rules from carrier configs, and check those as well: b/139133814
6162 SubscriptionController subController = SubscriptionController.getInstance();
6163 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6164 || subController == null) return privilegeFromSim;
6165
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006166 PackageManager pkgMgr = phone.getContext().getPackageManager();
6167 String[] packages = pkgMgr.getPackagesForUid(uid);
6168
6169 final long identity = Binder.clearCallingIdentity();
6170 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006171 int subId = phone.getSubId();
6172 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6173 // A test override is in place for the privileges for this subId, so don't try to
6174 // read the subscription privileges.
6175 return privilegeFromSim;
6176 }
6177 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006178 SubscriptionManager subManager = (SubscriptionManager)
6179 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6180 for (String pkg : packages) {
6181 if (subManager.canManageSubscription(subInfo, pkg)) {
6182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6183 }
6184 }
6185 return privilegeFromSim;
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6192 String pkgName) {
6193 //load access rules from carrier configs, and check those as well: b/139133814
6194 SubscriptionController subController = SubscriptionController.getInstance();
6195 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6196 || subController == null) return privilegeFromSim;
6197
6198 final long identity = Binder.clearCallingIdentity();
6199 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006200 int subId = phone.getSubId();
6201 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6202 // A test override is in place for the privileges for this subId, so don't try to
6203 // read the subscription privileges.
6204 return privilegeFromSim;
6205 }
6206 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006207 SubscriptionManager subManager = (SubscriptionManager)
6208 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6209 return subManager.canManageSubscription(subInfo, pkgName)
6210 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006217 public int getCarrierPrivilegeStatus(int subId) {
6218 final Phone phone = getPhone(subId);
6219 if (phone == null) {
6220 loge("getCarrierPrivilegeStatus: Invalid subId");
6221 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6222 }
6223 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006224 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006225 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006226 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6227 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006228
6229 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6230 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006231 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006232 }
Junda Liu29340342014-07-10 15:23:27 -07006233
6234 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006235 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006236 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006237 final Phone phone = getPhone(subId);
6238 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006239 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006240 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6241 }
6242 UiccProfile profile =
6243 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6244 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006245 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006246 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6247 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006248 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006249 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006250 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006251 }
6252
6253 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006254 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6255 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006256 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006257 }
6258
6259 int phoneId = SubscriptionManager.getPhoneId(subId);
6260 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006261 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006262 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006263 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6264 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006265 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6266 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6267 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006268 }
6269
6270 @Override
6271 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006272 if (TextUtils.isEmpty(pkgName))
6273 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006274 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6275 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6276 UiccCard card = UiccController.getInstance().getUiccCard(i);
6277 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006278 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006279 continue;
6280 }
6281
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006282 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6283 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6284 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006285 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6286 break;
6287 }
6288 }
6289
6290 return result;
Junda Liu29340342014-07-10 15:23:27 -07006291 }
Derek Tan89e89d42014-07-08 17:00:10 -07006292
6293 @Override
Junda Liue64de782015-04-16 17:19:16 -07006294 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6295 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6296 loge("phoneId " + phoneId + " is not valid.");
6297 return null;
6298 }
6299 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006300 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006301 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006302 return null ;
6303 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006304 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006305 }
6306
Amith Yamasani6e118872016-02-19 12:53:51 -08006307 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006308 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006309 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006310 List<String> privilegedPackages = new ArrayList<>();
6311 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006312 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6313 // has UICC in that slot.
6314 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006315 if (card.hasCarrierPrivilegeRules()) {
6316 if (packages == null) {
6317 // Only check packages in user 0 for now
6318 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006319 PackageManager.MATCH_DISABLED_COMPONENTS
6320 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006321 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006322 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006323 }
6324 for (int p = packages.size() - 1; p >= 0; p--) {
6325 PackageInfo pkgInfo = packages.get(p);
6326 if (pkgInfo != null && pkgInfo.packageName != null
6327 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006328 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006329 privilegedPackages.add(pkgInfo.packageName);
6330 }
6331 }
6332 }
6333 }
6334 return privilegedPackages;
6335 }
6336
chen xuf7e9fe82019-05-09 19:31:02 -07006337 @Override
6338 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006339 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6340
6341 final long identity = Binder.clearCallingIdentity();
6342
chen xuf7e9fe82019-05-09 19:31:02 -07006343 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006344 try {
6345 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6346 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6347 }
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006350 }
6351 return privilegedPackages;
6352 }
6353
Wink Savilleb564aae2014-10-23 10:18:09 -07006354 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006355 final Phone phone = getPhone(subId);
6356 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006357 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006358 return null;
6359 }
6360 String iccId = card.getIccId();
6361 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006362 return null;
6363 }
6364 return iccId;
6365 }
6366
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006367 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006368 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6369 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006370 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006371 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 final String iccId = getIccId(subId);
6376 final Phone phone = getPhone(subId);
6377 if (phone == null) {
6378 return false;
6379 }
6380 final String subscriberId = phone.getSubscriberId();
6381
6382 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006383 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 + subscriberId + " to " + number);
6385 }
6386
6387 if (TextUtils.isEmpty(iccId)) {
6388 return false;
6389 }
6390
6391 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6392
6393 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6394 if (alphaTag == null) {
6395 editor.remove(alphaTagPrefKey);
6396 } else {
6397 editor.putString(alphaTagPrefKey, alphaTag);
6398 }
6399
6400 // Record both the line number and IMSI for this ICCID, since we need to
6401 // track all merged IMSIs based on line number
6402 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6403 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6404 if (number == null) {
6405 editor.remove(numberPrefKey);
6406 editor.remove(subscriberPrefKey);
6407 } else {
6408 editor.putString(numberPrefKey, number);
6409 editor.putString(subscriberPrefKey, subscriberId);
6410 }
6411
6412 editor.commit();
6413 return true;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006416 }
Derek Tan7226c842014-07-02 17:42:23 -07006417 }
6418
6419 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006420 public String getLine1NumberForDisplay(int subId, String callingPackage,
6421 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006422 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006423 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006424 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006425 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006426 return null;
6427 }
Derek Tan97ebb422014-09-05 16:55:38 -07006428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 String iccId = getIccId(subId);
6432 if (iccId != null) {
6433 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6434 if (DBG_MERGE) {
6435 log("getLine1NumberForDisplay returning "
6436 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6437 }
6438 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6441 return null;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006444 }
Derek Tan7226c842014-07-02 17:42:23 -07006445 }
6446
6447 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006448 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6449 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006451 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006452 return null;
6453 }
Derek Tan97ebb422014-09-05 16:55:38 -07006454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 String iccId = getIccId(subId);
6458 if (iccId != null) {
6459 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6460 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6461 }
6462 return null;
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006465 }
Derek Tan7226c842014-07-02 17:42:23 -07006466 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006467
6468 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006469 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6470 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006471 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6472 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006474 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006475 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006476 return null;
6477 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006478
Jordan Liub49b04b2019-05-06 14:45:15 -07006479 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6480 // the process, where TelephonyManager was instantiated.
6481 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006482 final long identity = Binder.clearCallingIdentity();
6483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006484 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final TelephonyManager tele = TelephonyManager.from(context);
6486 final SubscriptionManager sub = SubscriptionManager.from(context);
6487
6488 // Figure out what subscribers are currently active
6489 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490
Jordan Liub49b04b2019-05-06 14:45:15 -07006491 // Only consider subs which match the current subId
6492 // This logic can be simplified. See b/131189269 for progress.
6493 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006494 activeSubscriberIds.add(tele.getSubscriberId(subId));
6495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496
6497 // First pass, find a number override for an active subscriber
6498 String mergeNumber = null;
6499 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6500 for (String key : prefs.keySet()) {
6501 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6502 final String subscriberId = (String) prefs.get(key);
6503 if (activeSubscriberIds.contains(subscriberId)) {
6504 final String iccId = key.substring(
6505 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6506 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6507 mergeNumber = (String) prefs.get(numberKey);
6508 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006509 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 + " for active subscriber " + subscriberId);
6511 }
6512 if (!TextUtils.isEmpty(mergeNumber)) {
6513 break;
6514 }
6515 }
6516 }
6517 }
6518
6519 // Shortcut when no active merged subscribers
6520 if (TextUtils.isEmpty(mergeNumber)) {
6521 return null;
6522 }
6523
6524 // Second pass, find all subscribers under that line override
6525 final ArraySet<String> result = new ArraySet<>();
6526 for (String key : prefs.keySet()) {
6527 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6528 final String number = (String) prefs.get(key);
6529 if (mergeNumber.equals(number)) {
6530 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6531 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6532 final String subscriberId = (String) prefs.get(subscriberKey);
6533 if (!TextUtils.isEmpty(subscriberId)) {
6534 result.add(subscriberId);
6535 }
6536 }
6537 }
6538 }
6539
6540 final String[] resultArray = result.toArray(new String[result.size()]);
6541 Arrays.sort(resultArray);
6542 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006543 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6545 }
6546 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006547 } finally {
6548 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006549 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006550 }
6551
6552 @Override
zoey chen38003472019-12-13 17:16:31 +08006553 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6554 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 final TelephonyManager telephonyManager = mApp.getSystemService(
6559 TelephonyManager.class);
6560 String subscriberId = telephonyManager.getSubscriberId(subId);
6561 if (subscriberId == null) {
6562 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006563 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006564 + subId);
6565 }
6566 return null;
6567 }
6568
6569 final SubscriptionInfo info = SubscriptionController.getInstance()
6570 .getSubscriptionInfo(subId);
6571 final ParcelUuid groupUuid = info.getGroupUuid();
6572 // If it doesn't belong to any group, return just subscriberId of itself.
6573 if (groupUuid == null) {
6574 return new String[]{subscriberId};
6575 }
6576
6577 // Get all subscriberIds from the group.
6578 final List<String> mergedSubscriberIds = new ArrayList<>();
6579 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006580 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006581 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006582 for (SubscriptionInfo subInfo : groupInfos) {
6583 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6584 if (subscriberId != null) {
6585 mergedSubscriberIds.add(subscriberId);
6586 }
6587 }
6588
6589 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
6592
6593 }
6594 }
6595
6596 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006597 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006598 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006599 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 final Phone phone = getPhone(subId);
6604 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006608 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006609
6610 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006611 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006612 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6613 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006614 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6615 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 final Phone phone = getPhone(subId);
6620 if (phone == null) {
6621 return false;
6622 }
6623 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6624 cdmaNonRoamingList);
6625 } finally {
6626 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006627 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006628 }
6629
6630 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006631 @Deprecated
6632 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6633 enforceModifyPermission();
6634
6635 int returnValue = 0;
6636 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006637 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006638 if(result.exception == null) {
6639 if (result.result != null) {
6640 byte[] responseData = (byte[])(result.result);
6641 if(responseData.length > oemResp.length) {
6642 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6643 responseData.length + "bytes. Buffer Size is " +
6644 oemResp.length + "bytes.");
6645 }
6646 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6647 returnValue = responseData.length;
6648 }
6649 } else {
6650 CommandException ex = (CommandException) result.exception;
6651 returnValue = ex.getCommandError().ordinal();
6652 if(returnValue > 0) returnValue *= -1;
6653 }
6654 } catch (RuntimeException e) {
6655 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6656 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6657 if(returnValue > 0) returnValue *= -1;
6658 }
6659
6660 return returnValue;
6661 }
6662
6663 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006664 public void setRadioCapability(RadioAccessFamily[] rafs) {
6665 try {
6666 ProxyController.getInstance().setRadioCapability(rafs);
6667 } catch (RuntimeException e) {
6668 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6669 }
6670 }
6671
6672 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006673 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006674 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006675 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006676 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006677 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 final long identity = Binder.clearCallingIdentity();
6680 try {
chen xub97461a2018-10-26 14:17:57 -07006681 TelephonyPermissions
6682 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6683 mApp, phone.getSubId(), "getRadioAccessFamily");
6684 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
chen xub97461a2018-10-26 14:17:57 -07006688 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006689 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006690
6691 @Override
6692 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006693 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695
6696 final long identity = Binder.clearCallingIdentity();
6697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006698 ImsManager.getInstance(defaultPhone.getContext(),
6699 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006703 }
6704
6705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006706 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006707 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6709 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006710 return false;
6711 }
Svet Ganovb320e182015-04-16 12:30:10 -07006712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 final long identity = Binder.clearCallingIdentity();
6714 try {
6715 // Check the user preference and the system-level IMS setting. Even if the user has
6716 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6717 // In the long run, we may instead need to check if there exists a connection service
6718 // which can support video calling.
6719 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006720 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 return imsManager.isVtEnabledByPlatform()
6722 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6723 && imsManager.isVtEnabledByUser();
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006727 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006728
Andrew Leea1239f22015-03-02 17:44:07 -08006729 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006730 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6731 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006733 mApp, subId, callingPackage, callingFeatureId,
6734 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 return false;
6736 }
6737
6738 final long identity = Binder.clearCallingIdentity();
6739 try {
6740 CarrierConfigManager configManager =
6741 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006742 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
6746 }
Andrew Leea1239f22015-03-02 17:44:07 -08006747 }
6748
6749 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006750 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006752 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 return false;
6754 }
6755
6756 final long identity = Binder.clearCallingIdentity();
6757 try {
6758 CarrierConfigManager configManager =
6759 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006760 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
Andrew Leea1239f22015-03-02 17:44:07 -08006765 }
6766
Andrew Lee9431b832015-03-09 18:46:45 -07006767 @Override
6768 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006769 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006770 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006771 }
6772
6773 @Override
6774 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006777 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
Andrew Lee9431b832015-03-09 18:46:45 -07006781 }
6782
Hall Liuf6668912018-10-31 17:05:23 -07006783 /**
6784 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6785 * support for the feature and device firmware support.
6786 *
6787 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6788 */
6789 @Override
6790 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006792 final Phone phone = getPhone(subscriptionId);
6793 if (phone == null) {
6794 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6795 return false;
6796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006798 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6800 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006801 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 return isCarrierSupported && isDeviceSupported;
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
Hall Liu98187582018-01-22 19:15:32 -08006806 }
6807
Hall Liuf6668912018-10-31 17:05:23 -07006808 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006809 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6810 * RTT setting, will return true if the device and carrier both support RTT.
6811 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006812 */
6813 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 final long identity = Binder.clearCallingIdentity();
6815 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006816 boolean isRttSupported = isRttSupported(subscriptionId);
6817 boolean isUserRttSettingOn = Settings.Secure.getInt(
6818 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6819 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6820 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6821 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006825 }
6826
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006827 @Deprecated
6828 @Override
6829 public String getDeviceId(String callingPackage) {
6830 return getDeviceIdWithFeature(callingPackage, null);
6831 }
6832
Sanket Padawe7310cc72015-01-14 09:53:20 -08006833 /**
6834 * Returns the unique device ID of phone, for example, the IMEI for
6835 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6836 *
6837 * <p>Requires Permission:
6838 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6839 */
6840 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006841 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006842 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006843 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006844 return null;
6845 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006846 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006847 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006848 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006849 return null;
6850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851
6852 final long identity = Binder.clearCallingIdentity();
6853 try {
6854 return phone.getDeviceId();
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006858 }
6859
Ping Sunc67b7c22016-03-02 19:16:45 +08006860 /**
6861 * {@hide}
6862 * Returns the IMS Registration Status on a particular subid
6863 *
6864 * @param subId
6865 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006866 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006867 Phone phone = getPhone(subId);
6868 if (phone != null) {
6869 return phone.isImsRegistered();
6870 } else {
6871 return false;
6872 }
6873 }
6874
Santos Cordon7a1885b2015-02-03 11:15:19 -08006875 @Override
6876 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006883 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006884
Tyler Gunnf70ed162019-04-03 15:28:53 -07006885 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006886 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006887 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006889 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006890 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6891 }
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
6900 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006901 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006902 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6903 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = getPhone(subscriptionId);
6907 if (phone == null) {
6908 return null;
6909 }
6910 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
6913 }
6914 }
6915
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006916 /**
6917 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006918 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006919 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 Phone phone = getPhone(subId);
6923 if (phone != null) {
6924 return phone.isWifiCallingEnabled();
6925 } else {
6926 return false;
6927 }
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006930 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006931 }
6932
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006933 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006934 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006935 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006936 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 Phone phone = getPhone(subId);
6940 if (phone != null) {
6941 return phone.isVideoEnabled();
6942 } else {
6943 return false;
6944 }
6945 } finally {
6946 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006947 }
6948 }
6949
6950 /**
6951 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6952 * defined in {@link ImsRegistrationImplBase}.
6953 */
6954 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 Phone phone = getPhone(subId);
6958 if (phone != null) {
6959 return phone.getImsRegistrationTech();
6960 } else {
6961 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6962 }
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006965 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006966 }
6967
Stuart Scott8eef64f2015-04-08 15:13:54 -07006968 @Override
6969 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006970 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006971 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6972 return;
6973 }
6974
Svet Ganovcc087f82015-05-12 20:35:54 -07006975 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006976
Svet Ganovcc087f82015-05-12 20:35:54 -07006977 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006978 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6979 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006980 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006981 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006982 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006983 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006984 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6985 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006986 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006987 // There has been issues when Sms raw table somehow stores orphan
6988 // fragments. They lead to garbled message when new fragments come
6989 // in and combined with those stale ones. In case this happens again,
6990 // user can reset all network settings which will clean up this table.
6991 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006992 // Clean up IMS settings as well here.
6993 int slotId = getSlotIndex(subId);
6994 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6995 ImsManager.getInstance(mApp, slotId).factoryReset();
6996 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006997
6998 // Erase modem config if erase modem on network setting is enabled.
6999 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7000 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7001 if (configValue != null && Boolean.parseBoolean(configValue)) {
7002 sendEraseModemConfig(getDefaultPhone());
7003 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007006 }
7007 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007008
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007009 private void cleanUpSmsRawTable(Context context) {
7010 ContentResolver resolver = context.getContentResolver();
7011 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7012 resolver.delete(uri, null, null);
7013 }
7014
Narayan Kamath1c496c22015-04-16 14:40:19 +01007015 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007016 public String getSimLocaleForSubscriber(int subId) {
7017 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7018 final Phone phone = getPhone(subId);
7019 if (phone == null) {
7020 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007021 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
chen xu5d3637b2019-01-21 23:31:38 -08007025 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007026 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007027 if (info == null) {
7028 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7029 return null;
7030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 // Try and fetch the locale from the carrier properties or from the SIM language
7032 // preferences (EF-PL and EF-LI)...
7033 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007035 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7036 if (localeFromDefaultSim != null) {
7037 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7038 if (DBG) log("Using locale from subId: " + subId + " locale: "
7039 + localeFromDefaultSim);
7040 return localeFromDefaultSim.toLanguageTag();
7041 } else {
7042 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 }
7044 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 // The SIM language preferences only store a language (e.g. fr = French), not an
7047 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7048 // the SIM and carrier preferences does not include a country we add the country
7049 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007050 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007052 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 return mccLocale.toLanguageTag();
7054 }
7055
7056 if (DBG) log("No locale found - returning null");
7057 return null;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007061 }
7062
7063 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007064 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007065 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007066 }
7067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 /**
7069 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7070 */
7071 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007072 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007073 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007074 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007075
Chenjie Yu1ba97252018-01-11 18:16:20 -08007076 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007077 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007078
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007079 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007080 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7081 * representing the state of the modem.
7082 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007083 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7084 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007085 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007086 */
7087 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007088 public void requestModemActivityInfo(ResultReceiver result) {
7089 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
sqian1a1be542020-03-05 11:37:28 -08007094 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007097 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007098 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007099
Siddharth Rayb8114062018-06-17 15:02:38 -07007100 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7101 // less than total activity duration.
7102 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7103 if (info == null) {
7104 return false;
7105 }
7106 int activityDurationMs =
7107 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7108 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007109 int[] txTimeMs = info.getTransmitTimeMillis();
7110 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7111 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007112 }
7113 return (info.isValid()
7114 && (info.getSleepTimeMillis() <= activityDurationMs)
7115 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007116 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007117 && (totalTxTimeMs <= activityDurationMs));
7118 }
7119
Jack Yu85bd38a2015-11-09 11:34:32 -08007120 /**
7121 * {@hide}
7122 * Returns the service state information on specified subscription.
7123 */
7124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007125 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7126 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007128 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007129 return null;
7130 }
7131
Hall Liuf19c44f2018-11-27 14:38:17 -08007132 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7133 LocationAccessPolicy.checkLocationPermission(mApp,
7134 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7135 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007136 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007137 .setCallingPid(Binder.getCallingPid())
7138 .setCallingUid(Binder.getCallingUid())
7139 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007140 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007141 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7142 .build());
7143
7144 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7145 LocationAccessPolicy.checkLocationPermission(mApp,
7146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7147 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007148 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007149 .setCallingPid(Binder.getCallingPid())
7150 .setCallingUid(Binder.getCallingUid())
7151 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007152 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7154 .build());
7155 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7156 boolean hasFinePermission =
7157 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7158 boolean hasCoarsePermission =
7159 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 final Phone phone = getPhone(subId);
7164 if (phone == null) {
7165 return null;
7166 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007167
Hall Liuf19c44f2018-11-27 14:38:17 -08007168 ServiceState ss = phone.getServiceState();
7169
7170 // Scrub out the location info in ServiceState depending on what level of access
7171 // the caller has.
7172 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007173 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7174 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007178 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007179
7180 /**
7181 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7182 *
7183 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7184 * voicemail ringtone.
7185 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7186 * PhoneAccount.
7187 */
7188 @Override
7189 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7193 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007194 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007201 }
7202
7203 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007204 * Sets the per-account voicemail ringtone.
7205 *
7206 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7207 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7208 *
7209 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7210 * voicemail ringtone.
7211 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7212 * PhoneAccount.
7213 */
7214 @Override
7215 public void setVoicemailRingtoneUri(String callingPackage,
7216 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007217 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007218 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007219 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7220 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7222 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7223 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225
7226 final long identity = Binder.clearCallingIdentity();
7227 try {
7228 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7229 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007230 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 }
7232 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007235 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007236 }
7237
7238 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007239 * Returns whether vibration is set for voicemail notification in Phone settings.
7240 *
7241 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7242 * voicemail vibration setting.
7243 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7244 */
7245 @Override
7246 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7250 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007251 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
7257 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007258 }
7259
Youhan Wange64578a2016-05-02 15:32:42 -07007260 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007261 * Sets the per-account voicemail vibration.
7262 *
7263 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7264 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7265 *
7266 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7267 * voicemail vibration setting.
7268 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7269 * specific PhoneAccount.
7270 */
7271 @Override
7272 public void setVoicemailVibrationEnabled(String callingPackage,
7273 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007274 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007276 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7277 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7279 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7280 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007281 }
7282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7286 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007287 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 }
7289 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007292 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007293 }
7294
7295 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007296 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7297 *
7298 * @throws SecurityException if the caller does not have the required permission
7299 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007300 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007301 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007302 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007303 }
7304
7305 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007306 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7307 * permission.
7308 *
7309 * @throws SecurityException if the caller does not have the required permission
7310 */
7311 private void enforceSendSmsPermission() {
7312 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7313 }
7314
7315 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007316 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007317 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007318 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007319 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007320 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
7323 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007324 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 if (componentName == null) {
7326 throw new SecurityException(
7327 "Caller not current active visual voicemail package[null]");
7328 }
7329 String vvmPackage = componentName.getPackageName();
7330 if (!callingPackage.equals(vvmPackage)) {
7331 throw new SecurityException("Caller not current active visual voicemail package["
7332 + vvmPackage + "]");
7333 }
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007336 }
7337 }
7338
7339 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007340 * Return the application ID for the app type.
7341 *
7342 * @param subId the subscription ID that this request applies to.
7343 * @param appType the uicc app type.
7344 * @return Application ID for specificied app type, or null if no uicc.
7345 */
7346 @Override
7347 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007348 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007349 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350
7351 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007352 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 if (phone == null) {
7354 return null;
7355 }
7356 String aid = null;
7357 try {
7358 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7359 .getApplicationByType(appType).getAid();
7360 } catch (Exception e) {
7361 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7362 }
7363 return aid;
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007366 }
Youhan Wange64578a2016-05-02 15:32:42 -07007367 }
7368
Youhan Wang4001d252016-05-11 10:29:41 -07007369 /**
7370 * Return the Electronic Serial Number.
7371 *
7372 * @param subId the subscription ID that this request applies to.
7373 * @return ESN or null if error.
7374 */
7375 @Override
7376 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007377 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007378 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379
7380 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007381 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 if (phone == null) {
7383 return null;
7384 }
7385 String esn = null;
7386 try {
7387 esn = phone.getEsn();
7388 } catch (Exception e) {
7389 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7390 }
7391 return esn;
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007394 }
Youhan Wang4001d252016-05-11 10:29:41 -07007395 }
7396
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007397 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007398 * Return the Preferred Roaming List Version.
7399 *
7400 * @param subId the subscription ID that this request applies to.
7401 * @return PRLVersion or null if error.
7402 */
7403 @Override
7404 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007405 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007406 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407
7408 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007409 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 if (phone == null) {
7411 return null;
7412 }
7413 String cdmaPrlVersion = null;
7414 try {
7415 cdmaPrlVersion = phone.getCdmaPrlVersion();
7416 } catch (Exception e) {
7417 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7418 }
7419 return cdmaPrlVersion;
7420 } finally {
7421 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007422 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007423 }
7424
7425 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007426 * Get snapshot of Telephony histograms
7427 * @return List of Telephony histograms
7428 * @hide
7429 */
7430 @Override
7431 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7433 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
7437 return RIL.getTelephonyRILTimingHistograms();
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007441 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007442
7443 /**
7444 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007445 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7446 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007447 * Require system privileges. In the future we may add this to carrier APIs.
7448 *
Michele Berionne482f8202018-11-27 18:57:59 -08007449 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007450 */
7451 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007452 @TelephonyManager.SetCarrierRestrictionResult
7453 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007454 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007455 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007456
Michele Berionne482f8202018-11-27 18:57:59 -08007457 if (carrierRestrictionRules == null) {
7458 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007459 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 final long identity = Binder.clearCallingIdentity();
7462 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007463 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007464 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007468 }
7469
7470 /**
7471 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007472 * Get the allowed carrier list and the excluded carrier list, including the priority between
7473 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007474 * Require system privileges. In the future we may add this to carrier APIs.
7475 *
Michele Berionne482f8202018-11-27 18:57:59 -08007476 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007477 */
7478 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007479 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007480 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482
7483 final long identity = Binder.clearCallingIdentity();
7484 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007485 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7486 if (response instanceof CarrierRestrictionRules) {
7487 return (CarrierRestrictionRules) response;
7488 }
7489 // Response is an Exception of some kind,
7490 // which is signalled to the user as a NULL retval
7491 return null;
7492 } catch (Exception e) {
7493 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7494 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007498 }
7499
fionaxu59545b42016-05-25 15:53:37 -07007500 /**
fionaxu59545b42016-05-25 15:53:37 -07007501 * Action set from carrier signalling broadcast receivers to enable/disable radio
7502 * @param subId the subscription ID that this action applies to.
7503 * @param enabled control enable or disable radio.
7504 * {@hide}
7505 */
7506 @Override
7507 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7508 enforceModifyPermission();
7509 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510
7511 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007512 if (phone == null) {
7513 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7514 return;
7515 }
7516 try {
7517 phone.carrierActionSetRadioEnabled(enabled);
7518 } catch (Exception e) {
7519 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007522 }
7523 }
7524
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007525 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007526 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7527 * network status based on which carrier apps could apply actions accordingly,
7528 * enable/disable default url handler for example.
7529 *
7530 * @param subId the subscription ID that this action applies to.
7531 * @param report control start/stop reporting the default network status.
7532 * {@hide}
7533 */
7534 @Override
7535 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7536 enforceModifyPermission();
7537 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
7539 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007540 if (phone == null) {
7541 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7542 return;
7543 }
7544 try {
7545 phone.carrierActionReportDefaultNetworkStatus(report);
7546 } catch (Exception e) {
7547 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 } finally {
7549 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007550 }
7551 }
7552
7553 /**
fionaxud9622282017-07-17 17:51:30 -07007554 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7555 * @param subId the subscription ID that this action applies to.
7556 * {@hide}
7557 */
7558 @Override
7559 public void carrierActionResetAll(int subId) {
7560 enforceModifyPermission();
7561 final Phone phone = getPhone(subId);
7562 if (phone == null) {
7563 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7564 return;
7565 }
7566 try {
7567 phone.carrierActionResetAll();
7568 } catch (Exception e) {
7569 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7570 }
7571 }
7572
7573 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007574 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7575 * bug report is being generated.
7576 */
7577 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007578 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007579 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7580 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007581 writer.println("Permission Denial: can't dump Phone from pid="
7582 + Binder.getCallingPid()
7583 + ", uid=" + Binder.getCallingUid()
7584 + "without permission "
7585 + android.Manifest.permission.DUMP);
7586 return;
7587 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007589 }
Jack Yueb89b242016-06-22 13:27:47 -07007590
Brad Ebingerdac2f002018-04-03 15:17:52 -07007591 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007592 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7593 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7594 @NonNull String[] args) {
7595 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7596 this, in.getFileDescriptor(), out.getFileDescriptor(),
7597 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007598 }
7599
Jack Yueb89b242016-06-22 13:27:47 -07007600 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007601 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007602 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007603 * @param reason the reason the data enable change is taking place
7604 * @param enabled True if enabling the data, otherwise disabling.
7605 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007606 */
7607 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007608 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007609 boolean enabled) {
7610 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7611 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7612 try {
7613 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007614 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007615 } catch (SecurityException se) {
7616 enforceModifyPermission();
7617 }
7618 } else {
7619 enforceModifyPermission();
7620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
7624 Phone phone = getPhone(subId);
7625 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007626 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7627 phone.carrierActionSetMeteredApnsEnabled(enabled);
7628 } else {
7629 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 }
7632 } finally {
7633 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007634 }
7635 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007636
7637 /**
7638 * Get Client request stats
7639 * @return List of Client Request Stats
7640 * @hide
7641 */
7642 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007643 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7644 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007646 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007647 return null;
7648 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007649 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 if (phone != null) {
7654 return phone.getClientRequestStats();
7655 }
7656
7657 return null;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007661 }
7662
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007663 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007664 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007665 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007666 }
Jack Yueb4124c2017-02-16 15:32:43 -08007667
7668 /**
Grace Chen70990072017-03-24 17:21:30 -07007669 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007670 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007671 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007672 * @param state State of SIM (power down, power up, pass through)
7673 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7675 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007676 *
7677 **/
7678 @Override
Grace Chen70990072017-03-24 17:21:30 -07007679 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007680 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007681 Phone phone = PhoneFactory.getPhone(slotIndex);
7682
vagdeviaf9a5b92018-08-15 16:01:53 -07007683 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007688 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 }
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007692 }
7693 }
Shuo Qiandd210312017-04-12 22:11:33 +00007694
Tyler Gunn65d45c22017-06-05 11:22:26 -07007695 private boolean isUssdApiAllowed(int subId) {
7696 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007697 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007698 if (configManager == null) {
7699 return false;
7700 }
7701 PersistableBundle pb = configManager.getConfigForSubId(subId);
7702 if (pb == null) {
7703 return false;
7704 }
7705 return pb.getBoolean(
7706 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7707 }
7708
Shuo Qiandd210312017-04-12 22:11:33 +00007709 /**
7710 * Check if phone is in emergency callback mode
7711 * @return true if phone is in emergency callback mode
7712 * @param subId sub id
7713 */
goneil9c5f4872017-12-05 14:07:56 -08007714 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007715 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007716 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 if (phone != null) {
7722 return phone.isInEcm();
7723 } else {
7724 return false;
7725 }
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007728 }
7729 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007730
7731 /**
7732 * Get the current signal strength information for the given subscription.
7733 * Because this information is not updated when the device is in a low power state
7734 * it should not be relied-upon to be current.
7735 * @param subId Subscription index
7736 * @return the most recent cached signal strength info from the modem
7737 */
7738 @Override
7739 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 Phone p = getPhone(subId);
7743 if (p == null) {
7744 return null;
7745 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 return p.getSignalStrength();
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
7750 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007751 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007752
Pengquan Meng77b7f132018-08-22 14:49:57 -07007753 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007754 * Get the current modem radio state for the given slot.
7755 * @param slotIndex slot index.
7756 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007757 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007758 * @return the current radio power state from the modem
7759 */
7760 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007761 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007762 Phone phone = PhoneFactory.getPhone(slotIndex);
7763 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7765 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007766 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7767 }
7768
7769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 return phone.getRadioPowerState();
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
7774 }
7775 }
7776 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7777 }
7778
7779 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007780 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7781 *
7782 * <p>Requires one of the following permissions:
7783 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7784 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7785 * privileges.
7786 *
7787 * @param subId subscription id
7788 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7789 * {@code false}.
7790 */
7791 @Override
7792 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007793 try {
7794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7795 null);
7796 } catch (Exception e) {
7797 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7798 mApp, subId, "isDataRoamingEnabled");
7799 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007800
Pengquan Menga1bb6272018-09-06 09:59:22 -07007801 boolean isEnabled = false;
7802 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007803 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007804 Phone phone = getPhone(subId);
7805 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007806 } finally {
7807 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007808 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007809 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007810 }
7811
7812
7813 /**
7814 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7815 *
7816 * <p> Requires permission:
7817 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7818 * privileges.
7819 *
7820 * @param subId subscription id
7821 * @param isEnabled {@code true} means enable, {@code false} means disable.
7822 */
7823 @Override
7824 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7826 mApp, subId, "setDataRoamingEnabled");
7827
Pengquan Menga1bb6272018-09-06 09:59:22 -07007828 final long identity = Binder.clearCallingIdentity();
7829 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007830 Phone phone = getPhone(subId);
7831 if (phone != null) {
7832 phone.setDataRoamingEnabled(isEnabled);
7833 }
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007836 }
7837 }
7838
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007839 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007840 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007841 TelephonyPermissions
7842 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007843 mApp, subId, "isManualNetworkSelectionAllowed");
7844
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007845 boolean isAllowed = true;
7846 final long identity = Binder.clearCallingIdentity();
7847 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007848 Phone phone = getPhone(subId);
7849 if (phone != null) {
7850 isAllowed = phone.isCspPlmnEnabled();
7851 }
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
7854 }
7855 return isAllowed;
7856 }
7857
7858 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007859 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007860 // Verify that tha callingPackage belongs to the calling UID
7861 mApp.getSystemService(AppOpsManager.class)
7862 .checkPackage(Binder.getCallingUid(), callingPackage);
7863
Jordan Liu1e142fc2019-04-22 15:10:43 -07007864 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007865 try {
7866 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007867 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007868 } catch (SecurityException e) {
7869 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7870 // has carrier privileges on an active UICC
7871 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7872 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007873 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007874 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007875 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007876
7877 final long identity = Binder.clearCallingIdentity();
7878 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007879 UiccController uiccController = UiccController.getInstance();
7880 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007881 if (hasReadPermission) {
7882 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007883 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007884
7885 // Remove private info if the caller doesn't have access
7886 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7887 for (UiccCardInfo cardInfo : cardInfos) {
7888 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7889 // is available
7890 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7891 if (card == null || card.getUiccProfile() == null) {
7892 // assume no access if the card or profile is unavailable
7893 filteredInfos.add(cardInfo.getUnprivileged());
7894 continue;
7895 }
7896 UiccProfile profile = card.getUiccProfile();
7897 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7898 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7899 filteredInfos.add(cardInfo);
7900 } else {
7901 filteredInfos.add(cardInfo.getUnprivileged());
7902 }
7903 }
7904 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007905 } finally {
7906 Binder.restoreCallingIdentity(identity);
7907 }
7908 }
7909
7910 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007911 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007912 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 final long identity = Binder.clearCallingIdentity();
7915 try {
7916 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7917 if (slots == null) {
7918 Rlog.i(LOG_TAG, "slots is null.");
7919 return null;
7920 }
7921
7922 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7923 for (int i = 0; i < slots.length; i++) {
7924 UiccSlot slot = slots[i];
7925 if (slot == null) {
7926 continue;
7927 }
7928
Jordan Liu7be7e652019-05-06 18:55:02 +00007929 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 UiccCard card = slot.getUiccCard();
7931 if (card != null) {
7932 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007933 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007934 cardId = slot.getEid();
7935 if (TextUtils.isEmpty(cardId)) {
7936 cardId = slot.getIccId();
7937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 }
7939
Jordan Liu857451f2019-05-09 16:35:35 -07007940 if (cardId != null) {
7941 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7942 // if cardId is an EID, it's all digits so this is fine
7943 cardId = IccUtils.stripTrailingFs(cardId);
7944 }
7945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946 int cardState = 0;
7947 switch (slot.getCardState()) {
7948 case CARDSTATE_ABSENT:
7949 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7950 break;
7951 case CARDSTATE_PRESENT:
7952 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7953 break;
7954 case CARDSTATE_ERROR:
7955 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7956 break;
7957 case CARDSTATE_RESTRICTED:
7958 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7959 break;
7960 default:
7961 break;
7962
7963 }
7964
7965 infos[i] = new UiccSlotInfo(
7966 slot.isActive(),
7967 slot.isEuicc(),
7968 cardId,
7969 cardState,
7970 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007971 slot.isExtendedApduSupported(),
7972 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 }
7974 return infos;
7975 } finally {
7976 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007977 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007978 }
7979
7980 @Override
7981 public boolean switchSlots(int[] physicalSlots) {
7982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983
7984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
7989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007990 }
Jack Yu4c988042018-02-27 15:30:01 -08007991
7992 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007993 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007994 final long identity = Binder.clearCallingIdentity();
7995 try {
7996 return UiccController.getInstance().getCardIdForDefaultEuicc();
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
7999 }
8000 }
8001
Pengquan Meng85728fb2018-03-12 16:31:21 -07008002 /**
goneil47ffb6e2018-04-06 15:40:58 -07008003 * A test API to reload the UICC profile.
8004 *
8005 * <p>Requires that the calling app has permission
8006 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8007 * @hide
8008 */
8009 @Override
8010 public void refreshUiccProfile(int subId) {
8011 enforceModifyPermission();
8012
8013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 Phone phone = getPhone(subId);
8016 if (phone == null) {
8017 return;
8018 }
8019 UiccCard uiccCard = phone.getUiccCard();
8020 if (uiccCard == null) {
8021 return;
8022 }
8023 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8024 if (uiccProfile == null) {
8025 return;
8026 }
8027 uiccProfile.refresh();
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
8031 }
8032
8033 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008034 * Returns false if the mobile data is disabled by default, otherwise return true.
8035 */
8036 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008037 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008038 }
8039
8040 /**
8041 * Returns true if the data roaming is enabled by default, i.e the system property
8042 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8043 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8044 */
8045 private boolean getDefaultDataRoamingEnabled(int subId) {
8046 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008047 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008048 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008049 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8050 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8051 return isDataRoamingEnabled;
8052 }
8053
8054 /**
8055 * Returns the default network type for the given {@code subId}, if the default network type is
8056 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8057 */
8058 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008059 List<Integer> list = TelephonyProperties.default_network();
8060 int phoneId = mSubscriptionController.getPhoneId(subId);
8061 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8062 return list.get(phoneId);
8063 }
8064 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008065 }
fionaxua13278b2018-03-21 00:08:13 -07008066
8067 @Override
8068 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008069 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071
8072 final long identity = Binder.clearCallingIdentity();
8073 try {
8074 final Phone phone = getPhone(subId);
8075 if (phone == null) {
8076 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8077 return;
8078 }
chen xueaba88a2019-03-15 13:15:10 -07008079 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8080 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008081 if (carrierPrivilegeRules == null) {
8082 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8083 } else {
8084 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 } finally {
8087 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008088 }
fionaxua13278b2018-03-21 00:08:13 -07008089 }
8090
8091 @Override
8092 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008093 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 final Phone phone = getPhone(subId);
8098 if (phone == null) {
8099 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8100 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8101 }
8102 return phone.getCarrierIdListVersion();
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008105 }
fionaxua13278b2018-03-21 00:08:13 -07008106 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008107
8108 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008109 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8110 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008112 mApp, subId, callingPackage, callingFeatureId,
8113 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008114 return -1;
8115 }
8116
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
8122 }
8123 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008124
8125 @Override
8126 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008127 TelephonyPermissions
8128 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008129 mApp, subId, "getCdmaRoamingMode");
8130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
8137 }
8138
8139 @Override
8140 public boolean setCdmaRoamingMode(int subId, int mode) {
8141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8142 mApp, subId, "setCdmaRoamingMode");
8143
8144 final long identity = Binder.clearCallingIdentity();
8145 try {
8146 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
8149 }
8150 }
8151
8152 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008153 public int getCdmaSubscriptionMode(int subId) {
8154 TelephonyPermissions
8155 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8156 mApp, subId, "getCdmaSubscriptionMode");
8157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8161 } finally {
8162 Binder.restoreCallingIdentity(identity);
8163 }
8164 }
8165
8166 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008167 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8169 mApp, subId, "setCdmaSubscriptionMode");
8170
8171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
8176 }
8177 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008178
sqianc5eccab2018-10-19 18:46:41 -07008179 @Override
sqian8c685422019-02-22 15:55:18 -08008180 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008181 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008183 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8184 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008185 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8186 }
8187 final long identity = Binder.clearCallingIdentity();
8188 try {
sqian854d44b2018-12-12 16:48:18 -08008189 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8190 for (Phone phone: PhoneFactory.getPhones()) {
8191 if (phone.getEmergencyNumberTracker() != null
8192 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8193 emergencyNumberListInternal.put(
8194 phone.getSubId(),
8195 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8196 }
sqian11b7a0e2018-12-05 18:48:28 -08008197 }
sqian854d44b2018-12-12 16:48:18 -08008198 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
sqianc5eccab2018-10-19 18:46:41 -07008202 }
8203
8204 @Override
sqian8c685422019-02-22 15:55:18 -08008205 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008206 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008207 if (!exactMatch) {
8208 TelephonyPermissions
8209 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008210 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008211 }
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
sqian854d44b2018-12-12 16:48:18 -08008214 for (Phone phone: PhoneFactory.getPhones()) {
8215 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008216 && phone.getEmergencyNumberTracker()
8217 .isEmergencyNumber(number, exactMatch)) {
8218 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008219 }
sqian11b7a0e2018-12-05 18:48:28 -08008220 }
8221 return false;
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
8225 }
8226
sqianf4ca7ed2019-01-15 18:32:07 -08008227 /**
8228 * Update emergency number list for test mode.
8229 */
8230 @Override
8231 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8233 "updateEmergencyNumberListTestMode");
8234
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 for (Phone phone: PhoneFactory.getPhones()) {
8238 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8239 if (tracker != null) {
8240 tracker.executeEmergencyNumberTestModeCommand(action, num);
8241 }
8242 }
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
8246 }
8247
8248 /**
8249 * Get the full emergency number list for test mode.
8250 */
8251 @Override
8252 public List<String> getEmergencyNumberListTestMode() {
8253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8254 "getEmergencyNumberListTestMode");
8255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
8258 Set<String> emergencyNumbers = new HashSet<>();
8259 for (Phone phone: PhoneFactory.getPhones()) {
8260 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8261 if (tracker != null) {
8262 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8263 emergencyNumbers.add(num.getNumber());
8264 }
8265 }
8266 }
8267 return new ArrayList<>(emergencyNumbers);
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
8271 }
8272
chen xud6b45bd2018-10-30 22:27:10 -07008273 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008274 public int getEmergencyNumberDbVersion(int subId) {
8275 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8276
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 final Phone phone = getPhone(subId);
8280 if (phone == null) {
8281 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8282 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8283 }
8284 return phone.getEmergencyNumberDbVersion();
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
8289
8290 @Override
8291 public void notifyOtaEmergencyNumberDbInstalled() {
8292 enforceModifyPermission();
8293
8294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 for (Phone phone: PhoneFactory.getPhones()) {
8297 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8298 if (tracker != null) {
8299 tracker.updateOtaEmergencyNumberDatabase();
8300 }
8301 }
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
8305 }
8306
8307 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008308 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008309 enforceActiveEmergencySessionPermission();
8310
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 for (Phone phone: PhoneFactory.getPhones()) {
8314 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8315 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008316 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8317 }
8318 }
8319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
8322 }
8323
8324 @Override
8325 public void resetOtaEmergencyNumberDbFilePath() {
8326 enforceActiveEmergencySessionPermission();
8327
8328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 for (Phone phone: PhoneFactory.getPhones()) {
8331 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8332 if (tracker != null) {
8333 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008334 }
8335 }
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
8341 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008342 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8343 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8344 Phone phone = getPhone(subId);
8345 if (phone == null) {
8346 return null;
8347 }
8348 final long identity = Binder.clearCallingIdentity();
8349 try {
8350 UiccProfile profile = UiccController.getInstance()
8351 .getUiccProfileForPhone(phone.getPhoneId());
8352 if (profile != null) {
8353 return profile.getCertsFromCarrierPrivilegeAccessRules();
8354 }
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
8358 return null;
8359 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008360
8361 /**
8362 * Enable or disable a modem stack.
8363 */
8364 @Override
8365 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8366 enforceModifyPermission();
8367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 Phone phone = PhoneFactory.getPhone(slotIndex);
8371 if (phone == null) {
8372 return false;
8373 } else {
8374 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8375 }
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
8379 }
Michelecea4cf22018-12-21 15:00:11 -08008380
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008381 /**
8382 * Whether a modem stack is enabled or not.
8383 */
8384 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008385 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8386 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008387 Phone phone = PhoneFactory.getPhone(slotIndex);
8388 if (phone == null) return false;
8389
8390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008391 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8392 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008393 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8394 }
8395
8396 final long identity = Binder.clearCallingIdentity();
8397 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008398 try {
8399 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8400 } catch (NoSuchElementException ex) {
8401 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8402 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
Michelecea4cf22018-12-21 15:00:11 -08008408 @Override
Michele0ea7d782019-03-19 14:58:42 -07008409 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008410 enforceModifyPermission();
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008415 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008416 .commit();
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
8421
8422 @Override
Michele0ea7d782019-03-19 14:58:42 -07008423 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008424 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008426 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8427 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008428 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008429 }
Michelecea4cf22018-12-21 15:00:11 -08008430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
Michele0ea7d782019-03-19 14:58:42 -07008433 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008438
Michele0ea7d782019-03-19 14:58:42 -07008439 @TelephonyManager.IsMultiSimSupportedResult
8440 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008441 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8442 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8443 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008444 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8445 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008446 }
8447 // Check if the hardware supports multisim functionality. If usage of multisim is not
8448 // supported by the modem, indicate that it is restricted.
8449 PhoneCapability staticCapability =
8450 mPhoneConfigurationManager.getStaticPhoneCapability();
8451 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008452 loge("isMultiSimSupportedInternal: no static configuration available");
8453 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008454 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008455 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008456 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008458 }
8459 // Check if support of multiple SIMs is restricted by carrier
8460 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008461 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008462 }
8463
Michele0ea7d782019-03-19 14:58:42 -07008464 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008465 }
8466
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008467 /**
8468 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008469 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8470 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8471 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008472 * @param numOfSims number of active sims we want to switch to
8473 */
8474 @Override
8475 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008476 if (numOfSims == 1) {
8477 enforceModifyPermission();
8478 } else {
8479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8480 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8481 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008482 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008483
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008484 try {
Michele30b57b22019-03-01 12:01:14 -08008485 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008486 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008487 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8488 return;
8489 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008490 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008496 @Override
8497 public boolean isApplicationOnUicc(int subId, int appType) {
8498 enforceReadPrivilegedPermission("isApplicationOnUicc");
8499 Phone phone = getPhone(subId);
8500 if (phone == null) {
8501 return false;
8502 }
8503 final long identity = Binder.clearCallingIdentity();
8504 try {
8505 UiccCard uiccCard = phone.getUiccCard();
8506 if (uiccCard == null) {
8507 return false;
8508 }
8509 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8510 if (uiccProfile == null) {
8511 return false;
8512 }
8513 if (TelephonyManager.APPTYPE_SIM <= appType
8514 && appType <= TelephonyManager.APPTYPE_ISIM) {
8515 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8516 }
8517 return false;
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008523 /**
chen xub4baa772019-04-03 10:23:41 -07008524 * Get whether making changes to modem configurations will trigger reboot.
8525 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008526 */
8527 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008528 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8529 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008531 mApp, subId, callingPackage, callingFeatureId,
8532 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008533 return false;
8534 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008535 final long identity = Binder.clearCallingIdentity();
8536 try {
8537 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
8540 }
8541 }
8542
Nathan Harold29f5f052019-02-15 13:41:57 -08008543 private void updateModemStateMetrics() {
8544 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8545 // TODO: check the state for each modem if the api is ready.
8546 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8547 }
8548
Pengquan Meng3889a572019-01-23 11:16:29 -08008549 @Override
8550 public int[] getSlotsMapping() {
8551 enforceReadPrivilegedPermission("getSlotsMapping");
8552
8553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8556 // All logical slots should have a mapping to a physical slot.
8557 int[] logicalSlotsMapping = new int[phoneCount];
8558 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8559 for (int i = 0; i < slotInfos.length; i++) {
8560 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8561 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8562 }
8563 }
8564 return logicalSlotsMapping;
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
8567 }
8568 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008569
8570 /**
8571 * Get the IRadio HAL Version
8572 */
8573 @Override
8574 public int getRadioHalVersion() {
8575 Phone phone = getDefaultPhone();
8576 if (phone == null) return -1;
8577 HalVersion hv = phone.getHalVersion();
8578 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8579 return hv.major * 100 + hv.minor;
8580 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008581
8582 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008583 * Get the current calling package name.
8584 * @return the current calling package name
8585 */
8586 @Override
8587 public String getCurrentPackageName() {
8588 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8589 }
8590
8591 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008592 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8593 * corresponding network requests on a subId.
8594 *
8595 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008596 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008597 * 2) APN is un-metered for this subscription, or
8598 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008599 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008600 *
8601 * @return whether data is allowed for a apn type.
8602 *
8603 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008604 */
8605 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008606 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008607 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8608 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008609
8610 // Now that all security checks passes, perform the operation as ourselves.
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 Phone phone = getPhone(subId);
8614 if (phone == null) return false;
8615
Jack Yu41407ee2019-05-13 16:54:09 -07008616 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008617 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
8623 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008624 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008625 enforceReadPrivilegedPermission("isApnMetered");
8626
8627 // Now that all security checks passes, perform the operation as ourselves.
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 Phone phone = getPhone(subId);
8631 if (phone == null) return true; // By default return true.
8632
Jack Yu41407ee2019-05-13 16:54:09 -07008633 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008638
8639 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008640 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8641 int subscriptionId, IBooleanConsumer resultCallback) {
8642 enforceModifyPermission();
8643 long token = Binder.clearCallingIdentity();
8644 try {
8645 Phone phone = getPhone(subscriptionId);
8646 if (phone == null) {
8647 try {
8648 if (resultCallback != null) {
8649 resultCallback.accept(false);
8650 }
8651 } catch (RemoteException e) {
8652 // ignore
8653 }
8654 return;
8655 }
8656 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8657 Pair.create(specifiers, (x) -> {
8658 try {
8659 if (resultCallback != null) {
8660 resultCallback.accept(x);
8661 }
8662 } catch (RemoteException e) {
8663 // ignore
8664 }
8665 });
8666 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8667 } finally {
8668 Binder.restoreCallingIdentity(token);
8669 }
8670 }
8671
8672 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008673 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008674 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008675 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8676 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8677 if (iccRecords == null) {
8678 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8679 return false;
8680 }
8681 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8682 }
8683
8684 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008685 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8686 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008687 if (callingPackage == null) {
8688 callingPackage = getCurrentPackageName();
8689 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008690 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8691 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008692 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8693 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008694 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8695 }
8696 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8697 Intent intent = new Intent();
8698 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8699 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8700 // Bring up choose default SMS subscription dialog right now
8701 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8702 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8703 mApp.startActivity(intent);
8704 }
chen xud5ca2d52019-05-28 15:20:57 -07008705
8706 @Override
8707 public String getMmsUAProfUrl(int subId) {
8708 //TODO investigate if this API should require proper permission check in R b/133791609
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008711 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8712 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8713 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8714 return carrierUAProfUrl;
8715 }
chen xud5ca2d52019-05-28 15:20:57 -07008716 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8717 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 }
8722
8723 @Override
8724 public String getMmsUserAgent(int subId) {
8725 //TODO investigate if this API should require proper permission check in R b/133791609
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008728 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8729 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8730 if (!TextUtils.isEmpty(carrierUserAgent)) {
8731 return carrierUserAgent;
8732 }
chen xud5ca2d52019-05-28 15:20:57 -07008733 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8734 .getString(com.android.internal.R.string.config_mms_user_agent);
8735 } finally {
8736 Binder.restoreCallingIdentity(identity);
8737 }
8738 }
Jack Yub07d4972019-05-28 16:12:25 -07008739
8740 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008741 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8742 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 Phone phone = getPhone(subscriptionId);
8747 if (phone == null) return false;
8748
8749 switch (policy) {
8750 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8751 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8752 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8753 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8754 default:
8755 throw new IllegalArgumentException(policy + " is not a valid policy");
8756 }
8757 } finally {
8758 Binder.restoreCallingIdentity(identity);
8759 }
8760 }
8761
8762 @Override
8763 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8764 boolean enabled) {
8765 enforceModifyPermission();
8766
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 Phone phone = getPhone(subscriptionId);
8770 if (phone == null) return;
8771
8772 switch (policy) {
8773 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8774 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8775 break;
8776 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8777 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8778 break;
8779 default:
8780 throw new IllegalArgumentException(policy + " is not a valid policy");
8781 }
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
8784 }
8785 }
8786
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008787 /**
Hall Liub48cf452020-09-25 11:13:49 -07008788 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008789 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8790 * otherwise.
8791 */
8792 @Override
8793 public void setCepEnabled(boolean isCepEnabled) {
8794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8799 for (Phone phone : PhoneFactory.getPhones()) {
8800 Phone defaultPhone = phone.getImsPhone();
8801 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8802 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8803 ImsPhoneCallTracker imsPhoneCallTracker =
8804 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8805 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8806 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8807 + imsPhone.getMsisdn());
8808 }
8809 }
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
allenwtsu46dcc572020-01-08 18:24:03 +08008814
8815 /**
8816 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8817 *
8818 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8819 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8820 * before being read.
8821 */
8822 @Override
8823 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8824 isCompressed) {
8825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8826 mApp, subId, "notifyRcsAutoConfigurationReceived");
8827 try {
8828 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8829 if (configBinder == null) {
8830 Rlog.e(LOG_TAG, "null result for getImsConfig");
8831 } else {
8832 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8833 }
8834 } catch (RemoteException e) {
8835 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8836 }
8837 }
zoey chenf95ca592019-12-30 16:11:23 +08008838
8839 @Override
8840 public boolean isIccLockEnabled(int subId) {
8841 enforceReadPrivilegedPermission("isIccLockEnabled");
8842
8843 // Now that all security checks passes, perform the operation as ourselves.
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 Phone phone = getPhone(subId);
8847 if (phone != null && phone.getIccCard() != null) {
8848 return phone.getIccCard().getIccLockEnabled();
8849 } else {
8850 return false;
8851 }
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
8855 }
8856
8857 /**
zoey chene02881a2019-12-30 16:11:23 +08008858 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008859 *
zoey chene02881a2019-12-30 16:11:23 +08008860 * @return an integer representing the status of IccLock enabled or disabled in the following
8861 * three cases:
8862 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8863 * successfully.
8864 * - Positive number and zero for remaining password attempts.
8865 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008866 *
8867 */
8868 @Override
8869 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8870 enforceModifyPermission();
8871
8872 Phone phone = getPhone(subId);
8873 if (phone == null) {
8874 return 0;
8875 }
8876 // Now that all security checks passes, perform the operation as ourselves.
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8880 new Pair<Boolean, String>(enabled, password), phone, null);
8881 return attemptsRemaining;
8882
8883 } catch (Exception e) {
8884 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 return 0;
8889 }
8890
8891 /**
8892 * Change the ICC password used in ICC pin lock.
8893 *
zoey chene02881a2019-12-30 16:11:23 +08008894 * @return an integer representing the status of IccLock changed in the following three cases:
8895 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8896 * - Positive number and zero for remaining password attempts.
8897 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008898 *
8899 */
8900 @Override
8901 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8902 enforceModifyPermission();
8903
8904 Phone phone = getPhone(subId);
8905 if (phone == null) {
8906 return 0;
8907 }
8908 // Now that all security checks passes, perform the operation as ourselves.
8909 final long identity = Binder.clearCallingIdentity();
8910 try {
8911 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8912 new Pair<String, String>(oldPassword, newPassword), phone, null);
8913 return attemptsRemaining;
8914
8915 } catch (Exception e) {
8916 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8917 } finally {
8918 Binder.restoreCallingIdentity(identity);
8919 }
8920 return 0;
8921 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008922
Peter Wangdafb9ac2020-01-15 14:13:38 -08008923 /**
8924 * Request for receiving user activity notification
8925 */
8926 @Override
8927 public void requestUserActivityNotification() {
8928 if (!mNotifyUserActivity.get()
8929 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8930 mNotifyUserActivity.set(true);
8931 }
8932 }
8933
8934 /**
8935 * Called when userActivity is signalled in the power manager.
8936 * This is safe to call from any thread, with any window manager locks held or not.
8937 */
8938 @Override
8939 public void userActivity() {
8940 // ***************************************
8941 // * Inherited from PhoneWindowManager *
8942 // ***************************************
8943 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8944 // WITH ITS LOCKS HELD.
8945 //
8946 // This code must be VERY careful about the locks
8947 // it acquires.
8948 // In fact, the current code acquires way too many,
8949 // and probably has lurking deadlocks.
8950
8951 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8952 throw new SecurityException("Only the OS may call notifyUserActivity()");
8953 }
8954
8955 if (mNotifyUserActivity.getAndSet(false)) {
8956 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8957 USER_ACTIVITY_NOTIFICATION_DELAY);
8958 }
8959 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008960
Malcolm Chen884180b2020-04-13 11:59:40 -07008961 @Override
8962 public boolean canConnectTo5GInDsdsMode() {
8963 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8964 }
Jack Yud10cdd42020-09-28 20:28:01 -07008965
8966 @Override
8967 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8968 String callingFeatureId) {
8969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8970 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8971 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8972 }
8973
8974 Phone phone = getPhone(subId);
8975 if (phone == null) {
8976 throw new RuntimeException("phone is not available");
8977 }
8978 // Now that all security checks passes, perform the operation as ourselves.
8979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 return phone.getEquivalentHomePlmns();
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008986}