blob: beda55cb6303e2fea0467379ed9f6a78774283f0 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800298 // Parameters of select command.
299 private static final int SELECT_COMMAND = 0xA4;
300 private static final int SELECT_P1 = 0x04;
301 private static final int SELECT_P2 = 0;
302 private static final int SELECT_P3 = 0x10;
303
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 /** The singleton instance. */
305 private static PhoneInterfaceManager sInstance;
306
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800309 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700310 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800311 private AppOpsManager mAppOps;
312 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800313 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800314 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700315 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
Peter Wangdafb9ac2020-01-15 14:13:38 -0800317 /** User Activity */
318 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800319 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
320
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700321 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
322
Derek Tan97ebb422014-09-05 16:55:38 -0700323 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
324 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800325 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800326 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700327
Michelecea4cf22018-12-21 15:00:11 -0800328 // String to store multi SIM allowed
329 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
330
Derek Tan740e1672017-06-27 14:56:27 -0700331 // The AID of ISD-R.
332 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
333
yinxub1bed742017-04-17 11:45:04 -0700334 private NetworkScanRequestTracker mNetworkScanRequestTracker;
335
David Kelly5e06a7f2018-03-12 14:10:59 +0000336 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
337 private static final int MANUFACTURER_CODE_LENGTH = 8;
338
Derek Tan89e89d42014-07-08 17:00:10 -0700339 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700340 * Experiment flag to enable erase modem config on reset network, default value is false
341 */
342 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
343 "reset_network_erase_modem_config_enabled";
344
345 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700346 * A request object to use for transmitting data to an ICC.
347 */
348 private static final class IccAPDUArgument {
349 public int channel, cla, command, p1, p2, p3;
350 public String data;
351
352 public IccAPDUArgument(int channel, int cla, int command,
353 int p1, int p2, int p3, String data) {
354 this.channel = channel;
355 this.cla = cla;
356 this.command = command;
357 this.p1 = p1;
358 this.p2 = p2;
359 this.p3 = p3;
360 this.data = data;
361 }
362 }
363
364 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700365 * A request object to use for transmitting data to an ICC.
366 */
367 private static final class ManualNetworkSelectionArgument {
368 public OperatorInfo operatorInfo;
369 public boolean persistSelection;
370
371 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
372 this.operatorInfo = operatorInfo;
373 this.persistSelection = persistSelection;
374 }
375 }
376
377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
379 * request after sending. The main thread will notify the request when it is complete.
380 */
381 private static final class MainThreadRequest {
382 /** The argument to use for the request */
383 public Object argument;
384 /** The result of the request that is run on the main thread */
385 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800386 // The subscriber id that this request applies to. Defaults to
387 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
388 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389
Nathan Harold92bed182018-10-12 18:16:49 -0700390 // In cases where subId is unavailable, the caller needs to specify the phone.
391 public Phone phone;
392
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 public WorkSource workSource;
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 public MainThreadRequest(Object argument) {
396 this.argument = argument;
397 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800398
Nathan Harold92bed182018-10-12 18:16:49 -0700399 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
400 this.argument = argument;
401 if (phone != null) {
402 this.phone = phone;
403 }
404 this.workSource = workSource;
405 }
406
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800409 if (subId != null) {
410 this.subId = subId;
411 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700412 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 }
415
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800416 private static final class IncomingThirdPartyCallArgs {
417 public final ComponentName component;
418 public final String callId;
419 public final String callerDisplayName;
420
421 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
422 String callerDisplayName) {
423 this.component = component;
424 this.callId = callId;
425 this.callerDisplayName = callerDisplayName;
426 }
427 }
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 /**
430 * A handler that processes messages on the main thread in the phone process. Since many
431 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
432 * inbound binder threads to the main thread in the phone process. The Binder thread
433 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
434 * on, which will be notified when the operation completes and will contain the result of the
435 * request.
436 *
437 * <p>If a MainThreadRequest object is provided in the msg.obj field,
438 * note that request.result must be set to something non-null for the calling thread to
439 * unblock.
440 */
441 private final class MainThreadHandler extends Handler {
442 @Override
443 public void handleMessage(Message msg) {
444 MainThreadRequest request;
445 Message onCompleted;
446 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800447 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800449 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
451 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 case CMD_HANDLE_USSD_REQUEST: {
453 request = (MainThreadRequest) msg.obj;
454 final Phone phone = getPhoneFromRequest(request);
455 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
456 String ussdRequest = ussdObject.first;
457 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 if (!isUssdApiAllowed(request.subId)) {
460 // Carrier does not support use of this API, return failure.
461 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
462 UssdResponse response = new UssdResponse(ussdRequest, null);
463 Bundle returnData = new Bundle();
464 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
465 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 request.result = true;
468 notifyRequester(request);
469 return;
470 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700471
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 try {
473 request.result = phone != null
474 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
475 } catch (CallStateException cse) {
476 request.result = false;
477 }
478 // Wake up the requesting thread
479 notifyRequester(request);
480 break;
pkanwar32d516d2016-10-14 19:37:38 -0700481 }
482
Yorke Lee716f67e2015-06-17 15:39:16 -0700483 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 final Phone phone = getPhoneFromRequest(request);
486 request.result = phone != null ?
487 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
488 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 if (uiccCard == null) {
499 loge("iccTransmitApduLogicalChannel: No UICC");
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
504 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700505 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 iccArgument.channel, iccArgument.cla, iccArgument.command,
507 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 break;
511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800521 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800523 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 } else {
525 loge("iccTransmitApduLogicalChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 break;
530
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccTransmitApduBasicChannel: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
541 request);
542 uiccCard.iccTransmitApduBasicChannel(
543 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
544 iccArgument.p3, iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
555 if (ar.result == null) {
556 loge("iccTransmitApduBasicChannel: Empty response");
557 } else if (ar.exception instanceof CommandException) {
558 loge("iccTransmitApduBasicChannel: CommandException: " +
559 ar.exception);
560 } else {
561 loge("iccTransmitApduBasicChannel: Unknown exception");
562 }
563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 break;
566
567 case CMD_EXCHANGE_SIM_IO:
568 request = (MainThreadRequest) msg.obj;
569 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 if (uiccCard == null) {
572 loge("iccExchangeSimIO: No UICC");
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 } else {
576 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
577 request);
578 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
579 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
580 iccArgument.data, onCompleted);
581 }
582 break;
583
584 case EVENT_EXCHANGE_SIM_IO_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
587 if (ar.exception == null && ar.result != null) {
588 request.result = ar.result;
589 } else {
590 request.result = new IccIoResult(0x6f, 0, (byte[])null);
591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 break;
594
Derek Tan4d5e5c12014-02-04 11:54:58 -0800595 case CMD_SEND_ENVELOPE:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("sendEnvelopeWithStatus: No UICC");
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
604 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
605 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 break;
607
608 case EVENT_SEND_ENVELOPE_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800613 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 if (ar.result == null) {
616 loge("sendEnvelopeWithStatus: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("sendEnvelopeWithStatus: CommandException: " +
619 ar.exception);
620 } else {
621 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
622 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800625 break;
626
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 case CMD_OPEN_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800630 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 if (uiccCard == null) {
632 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800633 request.result = new IccOpenLogicalChannelResponse(-1,
634 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800638 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
639 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
643 case EVENT_OPEN_CHANNEL_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 int[] result = (int[]) ar.result;
649 int channelId = result[0];
650 byte[] selectResponse = null;
651 if (result.length > 1) {
652 selectResponse = new byte[result.length - 1];
653 for (int i = 1; i < result.length; ++i) {
654 selectResponse[i - 1] = (byte) result[i];
655 }
656 }
657 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.result == null) {
661 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 if (ar.exception != null) {
664 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
665 }
666
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700668 if (ar.exception instanceof CommandException) {
669 CommandException.Error error =
670 ((CommandException) (ar.exception)).getCommandError();
671 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700672 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700673 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700674 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 }
676 }
677 openChannelResp = new IccOpenLogicalChannelResponse(
678 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700680 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
684 case CMD_CLOSE_CHANNEL:
685 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800686 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 if (uiccCard == null) {
688 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900689 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
693 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
694 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 break;
696
697 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800698 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
699 break;
700
701 case CMD_NV_READ_ITEM:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
705 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800706 break;
707
708 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 request.result = "";
715 if (ar.result == null) {
716 loge("nvReadItem: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("nvReadItem: CommandException: " +
719 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800721 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 break;
726
Jake Hambye994d462014-02-03 13:10:13 -0800727 case CMD_NV_WRITE_ITEM:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
730 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800731 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700732 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800733 break;
734
735 case EVENT_NV_WRITE_ITEM_DONE:
736 handleNullReturnEvent(msg, "nvWriteItem");
737 break;
738
739 case CMD_NV_WRITE_CDMA_PRL:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800742 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800743 break;
744
745 case EVENT_NV_WRITE_CDMA_PRL_DONE:
746 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
747 break;
748
chen xu6dac5ab2018-10-26 17:39:23 -0700749 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800750 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700751 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800752 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
chen xu6dac5ab2018-10-26 17:39:23 -0700755 case EVENT_RESET_MODEM_CONFIG_DONE:
756 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800757 break;
758
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700759 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
762 request);
763 Phone phone = getPhoneFromRequest(request);
764 if (phone != null) {
765 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
766 } else {
767 loge("isNRDualConnectivityEnabled: No phone object");
768 request.result = false;
769 notifyRequester(request);
770 }
771 break;
772 }
773
774 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
775 ar = (AsyncResult) msg.obj;
776 request = (MainThreadRequest) ar.userObj;
777 if (ar.exception == null && ar.result != null) {
778 request.result = ar.result;
779 } else {
780 // request.result must be set to something non-null
781 // for the calling thread to unblock
782 if (request.result != null) {
783 request.result = ar.result;
784 } else {
785 request.result = false;
786 }
787 if (ar.result == null) {
788 loge("isNRDualConnectivityEnabled: Empty response");
789 } else if (ar.exception instanceof CommandException) {
790 loge("isNRDualConnectivityEnabled: CommandException: "
791 + ar.exception);
792 } else {
793 loge("isNRDualConnectivityEnabled: Unknown exception");
794 }
795 }
796 notifyRequester(request);
797 break;
798
799 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
802 Phone phone = getPhoneFromRequest(request);
803 if (phone != null) {
804 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
805 request.workSource);
806 } else {
807 loge("enableNrDualConnectivity: No phone object");
808 request.result =
809 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
810 notifyRequester(request);
811 }
812 break;
813 }
814
815 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
818 if (ar.exception == null) {
819 request.result =
820 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
821 } else {
822 request.result =
823 TelephonyManager
824 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
825 if (ar.exception instanceof CommandException) {
826 CommandException.Error error =
827 ((CommandException) (ar.exception)).getCommandError();
828 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
829 request.result =
830 TelephonyManager
831 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
832 }
833 loge("enableNrDualConnectivity" + ": CommandException: "
834 + ar.exception);
835 } else {
836 loge("enableNrDualConnectivity" + ": Unknown exception");
837 }
838 }
839 notifyRequester(request);
840 break;
841 }
842
Jake Hamby7c27be32014-03-03 13:25:59 -0800843 case CMD_GET_PREFERRED_NETWORK_TYPE:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700846 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800847 break;
848
849 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result; // Integer
854 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530855 // request.result must be set to something non-null
856 // for the calling thread to unblock
857 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800858 if (ar.result == null) {
859 loge("getPreferredNetworkType: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("getPreferredNetworkType: CommandException: " +
862 ar.exception);
863 } else {
864 loge("getPreferredNetworkType: Unknown exception");
865 }
866 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700867 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800868 break;
869
870 case CMD_SET_PREFERRED_NETWORK_TYPE:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
873 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700874 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 break;
876
877 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
878 handleNullReturnEvent(msg, "setPreferredNetworkType");
879 break;
880
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000881 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
882 request = (MainThreadRequest)msg.obj;
883 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800884 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000885 break;
886
887 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
888 ar = (AsyncResult)msg.obj;
889 request = (MainThreadRequest)ar.userObj;
890 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700891 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000892 break;
893
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800894 case CMD_SET_VOICEMAIL_NUMBER:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
897 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800898 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
899 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800900 break;
901
902 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
903 handleNullReturnEvent(msg, "setVoicemailNumber");
904 break;
905
Stuart Scott54788802015-03-30 13:18:01 -0700906 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
909 request);
910 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
911 break;
912
913 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
914 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
915 break;
916
Shishir Agrawal302c8692015-06-19 13:49:39 -0700917 case CMD_PERFORM_NETWORK_SCAN:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
920 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
921 break;
922
Hall Liua1acea22020-09-18 19:04:59 -0700923 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700926 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
927 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
928 request.argument;
929 int callForwardingReason = args.first;
930 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800931 break;
Hall Liua1acea22020-09-18 19:04:59 -0700932 }
933 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700936 TelephonyManager.CallForwardingInfoCallback callback =
937 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
938 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800939 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700940 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800941 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
942 for (CallForwardInfo callForwardInfo : callForwardInfos) {
943 // Service Class is a bit mask per 3gpp 27.007. Search for
944 // any service for voice call.
945 if ((callForwardInfo.serviceClass
946 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700947 callForwardingInfo = new CallForwardingInfo(true,
948 callForwardInfo.reason,
949 callForwardInfo.number,
950 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800951 break;
952 }
953 }
954 // Didn't find a call forward info for voice call.
955 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700956 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
957 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800958 }
Hall Liua1acea22020-09-18 19:04:59 -0700959 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800960 } else {
961 if (ar.result == null) {
962 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
963 }
964 if (ar.exception != null) {
965 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
966 }
Hall Liuae527aa2020-09-29 17:10:18 -0700967 int errorCode = TelephonyManager
968 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700973 errorCode = TelephonyManager
974 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700976 errorCode = TelephonyManager
977 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800978 }
979 }
Hall Liua1acea22020-09-18 19:04:59 -0700980 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800981 }
sqian80370722020-01-29 15:02:51 -0800982 break;
Hall Liua1acea22020-09-18 19:04:59 -0700983 }
sqian80370722020-01-29 15:02:51 -0800984
Hall Liua1acea22020-09-18 19:04:59 -0700985 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700988 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800989 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -0700990 ((Pair<CallForwardingInfo, Consumer<Integer>>)
991 request.argument).first;
992 request.phone.setCallForwardingOption(
993 callForwardingInfoToSet.isEnabled()
994 ? CommandsInterface.CF_ACTION_ENABLE
995 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -0800996 callForwardingInfoToSet.getReason(),
997 callForwardingInfoToSet.getNumber(),
998 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
999 break;
Hall Liua1acea22020-09-18 19:04:59 -07001000 }
sqian80370722020-01-29 15:02:51 -08001001
Hall Liua1acea22020-09-18 19:04:59 -07001002 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001005 Consumer<Integer> callback =
1006 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1007 request.argument).second;
1008 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001009 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001010 int errorCode = TelephonyManager.CallForwardingInfoCallback
1011 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001012 if (ar.exception instanceof CommandException) {
1013 CommandException.Error error =
1014 ((CommandException) (ar.exception)).getCommandError();
1015 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001016 errorCode = TelephonyManager.CallForwardingInfoCallback
1017 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001018 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001019 errorCode = TelephonyManager.CallForwardingInfoCallback
1020 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001021 }
1022 }
1023 callback.accept(errorCode);
1024 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001025 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001026 }
sqian80370722020-01-29 15:02:51 -08001027 break;
Hall Liua1acea22020-09-18 19:04:59 -07001028 }
sqian80370722020-01-29 15:02:51 -08001029
Hall Liua1acea22020-09-18 19:04:59 -07001030 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1033 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1034 break;
Hall Liua1acea22020-09-18 19:04:59 -07001035 }
sqian80370722020-01-29 15:02:51 -08001036
Hall Liua1acea22020-09-18 19:04:59 -07001037 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001040 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001041 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1042 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001043 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001044 // Service Class is a bit mask per 3gpp 27.007.
1045 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001046 if (callForwardResults.length > 1
1047 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001048 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001049 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001050 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1051 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001052 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001053 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001054 }
1055 } else {
1056 if (ar.result == null) {
1057 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1058 }
1059 if (ar.exception != null) {
1060 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1061 }
1062 if (ar.exception instanceof CommandException) {
1063 CommandException.Error error =
1064 ((CommandException) (ar.exception)).getCommandError();
1065 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1066 callForwardingStatus =
1067 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1068 }
1069 }
1070 }
Hall Liua1acea22020-09-18 19:04:59 -07001071 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001072 break;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
sqian80370722020-01-29 15:02:51 -08001074
Hall Liua1acea22020-09-18 19:04:59 -07001075 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001078 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1079 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001080 break;
Hall Liua1acea22020-09-18 19:04:59 -07001081 }
sqian80370722020-01-29 15:02:51 -08001082
Hall Liua1acea22020-09-18 19:04:59 -07001083 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001086 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1087 Consumer<Integer> callback =
1088 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1089 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001090 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001091 if (ar.exception instanceof CommandException) {
1092 CommandException.Error error =
1093 ((CommandException) (ar.exception)).getCommandError();
1094 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1095 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1096 } else {
1097 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1098 }
1099 } else {
1100 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1101 }
1102 } else {
1103 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1104 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001105 }
sqian80370722020-01-29 15:02:51 -08001106 break;
Hall Liua1acea22020-09-18 19:04:59 -07001107 }
sqian80370722020-01-29 15:02:51 -08001108
Shishir Agrawal302c8692015-06-19 13:49:39 -07001109 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 CellNetworkScanResult cellScanResult;
1113 if (ar.exception == null && ar.result != null) {
1114 cellScanResult = new CellNetworkScanResult(
1115 CellNetworkScanResult.STATUS_SUCCESS,
1116 (List<OperatorInfo>) ar.result);
1117 } else {
1118 if (ar.result == null) {
1119 loge("getCellNetworkScanResults: Empty response");
1120 }
1121 if (ar.exception != null) {
1122 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1123 }
1124 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1129 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1130 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1131 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1132 }
1133 }
1134 cellScanResult = new CellNetworkScanResult(errorCode, null);
1135 }
1136 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001137 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001138 break;
1139
1140 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1141 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001142 ManualNetworkSelectionArgument selArg =
1143 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001144 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1145 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001146 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1147 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001148 break;
1149
1150 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
1153 if (ar.exception == null) {
1154 request.result = true;
1155 } else {
1156 request.result = false;
1157 loge("setNetworkSelectionModeManual " + ar.exception);
1158 }
1159 notifyRequester(request);
1160 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001161 break;
1162
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001163 case CMD_GET_MODEM_ACTIVITY_INFO:
1164 request = (MainThreadRequest) msg.obj;
1165 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001166 if (defaultPhone != null) {
1167 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001168 } else {
1169 ResultReceiver result = (ResultReceiver) request.argument;
1170 Bundle bundle = new Bundle();
1171 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1172 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1173 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001174 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001175 break;
1176
1177 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001180 ResultReceiver result = (ResultReceiver) request.argument;
1181
1182 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001183 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001184 // Update the last modem activity info and the result of the request.
1185 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1186 if (isModemActivityInfoValid(info)) {
1187 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1188 int[] txTimeMs = info.getTransmitTimeMillis();
1189 int[] lastModemTxTimeMs = mLastModemActivityInfo
1190 .getTransmitTimeMillis();
1191 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1192 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1193 }
1194 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1195 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1196 + mLastModemActivityInfo.getSleepTimeMillis());
1197 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1198 + mLastModemActivityInfo.getIdleTimeMillis());
1199 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1200 mLastModemActivityInfo.setReceiveTimeMillis(
1201 info.getReceiveTimeMillis()
1202 + mLastModemActivityInfo.getReceiveTimeMillis());
1203 }
1204 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1205 mLastModemActivityInfo.getSleepTimeMillis(),
1206 mLastModemActivityInfo.getIdleTimeMillis(),
1207 mLastModemActivityInfo.getTransmitTimeMillis(),
1208 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001209 } else {
1210 if (ar.result == null) {
1211 loge("queryModemActivityInfo: Empty response");
1212 } else if (ar.exception instanceof CommandException) {
1213 loge("queryModemActivityInfo: CommandException: " +
1214 ar.exception);
1215 } else {
1216 loge("queryModemActivityInfo: Unknown exception");
1217 }
1218 }
sqian1a1be542020-03-05 11:37:28 -08001219 Bundle bundle = new Bundle();
1220 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1221 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001223 break;
1224
Meng Wang1a7c35a2016-05-05 20:56:15 -07001225 case CMD_SET_ALLOWED_CARRIERS:
1226 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001227 CarrierRestrictionRules argument =
1228 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001229 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001230 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001231 break;
1232
1233 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
1236 if (ar.exception == null && ar.result != null) {
1237 request.result = ar.result;
1238 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001239 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1240 if (ar.exception instanceof CommandException) {
1241 loge("setAllowedCarriers: CommandException: " + ar.exception);
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1245 request.result =
1246 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001248 } else {
1249 loge("setAllowedCarriers: Unknown exception");
1250 }
1251 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001252 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001253 break;
1254
1255 case CMD_GET_ALLOWED_CARRIERS:
1256 request = (MainThreadRequest) msg.obj;
1257 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001258 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001259 break;
1260
1261 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 if (ar.exception == null && ar.result != null) {
1265 request.result = ar.result;
1266 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001267 request.result = new IllegalStateException(
1268 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 if (ar.result == null) {
1270 loge("getAllowedCarriers: Empty response");
1271 } else if (ar.exception instanceof CommandException) {
1272 loge("getAllowedCarriers: CommandException: " +
1273 ar.exception);
1274 } else {
1275 loge("getAllowedCarriers: Unknown exception");
1276 }
1277 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001278 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 break;
1280
Nathan Haroldb3014052017-01-25 15:57:32 -08001281 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 if (ar.exception == null && ar.result != null) {
1285 request.result = ar.result;
1286 } else {
1287 request.result = new IllegalArgumentException(
1288 "Failed to retrieve Forbidden Plmns");
1289 if (ar.result == null) {
1290 loge("getForbiddenPlmns: Empty response");
1291 } else {
1292 loge("getForbiddenPlmns: Unknown exception");
1293 }
1294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001296 break;
1297
1298 case CMD_GET_FORBIDDEN_PLMNS:
1299 request = (MainThreadRequest) msg.obj;
1300 uiccCard = getUiccCardFromRequest(request);
1301 if (uiccCard == null) {
1302 loge("getForbiddenPlmns() UiccCard is null");
1303 request.result = new IllegalArgumentException(
1304 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001305 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001306 break;
1307 }
1308 Integer appType = (Integer) request.argument;
1309 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1310 if (uiccApp == null) {
1311 loge("getForbiddenPlmns() no app with specified type -- "
1312 + appType);
1313 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001315 break;
1316 } else {
1317 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1318 + " specified type -- " + appType);
1319 }
1320 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1321 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1322 onCompleted);
1323 break;
1324
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001325 case CMD_SWITCH_SLOTS:
1326 request = (MainThreadRequest) msg.obj;
1327 int[] physicalSlots = (int[]) request.argument;
1328 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1329 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1330 break;
1331
1332 case EVENT_SWITCH_SLOTS_DONE:
1333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
1335 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001336 notifyRequester(request);
1337 break;
1338 case CMD_GET_NETWORK_SELECTION_MODE:
1339 request = (MainThreadRequest) msg.obj;
1340 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1341 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1342 break;
1343
1344 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 if (ar.exception != null) {
1348 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1349 } else {
1350 int mode = ((int[]) ar.result)[0];
1351 if (mode == 0) {
1352 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1353 } else {
1354 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1355 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
1358 break;
1359 case CMD_GET_CDMA_ROAMING_MODE:
1360 request = (MainThreadRequest) msg.obj;
1361 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1362 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1363 break;
1364 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 if (ar.exception != null) {
1368 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1369 } else {
1370 request.result = ((int[]) ar.result)[0];
1371 }
1372 notifyRequester(request);
1373 break;
1374 case CMD_SET_CDMA_ROAMING_MODE:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1377 int mode = (int) request.argument;
1378 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1379 break;
1380 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
1383 request.result = ar.exception == null;
1384 notifyRequester(request);
1385 break;
1386 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1387 request = (MainThreadRequest) msg.obj;
1388 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1389 int subscriptionMode = (int) request.argument;
1390 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1391 break;
1392 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 request.result = ar.exception == null;
1396 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001397 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001398 case CMD_GET_ALL_CELL_INFO:
1399 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001400 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001401 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001402 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001403 case EVENT_GET_ALL_CELL_INFO_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001406 // If a timeout occurs, the response will be null
1407 request.result = (ar.exception == null && ar.result != null)
1408 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001409 synchronized (request) {
1410 request.notifyAll();
1411 }
1412 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001413 case CMD_REQUEST_CELL_INFO_UPDATE:
1414 request = (MainThreadRequest) msg.obj;
1415 request.phone.requestCellInfoUpdate(request.workSource,
1416 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1417 break;
1418 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1422 try {
1423 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001424 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001425 cb.onError(
1426 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1427 ar.exception.getClass().getName(),
1428 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001429 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001430 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001431 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001432 } else {
1433 // use the result as returned
1434 cb.onCellInfo((List<CellInfo>) ar.result);
1435 }
1436 } catch (RemoteException re) {
1437 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1438 }
1439 break;
1440 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001441 request = (MainThreadRequest) msg.obj;
1442 WorkSource ws = (WorkSource) request.argument;
1443 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001444 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001446 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null) {
1450 request.result = ar.result;
1451 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001452 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001454 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 }
1456
1457 synchronized (request) {
1458 request.notifyAll();
1459 }
1460 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001461 case CMD_MODEM_REBOOT:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001464 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001465 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001466 case EVENT_CMD_MODEM_REBOOT_DONE:
1467 handleNullReturnEvent(msg, "rebootModem");
1468 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001469 case CMD_REQUEST_ENABLE_MODEM:
1470 request = (MainThreadRequest) msg.obj;
1471 boolean enable = (boolean) request.argument;
1472 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001473 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001474 PhoneConfigurationManager.getInstance()
1475 .enablePhone(request.phone, enable, onCompleted);
1476 break;
1477 case EVENT_ENABLE_MODEM_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001481 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001482 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001483 if ((boolean) request.result) {
1484 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1485 updateModemStateMetrics();
1486 } else {
1487 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1488 + ar.exception);
1489 }
1490 notifyRequester(request);
1491 break;
1492 case CMD_GET_MODEM_STATUS:
1493 request = (MainThreadRequest) msg.obj;
1494 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1495 PhoneConfigurationManager.getInstance()
1496 .getPhoneStatusFromModem(request.phone, onCompleted);
1497 break;
1498 case EVENT_GET_MODEM_STATUS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 int id = request.phone.getPhoneId();
1502 if (ar.exception == null && ar.result != null) {
1503 request.result = ar.result;
1504 //update the cache as modem status has changed
1505 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1506 (boolean) request.result);
1507 } else {
1508 // Return true if modem status cannot be retrieved. For most cases,
1509 // modem status is on. And for older version modems, GET_MODEM_STATUS
1510 // and disable modem are not supported. Modem is always on.
1511 // TODO: this should be fixed in R to support a third
1512 // status UNKNOWN b/131631629
1513 request.result = true;
1514 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1515 + ar.exception);
1516 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001517 notifyRequester(request);
1518 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001519 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1520 request = (MainThreadRequest) msg.obj;
1521 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1522 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1523 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1524 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1525 break;
1526 }
1527 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1531 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1532 args.second.accept(ar.exception == null);
1533 notifyRequester(request);
1534 break;
1535 }
yincheng zhaod698b842019-09-06 17:06:54 -07001536 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 if (ar.exception == null && ar.result != null) {
1540 request.result = ar.result;
1541 } else {
1542 request.result = -1;
1543 loge("Failed to set Forbidden Plmns");
1544 if (ar.result == null) {
1545 loge("setForbidenPlmns: Empty response");
1546 } else if (ar.exception != null) {
1547 loge("setForbiddenPlmns: Exception: " + ar.exception);
1548 request.result = -1;
1549 } else {
1550 loge("setForbiddenPlmns: Unknown exception");
1551 }
1552 }
1553 notifyRequester(request);
1554 break;
1555 case CMD_SET_FORBIDDEN_PLMNS:
1556 request = (MainThreadRequest) msg.obj;
1557 uiccCard = getUiccCardFromRequest(request);
1558 if (uiccCard == null) {
1559 loge("setForbiddenPlmns: UiccCard is null");
1560 request.result = -1;
1561 notifyRequester(request);
1562 break;
1563 }
1564 Pair<Integer, List<String>> setFplmnsArgs =
1565 (Pair<Integer, List<String>>) request.argument;
1566 appType = setFplmnsArgs.first;
1567 List<String> fplmns = setFplmnsArgs.second;
1568 uiccApp = uiccCard.getApplicationByType(appType);
1569 if (uiccApp == null) {
1570 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1571 request.result = -1;
1572 loge("Failed to get UICC App");
1573 notifyRequester(request);
1574 } else {
1575 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1576 ((SIMRecords) uiccApp.getIccRecords())
1577 .setForbiddenPlmns(onCompleted, fplmns);
1578 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001579 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001580 case CMD_ERASE_MODEM_CONFIG:
1581 request = (MainThreadRequest) msg.obj;
1582 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1583 defaultPhone.eraseModemConfig(onCompleted);
1584 break;
1585 case EVENT_ERASE_MODEM_CONFIG_DONE:
1586 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001587 break;
zoey chenf95ca592019-12-30 16:11:23 +08001588
1589 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1592 Pair<String, String> changed = (Pair<String, String>) request.argument;
1593 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1594 changed.first, changed.second, onCompleted);
1595 break;
1596 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 if (ar.exception == null) {
1600 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1601 } else {
1602 request.result = msg.arg1;
1603 }
1604 notifyRequester(request);
1605 break;
1606
1607 case CMD_SET_ICC_LOCK_ENABLED:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1610 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1611 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1612 enabled.first, enabled.second, onCompleted);
1613 break;
1614 case EVENT_SET_ICC_LOCK_ENABLED_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
Peter Wangdafb9ac2020-01-15 14:13:38 -08001625 case MSG_NOTIFY_USER_ACTIVITY:
1626 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001627 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001628 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1629 getDefaultPhone().getContext().sendBroadcastAsUser(
1630 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1631 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 default:
1633 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1634 break;
1635 }
1636 }
Jake Hambye994d462014-02-03 13:10:13 -08001637
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 private void notifyRequester(MainThreadRequest request) {
1639 synchronized (request) {
1640 request.notifyAll();
1641 }
1642 }
1643
Jake Hambye994d462014-02-03 13:10:13 -08001644 private void handleNullReturnEvent(Message msg, String command) {
1645 AsyncResult ar = (AsyncResult) msg.obj;
1646 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception == null) {
1648 request.result = true;
1649 } else {
1650 request.result = false;
1651 if (ar.exception instanceof CommandException) {
1652 loge(command + ": CommandException: " + ar.exception);
1653 } else {
1654 loge(command + ": Unknown exception");
1655 }
1656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001657 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
1661 /**
1662 * Posts the specified command to be executed on the main thread,
1663 * waits for the request to complete, and returns the result.
1664 * @see #sendRequestAsync
1665 */
1666 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001667 return sendRequest(
1668 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001669 }
1670
1671 /**
1672 * Posts the specified command to be executed on the main thread,
1673 * waits for the request to complete, and returns the result.
1674 * @see #sendRequestAsync
1675 */
1676 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1677 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001678 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001679 }
1680
1681 /**
1682 * Posts the specified command to be executed on the main thread,
1683 * waits for the request to complete, and returns the result.
1684 * @see #sendRequestAsync
1685 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001686 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001687 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001688 }
1689
1690 /**
1691 * Posts the specified command to be executed on the main thread,
1692 * waits for the request to complete, and returns the result.
1693 * @see #sendRequestAsync
1694 */
Nathan Harold92bed182018-10-12 18:16:49 -07001695 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1696 return sendRequest(command, argument, subId, null, workSource);
1697 }
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 */
1704 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1705 return sendRequest(
1706 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1707 }
1708
1709 /**
1710 * Posts the specified command to be executed on the main thread,
1711 * waits for the request to complete, and returns the result.
1712 * @see #sendRequestAsync
1713 */
1714 private Object sendRequest(
1715 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1717 throw new RuntimeException("This method will deadlock if called from the main thread.");
1718 }
1719
Nathan Harold92bed182018-10-12 18:16:49 -07001720 MainThreadRequest request = null;
1721 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1722 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1723 } else if (phone != null) {
1724 request = new MainThreadRequest(argument, phone, workSource);
1725 } else {
1726 request = new MainThreadRequest(argument, subId, workSource);
1727 }
1728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 Message msg = mMainThreadHandler.obtainMessage(command, request);
1730 msg.sendToTarget();
1731
1732 // Wait for the request to complete
1733 synchronized (request) {
1734 while (request.result == null) {
1735 try {
1736 request.wait();
1737 } catch (InterruptedException e) {
1738 // Do nothing, go back and wait until the request is complete
1739 }
1740 }
1741 }
1742 return request.result;
1743 }
1744
1745 /**
1746 * Asynchronous ("fire and forget") version of sendRequest():
1747 * Posts the specified command to be executed on the main thread, and
1748 * returns immediately.
1749 * @see #sendRequest
1750 */
1751 private void sendRequestAsync(int command) {
1752 mMainThreadHandler.sendEmptyMessage(command);
1753 }
1754
1755 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001756 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001757 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001758 */
1759 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001760 sendRequestAsync(command, argument, null, null);
1761 }
1762
1763 /**
1764 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1765 * @see {@link #sendRequest(int,Object)}
1766 */
1767 private void sendRequestAsync(
1768 int command, Object argument, Phone phone, WorkSource workSource) {
1769 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001770 Message msg = mMainThreadHandler.obtainMessage(command, request);
1771 msg.sendToTarget();
1772 }
1773
1774 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 * Initialize the singleton PhoneInterfaceManager instance.
1776 * This is only done once, at startup, from PhoneApp.onCreate().
1777 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001778 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 synchronized (PhoneInterfaceManager.class) {
1780 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001781 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 } else {
1783 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1784 }
1785 return sInstance;
1786 }
1787 }
1788
1789 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001790 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001793 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001794 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1796 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001797 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001798 mTelephonySharedPreferences =
1799 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001800 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001801 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001802 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001803
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 publish();
1805 }
1806
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001807 private Phone getDefaultPhone() {
1808 Phone thePhone = getPhone(getDefaultSubscription());
1809 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1810 }
1811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 private void publish() {
1813 if (DBG) log("publish: " + this);
1814
Peter Wangc035ce42020-01-08 21:00:22 -08001815 TelephonyFrameworkInitializer
1816 .getTelephonyServiceManager()
1817 .getTelephonyServiceRegisterer()
1818 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820
Stuart Scott584921c2015-01-15 17:10:34 -08001821 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001822 if (request.phone != null) {
1823 return request.phone;
1824 } else {
1825 return getPhoneFromSubId(request.subId);
1826 }
1827 }
1828
1829 private Phone getPhoneFromSubId(int subId) {
1830 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1831 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001832 }
1833
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001834 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1835 Phone phone = getPhoneFromRequest(request);
1836 return phone == null ? null :
1837 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1838 }
1839
Wink Saville36469e72014-06-11 15:17:00 -07001840 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001841 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001842 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001845 private void sendEraseModemConfig(Phone phone) {
1846 if (phone != null) {
1847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1848 mApp, phone.getSubId(), "eraseModemConfig");
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1852 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
1855 }
1856 }
1857 }
1858
Peter Wang050bb052020-01-13 23:33:09 -08001859 private boolean isImsAvailableOnDevice() {
1860 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1861 if (pm == null) {
1862 // For some reason package manger is not available.. This will fail internally anyway,
1863 // so do not throw error and allow.
1864 return true;
1865 }
1866 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1867 }
1868
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001870 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001871 }
1872
Wink Savilleb564aae2014-10-23 10:18:09 -07001873 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 if (DBG) log("dial: " + number);
1875 // No permission check needed here: This is just a wrapper around the
1876 // ACTION_DIAL intent, which is available to any app since it puts up
1877 // the UI before it does anything.
1878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 String url = createTelUrl(number);
1882 if (url == null) {
1883 return;
1884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 // PENDING: should we just silently fail if phone is offhook or ringing?
1887 PhoneConstants.State state = mCM.getState(subId);
1888 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1889 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1890 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1891 mApp.startActivity(intent);
1892 }
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896 }
1897
1898 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001899 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 if (DBG) log("call: " + number);
1904
1905 // This is just a wrapper around the ACTION_CALL intent, but we still
1906 // need to do a permission check since we're calling startActivity()
1907 // from the context of the phone app.
1908 enforceCallPermission();
1909
Jordan Liu1617b712019-07-10 15:06:26 -07001910 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 != AppOpsManager.MODE_ALLOWED) {
1912 return;
1913 }
1914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 String url = createTelUrl(number);
1918 if (url == null) {
1919 return;
1920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001922 boolean isValid = false;
1923 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1924 if (slist != null) {
1925 for (SubscriptionInfo subInfoRecord : slist) {
1926 if (subInfoRecord.getSubscriptionId() == subId) {
1927 isValid = true;
1928 break;
1929 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001930 }
Wink Saville08874612014-08-31 19:19:58 -07001931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932 if (!isValid) {
1933 return;
1934 }
Wink Saville08874612014-08-31 19:19:58 -07001935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1937 intent.putExtra(SUBSCRIPTION_KEY, subId);
1938 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1939 mApp.startActivity(intent);
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Wink Savilleb564aae2014-10-23 10:18:09 -07001945 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001946 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001947 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1948 }
1949
Wink Savilleb564aae2014-10-23 10:18:09 -07001950 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001951 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001952 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1953 }
1954
Wink Savilleb564aae2014-10-23 10:18:09 -07001955 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957
1958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1961 checkSimPin.start();
1962 return checkSimPin.unlockSim(null, pin);
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
Wink Savilleb564aae2014-10-23 10:18:09 -07001968 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001970
1971 final long identity = Binder.clearCallingIdentity();
1972 try {
1973 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1974 checkSimPuk.start();
1975 return checkSimPuk.unlockSim(puk, pin);
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
1978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
1981 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001982 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 * a synchronous one.
1984 */
1985 private static class UnlockSim extends Thread {
1986
1987 private final IccCard mSimCard;
1988
1989 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001990 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1991 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992
1993 // For replies from SimCard interface
1994 private Handler mHandler;
1995
1996 // For async handler to identify request type
1997 private static final int SUPPLY_PIN_COMPLETE = 100;
1998
1999 public UnlockSim(IccCard simCard) {
2000 mSimCard = simCard;
2001 }
2002
2003 @Override
2004 public void run() {
2005 Looper.prepare();
2006 synchronized (UnlockSim.this) {
2007 mHandler = new Handler() {
2008 @Override
2009 public void handleMessage(Message msg) {
2010 AsyncResult ar = (AsyncResult) msg.obj;
2011 switch (msg.what) {
2012 case SUPPLY_PIN_COMPLETE:
2013 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2014 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002015 mRetryCount = msg.arg1;
2016 if (ar.exception != null) {
2017 if (ar.exception instanceof CommandException &&
2018 ((CommandException)(ar.exception)).getCommandError()
2019 == CommandException.Error.PASSWORD_INCORRECT) {
2020 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002021 } //When UiccCardApp dispose,handle message and return exception
2022 else if (ar.exception instanceof CommandException &&
2023 ((CommandException) (ar.exception)).getCommandError()
2024 == CommandException.Error.ABORTED) {
2025 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002026 } else {
2027 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2028 }
2029 } else {
2030 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 mDone = true;
2033 UnlockSim.this.notifyAll();
2034 }
2035 break;
2036 }
2037 }
2038 };
2039 UnlockSim.this.notifyAll();
2040 }
2041 Looper.loop();
2042 }
2043
2044 /*
2045 * Use PIN or PUK to unlock SIM card
2046 *
2047 * If PUK is null, unlock SIM card with PIN
2048 *
2049 * If PUK is not null, unlock SIM card with PUK and set PIN code
2050 */
Wink Saville9de0f752013-10-22 19:04:03 -07002051 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052
2053 while (mHandler == null) {
2054 try {
2055 wait();
2056 } catch (InterruptedException e) {
2057 Thread.currentThread().interrupt();
2058 }
2059 }
2060 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2061
2062 if (puk == null) {
2063 mSimCard.supplyPin(pin, callback);
2064 } else {
2065 mSimCard.supplyPuk(puk, pin, callback);
2066 }
2067
2068 while (!mDone) {
2069 try {
2070 Log.d(LOG_TAG, "wait for done");
2071 wait();
2072 } catch (InterruptedException e) {
2073 // Restore the interrupted status
2074 Thread.currentThread().interrupt();
2075 }
2076 }
2077 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002078 int[] resultArray = new int[2];
2079 resultArray[0] = mResult;
2080 resultArray[1] = mRetryCount;
2081 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 }
2083 }
2084
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002085 /**
2086 * This method has been removed due to privacy and stability concerns.
2087 */
2088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002090 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2091 return;
Wink Saville36469e72014-06-11 15:17:00 -07002092 }
2093
Nathan Harold1f889d82020-06-04 17:05:26 -07002094 @Override
2095 public void updateServiceLocationWithPackageName(String callingPackage) {
2096 mApp.getSystemService(AppOpsManager.class)
2097 .checkPackage(Binder.getCallingUid(), callingPackage);
2098
2099 final int targetSdk = getTargetSdk(callingPackage);
2100 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2101 // Callers targeting S have no business invoking this method.
2102 return;
2103 }
2104
2105 LocationAccessPolicy.LocationPermissionResult locationResult =
2106 LocationAccessPolicy.checkLocationPermission(mApp,
2107 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2108 .setCallingPackage(callingPackage)
2109 .setCallingFeatureId(null)
2110 .setCallingPid(Binder.getCallingPid())
2111 .setCallingUid(Binder.getCallingUid())
2112 .setMethod("updateServiceLocation")
2113 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2114 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2115 .build());
2116 // Apps that lack location permission have no business calling this method;
2117 // however, because no permission was declared in the public API, denials must
2118 // all be "soft".
2119 switch (locationResult) {
2120 case DENIED_HARD: /* fall through */
2121 case DENIED_SOFT:
2122 return;
2123 }
2124
2125 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 final long identity = Binder.clearCallingIdentity();
2127 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002128 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002129 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002130 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002137 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 @Override
2139 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002140 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002141 }
2142
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002143
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002144 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002145 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2146 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2147 callingFeatureId);
2148 }
2149
2150 @Deprecated
2151 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002152 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002153 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2154 }
2155
2156 @Override
2157 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2158 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002160 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002161 return false;
2162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 return isRadioOnForSubscriber(subId);
2167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 }
2171
2172 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2178 } else {
2179 return false;
2180 }
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
2186 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002187 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
Wink Saville36469e72014-06-11 15:17:00 -07002189
Wink Savilleb564aae2014-10-23 10:18:09 -07002190 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
2197 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2198 }
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 }
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
2204 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002205 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002206 }
2207
Wink Savilleb564aae2014-10-23 10:18:09 -07002208 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -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 return false;
2216 }
2217 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2218 toggleRadioOnOffForSubscriber(subId);
2219 }
2220 return true;
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
Wink Saville36469e72014-06-11 15:17:00 -07002225
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002226 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002227 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002228 /*
2229 * If any of the Radios are available, it will need to be
2230 * shutdown. So return true if any Radio is available.
2231 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 final long identity = Binder.clearCallingIdentity();
2233 try {
2234 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2235 Phone phone = PhoneFactory.getPhone(i);
2236 if (phone != null && phone.isRadioAvailable()) return true;
2237 }
2238 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2239 return false;
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002242 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002243 }
2244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002246 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 enforceModifyPermission();
2248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2252 logv("Shutting down Phone " + i);
2253 shutdownRadioUsingPhoneId(i);
2254 }
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002257 }
2258 }
2259
2260 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002261 Phone phone = PhoneFactory.getPhone(phoneId);
2262 if (phone != null && phone.isRadioAvailable()) {
2263 phone.shutdownRadio();
2264 }
2265 }
2266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002268 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2273 if (defaultPhone != null) {
2274 defaultPhone.setRadioPower(turnOn);
2275 return true;
2276 } else {
2277 loge("There's no default phone.");
2278 return false;
2279 }
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002282 }
Wink Saville36469e72014-06-11 15:17:00 -07002283 }
2284
Wink Savilleb564aae2014-10-23 10:18:09 -07002285 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone phone = getPhone(subId);
2291 if (phone != null) {
2292 phone.setRadioPower(turnOn);
2293 return true;
2294 } else {
2295 return false;
2296 }
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
Wink Saville36469e72014-06-11 15:17:00 -07002302 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 public boolean enableDataConnectivity() {
2305 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 int subId = mSubscriptionController.getDefaultDataSubId();
2310 final Phone phone = getPhone(subId);
2311 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002312 phone.getDataEnabledSettings().setDataEnabled(
2313 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314 return true;
2315 } else {
2316 return false;
2317 }
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
Wink Saville36469e72014-06-11 15:17:00 -07002323 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 public boolean disableDataConnectivity() {
2326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 int subId = mSubscriptionController.getDefaultDataSubId();
2331 final Phone phone = getPhone(subId);
2332 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002333 phone.getDataEnabledSettings().setDataEnabled(
2334 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 return true;
2336 } else {
2337 return false;
2338 }
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002345 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
2349 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002350 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 } else {
2352 return false;
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
2359 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002360 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002361 }
2362
pkanwarae03a6b2016-11-06 20:37:09 -08002363 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364 enforceCallPermission();
2365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2369 return;
2370 }
2371 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2372 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
2375 }
pkanwar32d516d2016-10-14 19:37:38 -07002376 };
2377
Wink Savilleb564aae2014-10-23 10:18:09 -07002378 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2384 return false;
2385 }
2386 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002393 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002394 }
2395
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002396 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 Phone phone = PhoneFactory.getPhone(slotIndex);
2400 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2401 PhoneConstantConversions.convertCallState(phone.getState());
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002408 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002409 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2410 }
2411
2412 @Override
2413 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002414 final long identity = Binder.clearCallingIdentity();
2415 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002416 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 if (phone != null) {
2418 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2419 } else {
2420 return PhoneConstantConversions.convertDataState(
2421 PhoneConstants.DataState.DISCONNECTED);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002429 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002430 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2431 }
2432
2433 @Override
2434 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 final long identity = Binder.clearCallingIdentity();
2436 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438 if (phone != null) {
2439 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2440 } else {
2441 return TelephonyManager.DATA_ACTIVITY_NONE;
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 }
2447
2448 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002449 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002450 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002451 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002452
2453 LocationAccessPolicy.LocationPermissionResult locationResult =
2454 LocationAccessPolicy.checkLocationPermission(mApp,
2455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2456 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002458 .setCallingPid(Binder.getCallingPid())
2459 .setCallingUid(Binder.getCallingUid())
2460 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002462 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2463 .build());
2464 switch (locationResult) {
2465 case DENIED_HARD:
2466 throw new SecurityException("Not allowed to access cell location");
2467 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002468 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2469 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 }
2471
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002476 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002477 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
Svetoslav64fad262015-04-14 14:35:21 -07002481 }
2482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 @Override
Jack Yu01425032020-02-22 19:38:58 -08002484 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002485 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2486 // registered cell info, so return a NULL country instead.
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002489 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2490 // Get default phone in this case.
2491 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2492 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002493 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002495 if (phone == null) return "";
2496 ServiceStateTracker sst = phone.getServiceStateTracker();
2497 if (sst == null) return "";
2498 LocaleTracker lt = sst.getLocaleTracker();
2499 if (lt == null) return "";
2500 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2501 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2502 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002503 } finally {
2504 Binder.restoreCallingIdentity(identity);
2505 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002506 }
2507
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002508 /**
2509 * This method was removed due to potential issues caused by performing partial
2510 * updates of service state, and lack of a credible use case.
2511 *
2512 * This has the ability to break the telephony implementation by disabling notification of
2513 * changes in device connectivity. DO NOT USE THIS!
2514 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002515 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public void enableLocationUpdates() {
2517 mApp.enforceCallingOrSelfPermission(
2518 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002521 /**
2522 * This method was removed due to potential issues caused by performing partial
2523 * updates of service state, and lack of a credible use case.
2524 *
2525 * This has the ability to break the telephony implementation by disabling notification of
2526 * changes in device connectivity. DO NOT USE THIS!
2527 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 @Override
2529 public void disableLocationUpdates() {
2530 mApp.enforceCallingOrSelfPermission(
2531 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
Nathan Harold31d7ff32018-10-15 20:20:30 -07002534 /**
2535 * Returns the target SDK version number for a given package name.
2536 *
Nathan Haroldec184742019-07-10 17:04:16 -07002537 * This call MUST be invoked before clearing the calling UID.
2538 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002539 * @return target SDK if the package is found or INT_MAX.
2540 */
2541 private int getTargetSdk(String packageName) {
2542 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002543 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002544 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002545 if (ai != null) return ai.targetSdkVersion;
2546 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002547 loge("Failed to get package info for pkg="
2548 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002549 }
2550 return Integer.MAX_VALUE;
2551 }
2552
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 @Override
2554 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002555 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2556 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002557 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002558 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2559 throw new SecurityException(
2560 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2561 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002562
Jordan Liu1617b712019-07-10 15:06:26 -07002563 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2565 return null;
2566 }
Svetoslav64fad262015-04-14 14:35:21 -07002567
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002568 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002571 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572
Nathan Haroldf180aac2018-06-01 18:43:55 -07002573 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2574 for (CellInfo ci : info) {
2575 if (ci instanceof CellInfoGsm) {
2576 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2577 } else if (ci instanceof CellInfoWcdma) {
2578 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002581 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002584 private List<CellInfo> getCachedCellInfo() {
2585 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2586 for (Phone phone : PhoneFactory.getPhones()) {
2587 List<CellInfo> info = phone.getAllCellInfo();
2588 if (info != null) cellInfos.addAll(info);
2589 }
2590 return cellInfos;
2591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002594 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002596 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002597
2598 LocationAccessPolicy.LocationPermissionResult locationResult =
2599 LocationAccessPolicy.checkLocationPermission(mApp,
2600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2601 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002602 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002603 .setCallingPid(Binder.getCallingPid())
2604 .setCallingUid(Binder.getCallingUid())
2605 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002607 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2608 .build());
2609 switch (locationResult) {
2610 case DENIED_HARD:
2611 throw new SecurityException("Not allowed to access cell info");
2612 case DENIED_SOFT:
2613 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002616 final int targetSdk = getTargetSdk(callingPackage);
2617 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2618 return getCachedCellInfo();
2619 }
2620
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002621 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002622 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2626 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002627 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002628 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 if (info != null) cellInfos.addAll(info);
2630 }
2631 return cellInfos;
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635 }
2636
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002637 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002638 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2639 String callingFeatureId) {
2640 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2641 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002642 }
2643
2644 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002645 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2646 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002647 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002648 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002649 }
2650
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002651 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2652 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002653 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002654 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002655
2656 LocationAccessPolicy.LocationPermissionResult locationResult =
2657 LocationAccessPolicy.checkLocationPermission(mApp,
2658 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2659 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002660 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002661 .setCallingPid(Binder.getCallingPid())
2662 .setCallingUid(Binder.getCallingUid())
2663 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002664 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2665 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002666 .build());
2667 switch (locationResult) {
2668 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002669 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2670 // Safetynet logging for b/154934934
2671 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2672 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002673 throw new SecurityException("Not allowed to access cell info");
2674 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002675 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2676 // Safetynet logging for b/154934934
2677 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2678 }
Nathan Harold5320c422019-05-09 10:26:08 -07002679 try {
2680 cb.onCellInfo(new ArrayList<CellInfo>());
2681 } catch (RemoteException re) {
2682 // Drop without consequences
2683 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002684 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002685 }
2686
Nathan Harolda939a962019-05-09 10:13:47 -07002687
2688 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002689 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2690
2691 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2692 }
2693
2694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002696 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002701 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 } finally {
2703 Binder.restoreCallingIdentity(identity);
2704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 }
2706
Shishir Agrawala9f32182016-04-12 12:00:16 -07002707 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002708 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002709 Phone phone = PhoneFactory.getPhone(slotIndex);
2710 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 return null;
2712 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002713 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002714 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002715 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002716 return null;
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 return phone.getImei();
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002725 }
2726
2727 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002728 public String getTypeAllocationCodeForSlot(int slotIndex) {
2729 Phone phone = PhoneFactory.getPhone(slotIndex);
2730 String tac = null;
2731 if (phone != null) {
2732 String imei = phone.getImei();
2733 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2734 }
2735 return tac;
2736 }
2737
2738 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002739 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002740 Phone phone = PhoneFactory.getPhone(slotIndex);
2741 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002742 return null;
2743 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744
Jeff Davidson913390f2018-02-23 17:11:49 -08002745 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002746 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002747 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002748 return null;
2749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 return phone.getMeid();
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Jack Yu2af8d712017-03-15 17:14:14 -07002757 }
2758
2759 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002760 public String getManufacturerCodeForSlot(int slotIndex) {
2761 Phone phone = PhoneFactory.getPhone(slotIndex);
2762 String manufacturerCode = null;
2763 if (phone != null) {
2764 String meid = phone.getMeid();
2765 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2766 }
2767 return manufacturerCode;
2768 }
2769
2770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002771 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2772 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002773 Phone phone = PhoneFactory.getPhone(slotIndex);
2774 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002775 return null;
2776 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002777 int subId = phone.getSubId();
2778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002779 mApp, subId, callingPackage, callingFeatureId,
2780 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002781 return null;
2782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 return phone.getDeviceSvn();
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002790 }
2791
fionaxu43304da2017-11-27 22:51:16 -08002792 @Override
2793 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 final Phone phone = getPhone(subId);
2797 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
fionaxu43304da2017-11-27 22:51:16 -08002801 }
2802
2803 @Override
2804 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 final Phone phone = getPhone(subId);
2808 return phone == null ? null : phone.getCarrierName();
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
fionaxu43304da2017-11-27 22:51:16 -08002812 }
2813
calvinpanffe225e2018-11-01 19:43:06 +08002814 @Override
chen xu0026ca62019-03-06 15:28:50 -08002815 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002820 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002821 } finally {
2822 Binder.restoreCallingIdentity(identity);
2823 }
2824 }
2825
2826 @Override
chen xu0026ca62019-03-06 15:28:50 -08002827 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002831 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
2835 }
2836
chen xu651eec72018-11-11 19:03:44 -08002837 @Override
chen xu864e11c2018-12-06 22:10:03 -08002838 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2839 if (!isSubscriptionMccMnc) {
2840 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2841 }
chen xu651eec72018-11-11 19:03:44 -08002842 final Phone phone = PhoneFactory.getPhone(slotIndex);
2843 if (phone == null) {
2844 return TelephonyManager.UNKNOWN_CARRIER_ID;
2845 }
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
2852 }
2853
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 //
2855 // Internal helper methods.
2856 //
2857
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002858 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2860 *
2861 * @throws SecurityException if the caller does not have the required permission
2862 */
2863 private void enforceModifyPermission() {
2864 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2865 }
2866
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002867 /**
2868 * Make sure the caller is system.
2869 *
2870 * @throws SecurityException if the caller is not system.
2871 */
2872 private void enforceSystemCaller() {
2873 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2874 throw new SecurityException("Caller must be system");
2875 }
2876 }
2877
Shuo Qianf2b2df42019-11-13 17:43:31 -08002878 private void enforceActiveEmergencySessionPermission() {
2879 mApp.enforceCallingOrSelfPermission(
2880 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2881 }
2882
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 /**
2884 * Make sure the caller has the CALL_PHONE permission.
2885 *
2886 * @throws SecurityException if the caller does not have the required permission
2887 */
2888 private void enforceCallPermission() {
2889 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2890 }
2891
paulhu423b5f22019-08-23 19:17:33 +08002892 private void enforceSettingsPermission() {
2893 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002894 }
2895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 private String createTelUrl(String number) {
2897 if (TextUtils.isEmpty(number)) {
2898 return null;
2899 }
2900
Jake Hambye994d462014-02-03 13:10:13 -08002901 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
Ihab Awadf9e92732013-12-05 18:02:52 -08002904 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2906 }
2907
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002908 private static void logv(String msg) {
2909 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2910 }
2911
Ihab Awadf9e92732013-12-05 18:02:52 -08002912 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2914 }
2915
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002918 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002919 }
2920
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002922 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 final Phone phone = PhoneFactory.getPhone(slotIndex);
2926 if (phone == null) {
2927 return PhoneConstants.PHONE_TYPE_NONE;
2928 } else {
2929 return phone.getPhoneType();
2930 }
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
2936 /**
2937 * Returns the CDMA ERI icon index to display
2938 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002939 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002940 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2941 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2942 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002943 }
2944
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2947 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002949 mApp, subId, callingPackage, callingFeatureId,
2950 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002951 return -1;
2952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 if (phone != null) {
2958 return phone.getCdmaEriIconIndex();
2959 } else {
2960 return -1;
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 }
2966
2967 /**
2968 * Returns the CDMA ERI icon mode,
2969 * 0 - ON
2970 * 1 - FLASHING
2971 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002972 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002973 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2974 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2975 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002976 }
2977
Sanket Padawe356d7632015-06-22 14:03:32 -07002978 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002979 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2980 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002982 mApp, subId, callingPackage, callingFeatureId,
2983 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002984 return -1;
2985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 final Phone phone = getPhone(subId);
2990 if (phone != null) {
2991 return phone.getCdmaEriIconMode();
2992 } else {
2993 return -1;
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 }
2999
3000 /**
3001 * Returns the CDMA ERI text,
3002 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003003 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003004 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3005 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3006 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003007 }
3008
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003010 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3011 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 mApp, subId, callingPackage, callingFeatureId,
3014 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003015 return null;
3016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 final Phone phone = getPhone(subId);
3021 if (phone != null) {
3022 return phone.getCdmaEriText();
3023 } else {
3024 return null;
3025 }
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030
3031 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003032 * Returns the CDMA MDN.
3033 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003034 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003035 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3037 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 return phone.getLine1Number();
3044 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 return null;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003050 }
3051 }
3052
3053 /**
3054 * Returns the CDMA MIN.
3055 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003056 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003057 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3065 return phone.getCdmaMin();
3066 } else {
3067 return null;
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003071 }
3072 }
3073
Hall Liud892bec2018-11-30 14:51:45 -08003074 @Override
3075 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3076 INumberVerificationCallback callback, String callingPackage) {
3077 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3078 != PERMISSION_GRANTED) {
3079 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3080 }
3081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3082
3083 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3084 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3085 throw new SecurityException("Calling package must be configured in the device config");
3086 }
3087
3088 if (range == null) {
3089 throw new NullPointerException("Range must be non-null");
3090 }
3091
3092 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003093 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003094
3095 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3096 }
3097
Junda Liuca05d5d2014-08-14 22:36:34 -07003098 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 * Returns true if CDMA provisioning needs to run.
3100 */
3101 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
3110 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003111 * Sets the voice mail number of a given subId.
3112 */
3113 @Override
3114 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003115 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3116 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3121 new Pair<String, String>(alphaTag, number), new Integer(subId));
3122 return success;
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003126 }
3127
Ta-wei Yen87c49842016-05-13 21:19:52 -07003128 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003129 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003131 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3132 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003133 if (!TextUtils.equals(callingPackage, systemDialer)) {
3134 throw new SecurityException("caller must be system dialer");
3135 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3140 if (phoneAccountHandle == null) {
3141 return null;
3142 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003146 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003147 }
3148
3149 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003150 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3151 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003152 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003154 mApp, subId, callingPackage, callingFeatureId,
3155 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003156 return null;
3157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003159 final long identity = Binder.clearCallingIdentity();
3160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003165 }
3166
3167 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003168 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3169 VisualVoicemailSmsFilterSettings settings) {
3170 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171
3172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003175 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003179 }
3180
3181 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003182 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003192 }
3193
3194 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003195 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3196 String callingPackage, int subId) {
3197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003206 }
3207
3208 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003209 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003219 }
3220
3221 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003222 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3223 String callingAttributionTag, int subId, String number, int port, String text,
3224 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003225 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003226 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003227 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003228 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003229 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3230 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003231 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003232
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003233 /**
fionaxu0152e512016-11-14 13:36:14 -08003234 * Sets the voice activation state of a given subId.
3235 */
3236 @Override
3237 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3239 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 final Phone phone = getPhone(subId);
3244 if (phone != null) {
3245 phone.setVoiceActivationState(activationState);
3246 } else {
3247 loge("setVoiceActivationState fails with invalid subId: " + subId);
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003251 }
3252 }
3253
3254 /**
3255 * Sets the data activation state of a given subId.
3256 */
3257 @Override
3258 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3260 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 final Phone phone = getPhone(subId);
3265 if (phone != null) {
3266 phone.setDataActivationState(activationState);
3267 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003268 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 }
3270 } finally {
3271 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003272 }
3273 }
3274
3275 /**
3276 * Returns the voice activation state of a given subId.
3277 */
3278 @Override
3279 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
fionaxu0152e512016-11-14 13:36:14 -08003282 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 if (phone != null) {
3286 return phone.getVoiceActivationState();
3287 } else {
3288 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3289 }
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003292 }
3293 }
3294
3295 /**
3296 * Returns the data activation state of a given subId.
3297 */
3298 @Override
3299 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301
fionaxu0152e512016-11-14 13:36:14 -08003302 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 if (phone != null) {
3306 return phone.getDataActivationState();
3307 } else {
3308 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3309 }
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003312 }
3313 }
3314
3315 /**
Wink Saville36469e72014-06-11 15:17:00 -07003316 * Returns the unread count of voicemails for a subId
3317 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003318 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003319 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3320 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003322 mApp, subId, callingPackage, callingFeatureId,
3323 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003324 return 0;
3325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
3329 if (phone != null) {
3330 return phone.getVoiceMessageCount();
3331 } else {
3332 return 0;
3333 }
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 }
3338
3339 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003340 * returns true, if the device is in a state where both voice and data
3341 * are supported simultaneously. This can change based on location or network condition.
3342 */
3343 @Override
3344 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 final Phone phone = getPhone(subId);
3348 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003352 }
3353
3354 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003355 * Send the dialer code if called from the current default dialer or the caller has
3356 * carrier privilege.
3357 * @param inputCode The dialer code to send
3358 */
3359 @Override
3360 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003363 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3364 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003365 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003366 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373 } finally {
3374 Binder.restoreCallingIdentity(identity);
3375 }
fionaxu235cc5e2017-03-06 22:25:57 -08003376 }
3377
Pengquan Menga1bb6272018-09-06 09:59:22 -07003378 @Override
3379 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003380 TelephonyPermissions
3381 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3382 mApp, subId, "getNetworkSelectionMode");
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 if (!isActiveSubscription(subId)) {
3386 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3387 }
3388 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003391 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003392 }
3393
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003395 public boolean isInEmergencySmsMode() {
3396 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 for (Phone phone : PhoneFactory.getPhones()) {
3400 if (phone.isInEmergencySmsMode()) {
3401 return true;
3402 }
3403 }
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
3407 return false;
3408 }
3409
shilu366312e2019-12-17 09:28:10 -08003410 /**
3411 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3412 * @param subId The subscription to use to check the configuration.
3413 * @param c The callback that will be used to send the result.
3414 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003415 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003416 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3417 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003418 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3419 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003420
Brad Ebinger77b832e2019-10-17 17:03:22 -07003421 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3422 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3423 "IMS not available on device.");
3424 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 final long token = Binder.clearCallingIdentity();
3426 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (ImsException e) {
3431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 } finally {
3433 Binder.restoreCallingIdentity(token);
3434 }
3435 }
3436
shilu366312e2019-12-17 09:28:10 -08003437 /**
3438 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3439 * @param subId The subscription to use to check the configuration.
3440 * @param c The callback that will be used to send the result.
3441 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003443 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003444 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3445 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3447 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3448 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003449 final long token = Binder.clearCallingIdentity();
3450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3452 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3453 .removeRegistrationCallbackForSubscription(c, subId);
3454 } catch (ImsException e) {
3455 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3456 + "is inactive, ignoring unregister.");
3457 // If the subscription is no longer active, just return, since the callback
3458 // will already have been removed internally.
3459 } finally {
3460 Binder.restoreCallingIdentity(token);
3461 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 }
3463
Brad Ebinger774ba362019-10-22 17:36:18 -07003464 /**
3465 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3466 */
3467 @Override
3468 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3469 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3470 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3472 "IMS not available on device.");
3473 }
3474 final long token = Binder.clearCallingIdentity();
3475 try {
3476 Phone phone = getPhone(subId);
3477 if (phone == null) {
3478 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3479 + subId + "'");
3480 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3481 }
3482 phone.getImsRegistrationState(regState -> {
3483 try {
3484 consumer.accept((regState == null)
3485 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3486 } catch (RemoteException e) {
3487 // Ignore if the remote process is no longer available to call back.
3488 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3489 }
3490 });
3491 } finally {
3492 Binder.restoreCallingIdentity(token);
3493 }
3494 }
3495
3496 /**
3497 * Get the transport type for the IMS service registration state.
3498 */
3499 @Override
3500 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003501 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3502 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003503 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3505 "IMS not available on device.");
3506 }
3507 final long token = Binder.clearCallingIdentity();
3508 try {
3509 Phone phone = getPhone(subId);
3510 if (phone == null) {
3511 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3512 + subId + "'");
3513 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3514 }
3515 phone.getImsRegistrationTech(regTech -> {
3516 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3517 int regTechConverted = (regTech == null)
3518 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3519 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3520 regTechConverted);
3521 try {
3522 consumer.accept(regTechConverted);
3523 } catch (RemoteException e) {
3524 // Ignore if the remote process is no longer available to call back.
3525 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3526 }
3527 });
3528 } finally {
3529 Binder.restoreCallingIdentity(token);
3530 }
3531 }
3532
shilu366312e2019-12-17 09:28:10 -08003533 /**
3534 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3535 * @param subId The subscription to use to check the configuration.
3536 * @param c The callback that will be used to send the result.
3537 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003539 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3540 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003541 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3542 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003543 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3544 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3545 "IMS not available on device.");
3546 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3548 final long token = Binder.clearCallingIdentity();
3549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(token);
3556 }
3557 }
3558
shilu366312e2019-12-17 09:28:10 -08003559 /**
3560 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3561 * @param subId The subscription to use to check the configuration.
3562 * @param c The callback that will be used to send the result.
3563 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003565 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003566 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3567 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003568 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3569 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3570 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003571
3572 final long token = Binder.clearCallingIdentity();
3573 try {
3574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3575 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003576 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003577 } catch (ImsException e) {
3578 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3579 + "is inactive, ignoring unregister.");
3580 // If the subscription is no longer active, just return, since the callback
3581 // will already have been removed internally.
3582 } finally {
3583 Binder.restoreCallingIdentity(token);
3584 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 }
3586
3587 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003588 public boolean isCapable(int subId, int capability, int regTech) {
3589 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3591 final long token = Binder.clearCallingIdentity();
3592 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003595 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3597 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003599 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3600 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 } finally {
3602 Binder.restoreCallingIdentity(token);
3603 }
3604 }
3605
3606 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003607 public boolean isAvailable(int subId, int capability, int regTech) {
3608 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 final long token = Binder.clearCallingIdentity();
3610 try {
3611 Phone phone = getPhone(subId);
3612 if (phone == null) return false;
3613 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003614 } catch (com.android.ims.ImsException e) {
3615 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3616 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 } finally {
3618 Binder.restoreCallingIdentity(token);
3619 }
3620 }
3621
Brad Ebinger77b832e2019-10-17 17:03:22 -07003622 /**
3623 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3624 * subscription.
3625 * @param subId The subscription to use to check the configuration.
3626 * @param callback The callback that will be used to send the result.
3627 * @param capability The MmTelFeature capability that will be used to send the result.
3628 * @param transportType The transport type of the MmTelFeature capability.
3629 */
3630 @Override
3631 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3632 int transportType) {
3633 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3634 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3635 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3636 "IMS not available on device.");
3637 }
3638 final long token = Binder.clearCallingIdentity();
3639 try {
3640 int slotId = getSlotIndex(subId);
3641 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3642 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3643 + subId + "'");
3644 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3645 }
3646 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3647 transportType, aBoolean -> {
3648 try {
3649 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3650 } catch (RemoteException e) {
3651 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3652 + "running. Ignore");
3653 }
3654 });
3655 } finally {
3656 Binder.restoreCallingIdentity(token);
3657 }
3658 }
3659
shilu366312e2019-12-17 09:28:10 -08003660 /**
3661 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3662 * @param subId The subscription to use to check the configuration.
3663 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 @Override
3665 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003666 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3667 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003668
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3670 final long token = Binder.clearCallingIdentity();
3671 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (ImsException e) {
3675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 } finally {
3677 Binder.restoreCallingIdentity(token);
3678 }
3679 }
3680
3681 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003682 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003684 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (ImsException e) {
3691 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
shilu366312e2019-12-17 09:28:10 -08003697 /**
3698 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3699 * @param subId The subscription to use to check the configuration.
3700 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003702 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003703 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3704 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3709 } catch (ImsException e) {
3710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003717 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003719 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
shilu366312e2019-12-17 09:28:10 -08003731 /**
3732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3733 * @param subId The subscription to use to check the configuration.
3734 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 @Override
3736 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
3745 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
3751 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003752 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003754 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (ImsException e) {
3760 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
3764 }
3765
shilu366312e2019-12-17 09:28:10 -08003766 /**
3767 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3768 * @param subId The subscription to use to check the configuration.
3769 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 @Override
3771 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003772 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3773 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003777 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003779 } catch (ImsException e) {
3780 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 } finally {
3782 Binder.restoreCallingIdentity(identity);
3783 }
3784 }
3785
3786 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003787 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003789 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
3796 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
3800 }
3801
3802 @Override
3803 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3805 "setVoWiFiNonPersistent");
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003810 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003811 } catch (ImsException e) {
3812 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
3816 }
3817
shilu366312e2019-12-17 09:28:10 -08003818 /**
3819 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3820 * @param subId The subscription to use to check the configuration.
3821 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 @Override
3823 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003824 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3825 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003831 } catch (ImsException e) {
3832 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
3836 }
3837
3838 @Override
3839 public void setVoWiFiModeSetting(int subId, int mode) {
3840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3841 "setVoWiFiModeSetting");
3842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003845 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003847 } catch (ImsException e) {
3848 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
3852 }
3853
3854 @Override
3855 public int getVoWiFiRoamingModeSetting(int subId) {
3856 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003860 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003862 } catch (ImsException e) {
3863 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
3869 @Override
3870 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3872 "setVoWiFiRoamingModeSetting");
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003876 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003878 } catch (ImsException e) {
3879 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
3883 }
3884
3885 @Override
3886 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3888 "setRttCapabilityEnabled");
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3893 } catch (ImsException e) {
3894 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
3898 }
3899
shilu366312e2019-12-17 09:28:10 -08003900 /**
3901 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3902 * @param subId The subscription to use to check the configuration.
3903 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 @Override
3905 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003906 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3907 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003913 } catch (ImsException e) {
3914 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
3918 }
3919
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003920 @Override
3921 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3922 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003925 if (!isImsAvailableOnDevice()) {
3926 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3927 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003928 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003931 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003932 } catch (ImsException e) {
3933 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003934 } finally {
3935 Binder.restoreCallingIdentity(identity);
3936 }
3937 }
3938
3939 @Override
3940 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3941 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3942 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3944 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3945 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003946 try {
3947 // 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 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003951 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3952 + "is inactive, ignoring unregister.");
3953 // If the subscription is no longer active, just return, since the callback will already
3954 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
allenwtsu99c623b2020-01-03 18:24:23 +08003960
3961 private void checkModifyPhoneStatePermission(int subId, String message) {
3962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3963 message);
3964 }
3965
3966 private boolean isImsProvisioningRequired(int subId, int capability,
3967 boolean isMmtelCapability) {
3968 Phone phone = getPhone(subId);
3969 if (phone == null) {
3970 loge("phone instance null for subid " + subId);
3971 return false;
3972 }
3973 if (isMmtelCapability) {
3974 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3975 return false;
3976 }
3977 } else {
3978 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3979 return false;
3980 }
3981 }
3982 return true;
3983 }
3984
3985 @Override
3986 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3987 boolean isProvisioned) {
3988 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3989
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3993 if (!isImsProvisioningRequired(subId, capability, false)) {
3994 return;
3995 }
3996
3997 // this capability requires provisioning, route to the correct API.
3998 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3999 switch (capability) {
4000 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4001 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4002 ims.setEabProvisioned(isProvisioned);
4003 break;
4004 default: {
4005 throw new IllegalArgumentException("Tried to set provisioning for "
4006 + "rcs capability '" + capability + "', which does not require "
4007 + "provisioning.");
4008 }
4009 }
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013
4014 }
4015
4016
4017 @Override
4018 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4019 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4023 if (!isImsProvisioningRequired(subId, capability, false)) {
4024 return true;
4025 }
4026
4027 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4028 switch (capability) {
4029 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4030 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4031 return ims.isEabProvisionedOnDevice();
4032
4033 default: {
4034 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4035 + "capability '" + capability + "', which does not require "
4036 + "provisioning.");
4037 }
4038 }
4039
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004045 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004046 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4047 boolean isProvisioned) {
4048 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4049 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4050 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4051 }
allenwtsu99c623b2020-01-03 18:24:23 +08004052 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004056 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004057 return;
4058 }
4059
4060 // this capability requires provisioning, route to the correct API.
4061 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4062 switch (capability) {
4063 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4064 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4065 ims.setVolteProvisioned(isProvisioned);
4066 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4067 ims.setWfcProvisioned(isProvisioned);
4068 }
4069 break;
4070 }
4071 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4072 // There is currently no difference in VT provisioning type.
4073 ims.setVtProvisioned(isProvisioned);
4074 break;
4075 }
4076 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4077 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4078 // change the capability of the feature instead if needed.
4079 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4080 == isProvisioned) {
4081 // No change in provisioning.
4082 return;
4083 }
4084 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4085 try {
4086 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004087 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004088 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4089 + ", Exception" + e.getMessage());
4090 }
4091 break;
4092 }
4093 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004094 throw new IllegalArgumentException("Tried to set provisioning for "
4095 + "MmTel capability '" + capability + "', which does not require "
4096 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004097 }
4098 }
4099
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
4103 }
4104
4105 @Override
4106 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4107 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4108 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4109 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4110 }
4111 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004115 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004116 return true;
4117 }
4118
4119 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4120 switch (capability) {
4121 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4122 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4123 return ims.isVolteProvisionedOnDevice();
4124 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4125 return ims.isWfcProvisionedOnDevice();
4126 }
4127 // This should never happen, since we are checking tech above to make sure it
4128 // is either LTE or IWLAN.
4129 throw new IllegalArgumentException("Invalid radio technology for voice "
4130 + "capability.");
4131 }
4132 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4133 // There is currently no difference in VT provisioning type.
4134 return ims.isVtProvisionedOnDevice();
4135 }
4136 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4137 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4138 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4139 }
4140 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004141 throw new IllegalArgumentException(
4142 "Tried to get provisioning for MmTel capability '" + capability
4143 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 }
4145 }
4146
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
4150 }
4151
4152 @Override
4153 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4154 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4155 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4156 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4157 }
4158 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4159 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4160 return (provisionedBits & capability) > 0;
4161 }
4162
4163 @Override
4164 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4165 boolean isProvisioned) {
4166 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4167 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4168 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4169 }
4170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4171 "setProvisioningStatusForCapability");
4172 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4173 // If the current provisioning status for capability already matches isProvisioned,
4174 // do nothing.
4175 if (((provisionedBits & capability) > 0) == isProvisioned) {
4176 return;
4177 }
4178 if (isProvisioned) {
4179 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4180 } else {
4181 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4182 }
4183 }
4184
4185 /**
4186 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4187 * technology. The bitfield should mirror the bitfield defined by
4188 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4189 */
4190 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4191 String key = getMmTelProvisioningKey(subId, tech);
4192 // Default is no capabilities are provisioned.
4193 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4194 }
4195
4196 /**
4197 * Sets the MmTel capability provisioning bitfield (defined by
4198 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4199 * technology specified.
4200 *
4201 * Note: This is a synchronous command and should not be called on UI thread.
4202 */
4203 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4204 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4205 String key = getMmTelProvisioningKey(subId, tech);
4206 editor.putInt(key, newField);
4207 editor.commit();
4208 }
4209
4210 private static String getMmTelProvisioningKey(int subId, int tech) {
4211 // resulting key is provision_ims_mmtel_{subId}_{tech}
4212 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4213 }
4214
4215 /**
4216 * Query CarrierConfig to see if the specified capability requires provisioning for the
4217 * carrier associated with the subscription id.
4218 */
4219 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4220 int capability) {
4221 CarrierConfigManager configManager = new CarrierConfigManager(context);
4222 PersistableBundle c = configManager.getConfigForSubId(subId);
4223 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004224 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004225 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4226 false);
4227 boolean requireVoiceVtProvisioning = c.getBoolean(
4228 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4229
4230 // First check to make sure that the capability requires provisioning.
4231 switch (capability) {
4232 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4233 // intentional fallthrough
4234 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4235 if (requireVoiceVtProvisioning) {
4236 // Voice and Video requires provisioning
4237 return true;
4238 }
4239 break;
4240 }
4241 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4242 if (requireUtProvisioning) {
4243 // UT requires provisioning
4244 return true;
4245 }
4246 break;
4247 }
4248 }
4249 return false;
4250 }
4251
allenwtsu99c623b2020-01-03 18:24:23 +08004252 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4253 int capability) {
4254 CarrierConfigManager configManager = new CarrierConfigManager(context);
4255 PersistableBundle c = configManager.getConfigForSubId(subId);
4256
4257 boolean requireRcsProvisioning = c.getBoolean(
4258 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4259
4260 // First check to make sure that the capability requires provisioning.
4261 switch (capability) {
4262 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4263 // intentional fallthrough
4264 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4265 if (requireRcsProvisioning) {
4266 // OPTION or PRESENCE requires provisioning
4267 return true;
4268 }
4269 break;
4270 }
4271 }
4272 return false;
4273 }
4274
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004275 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004276 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004277 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4278 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4279 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004280 enforceReadPrivilegedPermission("getImsProvisioningInt");
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004284 int slotId = getSlotIndex(subId);
4285 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4286 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4287 + subId + "' for key:" + key);
4288 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4289 }
4290 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004291 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004292 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4293 + subId + "' for key:" + key);
4294 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
4300 @Override
4301 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004302 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4303 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4304 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004305 enforceReadPrivilegedPermission("getImsProvisioningString");
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004309 int slotId = getSlotIndex(subId);
4310 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4311 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4312 + subId + "' for key:" + key);
4313 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4314 }
4315 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004317 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4318 + subId + "' for key:" + key);
4319 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 @Override
4326 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004327 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4328 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4329 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4331 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 int slotId = getSlotIndex(subId);
4336 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4337 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4338 + subId + "' for key:" + key);
4339 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4340 }
4341 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004342 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004343 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4344 + "' for key:" + key);
4345 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
4352 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4354 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4355 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4357 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 int slotId = getSlotIndex(subId);
4362 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4363 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4364 + subId + "' for key:" + key);
4365 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4366 }
4367 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004369 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4370 + "' for key:" + key);
4371 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
4375 }
4376
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 int slotId = SubscriptionManager.getSlotIndex(subId);
4379 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4381 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 }
4383 return slotId;
4384 }
4385
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004386 private int getSlotIndex(int subId) {
4387 int slotId = SubscriptionManager.getSlotIndex(subId);
4388 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4389 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4390 }
4391 return slotId;
4392 }
4393
Wink Saville36469e72014-06-11 15:17:00 -07004394 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004395 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004396 */
4397 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004398 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4399 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004400 final int targetSdk = getTargetSdk(callingPackage);
4401 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004402 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004403 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004404 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004405 mApp, subId, callingPackage, callingFeatureId,
4406 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004407 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4408 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 final Phone phone = getPhone(subId);
4413 if (phone != null) {
4414 return phone.getServiceState().getDataNetworkType();
4415 } else {
4416 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4417 }
4418 } finally {
4419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004421 }
4422
4423 /**
4424 * Returns the data network type
4425 */
4426 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004427 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4428 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4429 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004430 }
4431
4432 /**
4433 * Returns the data network type for a subId
4434 */
4435 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004436 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4437 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004439 mApp, subId, callingPackage, callingFeatureId,
4440 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004441 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4442 }
4443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 final Phone phone = getPhone(subId);
4447 if (phone != null) {
4448 return phone.getServiceState().getDataNetworkType();
4449 } else {
4450 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4451 }
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004455 }
4456
4457 /**
Wink Saville36469e72014-06-11 15:17:00 -07004458 * Returns the Voice network type for a subId
4459 */
4460 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004461 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4462 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004464 mApp, subId, callingPackage, callingFeatureId,
4465 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004466 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4467 }
4468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 final Phone phone = getPhone(subId);
4472 if (phone != null) {
4473 return phone.getServiceState().getVoiceNetworkType();
4474 } else {
4475 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4476 }
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004480 }
4481
4482 /**
4483 * @return true if a ICC card is present
4484 */
4485 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004486 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004487 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4488 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004489 }
4490
4491 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004492 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004493 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004494 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004495 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 final Phone phone = PhoneFactory.getPhone(slotIndex);
4499 if (phone != null) {
4500 return phone.getIccCard().hasIccCard();
4501 } else {
4502 return false;
4503 }
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004507 }
4508
4509 /**
4510 * Return if the current radio is LTE on CDMA. This
4511 * is a tri-state return value as for a period of time
4512 * the mode may be unknown.
4513 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004514 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004515 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004516 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004517 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004519 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4520 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4521 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004522 }
4523
Sanket Padawe356d7632015-06-22 14:03:32 -07004524 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004525 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4526 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004527 try {
4528 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4529 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004530 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4531 }
4532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 final Phone phone = getPhone(subId);
4536 if (phone == null) {
4537 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4538 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004539 return TelephonyProperties.lte_on_cdma_device()
4540 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004544 }
Wink Saville36469e72014-06-11 15:17:00 -07004545 }
4546
Wink Saville36469e72014-06-11 15:17:00 -07004547 /**
4548 * {@hide}
4549 * Returns Default subId, 0 in the case of single standby.
4550 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004551 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004552 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004553 }
4554
Shishir Agrawala9f32182016-04-12 12:00:16 -07004555 private int getSlotForDefaultSubscription() {
4556 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4557 }
4558
Wink Savilleb564aae2014-10-23 10:18:09 -07004559 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004560 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004561 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004562
Pengquan Menge92a50d2018-09-21 15:54:48 -07004563 private boolean isActiveSubscription(int subId) {
4564 return mSubscriptionController.isActiveSubId(subId);
4565 }
4566
Ihab Awadf2177b72013-11-25 13:33:23 -08004567 /**
4568 * @see android.telephony.TelephonyManager.WifiCallingChoices
4569 */
4570 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004573 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4575 getWhenToMakeWifiCallsDefaultPreference());
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004579 }
4580
4581 /**
4582 * @see android.telephony.TelephonyManager.WifiCallingChoices
4583 */
4584 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004588 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004593 }
4594
Sailesh Nepald1e68152013-12-12 19:08:02 -08004595 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004596 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004597 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004598 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004599
Jordan Liu4c733742019-02-28 12:03:40 -08004600 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4601 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4602 if (phoneId == -1) {
4603 throw new IllegalArgumentException("Given slot index: " + slotIndex
4604 + " does not correspond to an active phone");
4605 }
4606 return PhoneFactory.getPhone(phoneId);
4607 }
4608
Shishir Agrawal566b7612013-10-28 14:41:00 -07004609 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004610 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4611 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4613 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004615 if (DBG) {
4616 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4617 }
4618 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4619 p2);
4620 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004621
Jordan Liu4c733742019-02-28 12:03:40 -08004622
4623 @Override
4624 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4625 int slotIndex, String callingPackage, String aid, int p2) {
4626 enforceModifyPermission();
4627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4628 if (DBG) {
4629 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4630 }
4631 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4632 callingPackage, aid, p2);
4633 }
4634
4635 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4636 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (TextUtils.equals(ISDR_AID, aid)) {
4640 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004641 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4642 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 if (bestComponent == null
4644 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4645 loge("The calling package is not allowed to access ISD-R.");
4646 throw new SecurityException(
4647 "The calling package is not allowed to access ISD-R.");
4648 }
Derek Tan740e1672017-06-27 14:56:27 -07004649 }
Derek Tan740e1672017-06-27 14:56:27 -07004650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004652 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4653 null /* workSource */);
4654 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 return response;
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004659 }
4660
4661 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004662 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4664 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004665 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4666 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4667 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004668
Jordan Liu4c733742019-02-28 12:03:40 -08004669 @Override
4670 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4671 enforceModifyPermission();
4672 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4673 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4674 channel);
4675 }
4676
4677 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 final long identity = Binder.clearCallingIdentity();
4679 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 if (channel < 0) {
4681 return false;
4682 }
Jordan Liu4c733742019-02-28 12:03:40 -08004683 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4684 null /* workSource */);
4685 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686 return success;
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004690 }
4691
4692 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004693 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004694 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4696 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004697 if (DBG) {
4698 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4699 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4700 + p3 + " data=" + data);
4701 }
4702 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4703 command, p1, p2, p3, data);
4704 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004705
Jordan Liu4c733742019-02-28 12:03:40 -08004706 @Override
4707 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4708 int command, int p1, int p2, int p3, String data) {
4709 enforceModifyPermission();
4710 if (DBG) {
4711 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4712 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4713 + p3 + " data=" + data);
4714 }
4715 return iccTransmitApduLogicalChannelWithPermission(
4716 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4717 data);
4718 }
4719
4720 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4721 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004724 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 return "";
4726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004729 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4730 null /* workSource */);
4731 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 // Append the returned status code to the end of the response payload.
4734 String s = Integer.toHexString(
4735 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4736 if (response.payload != null) {
4737 s = IccUtils.bytesToHexString(response.payload) + s;
4738 }
4739 return s;
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004742 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004743 }
Jake Hambye994d462014-02-03 13:10:13 -08004744
Evan Charltonc66da362014-05-16 14:06:40 -07004745 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004746 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4747 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4749 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004751 if (DBG) {
4752 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4753 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4754 }
4755 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4756 cla, command, p1, p2, p3, data);
4757 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004758
Jordan Liu4c733742019-02-28 12:03:40 -08004759 @Override
4760 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4761 int command, int p1, int p2, int p3, String data) {
4762 enforceModifyPermission();
4763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4764 if (DBG) {
4765 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4766 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4767 + " data=" + data);
4768 }
4769
4770 return iccTransmitApduBasicChannelWithPermission(
4771 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4772 p2, p3, data);
4773 }
4774
4775 // open APDU basic channel assuming the caller has sufficient permissions
4776 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4777 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4781 && TextUtils.equals(ISDR_AID, data)) {
4782 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004783 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4784 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 if (bestComponent == null
4786 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4787 loge("The calling package is not allowed to select ISD-R.");
4788 throw new SecurityException(
4789 "The calling package is not allowed to select ISD-R.");
4790 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004791 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004794 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4795 null /* workSource */);
4796 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 // Append the returned status code to the end of the response payload.
4799 String s = Integer.toHexString(
4800 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4801 if (response.payload != null) {
4802 s = IccUtils.bytesToHexString(response.payload) + s;
4803 }
4804 return s;
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004807 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004808 }
4809
4810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004811 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004812 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4814 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 if (DBG) {
4819 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4820 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4821 }
4822
4823 IccIoResult response =
4824 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4825 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4826 subId);
4827
4828 if (DBG) {
4829 log("Exchange SIM_IO [R]" + response);
4830 }
4831
4832 byte[] result = null;
4833 int length = 2;
4834 if (response.payload != null) {
4835 length = 2 + response.payload.length;
4836 result = new byte[length];
4837 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4838 } else {
4839 result = new byte[length];
4840 }
4841
4842 result[length - 1] = (byte) response.sw2;
4843 result[length - 2] = (byte) response.sw1;
4844 return result;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004847 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004848 }
4849
Nathan Haroldb3014052017-01-25 15:57:32 -08004850 /**
4851 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4852 * on a particular subscription
4853 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004854 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4855 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004857 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004858 return null;
4859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 if (appType != TelephonyManager.APPTYPE_USIM
4864 && appType != TelephonyManager.APPTYPE_SIM) {
4865 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4866 return null;
4867 }
4868 Object response = sendRequest(
4869 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4870 if (response instanceof String[]) {
4871 return (String[]) response;
4872 }
yincheng zhaod698b842019-09-06 17:06:54 -07004873 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004875 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004878 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004879 }
4880
yincheng zhaod698b842019-09-06 17:06:54 -07004881 /**
4882 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4883 * subscription.
4884 *
4885 * @param subId the id of the subscription.
4886 * @param appType the uicc app type, must be USIM or SIM.
4887 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4888 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004889 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004890 * @return number of fplmns that is successfully written to the SIM.
4891 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004892 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4893 String callingFeatureId) {
4894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4895 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004896 if (DBG) logv("no permissions for setForbiddenplmns");
4897 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4898 }
4899 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4900 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4901 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4902 }
4903 if (fplmns == null) {
4904 throw new IllegalArgumentException("Fplmn List provided is null");
4905 }
4906 for (String fplmn : fplmns) {
4907 if (!CellIdentity.isValidPlmn(fplmn)) {
4908 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4909 }
4910 }
4911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 Object response = sendRequest(
4914 CMD_SET_FORBIDDEN_PLMNS,
4915 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4916 subId);
4917 return (int) response;
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004924 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4926 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4931 if (response.payload == null) {
4932 return "";
4933 }
Evan Charltonc66da362014-05-16 14:06:40 -07004934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 // Append the returned status code to the end of the response payload.
4936 String s = Integer.toHexString(
4937 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4938 s = IccUtils.bytesToHexString(response.payload) + s;
4939 return s;
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Evan Charltonc66da362014-05-16 14:06:40 -07004943 }
4944
Jake Hambye994d462014-02-03 13:10:13 -08004945 /**
4946 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4947 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4948 *
4949 * @param itemID the ID of the item to read
4950 * @return the NV item as a String, or null on error.
4951 */
4952 @Override
4953 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004954 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4956 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957
4958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004961 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4963 return value;
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Jake Hambye994d462014-02-03 13:10:13 -08004967 }
4968
4969 /**
4970 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4971 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4972 *
4973 * @param itemID the ID of the item to read
4974 * @param itemValue the value to write, as a String
4975 * @return true on success; false on any failure
4976 */
4977 @Override
4978 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4986 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004987 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4989 return success;
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Jake Hambye994d462014-02-03 13:10:13 -08004993 }
4994
4995 /**
4996 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4997 * Used for device configuration by some CDMA operators.
4998 *
4999 * @param preferredRoamingList byte array containing the new PRL
5000 * @return true on success; false on any failure
5001 */
5002 @Override
5003 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5005 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5010 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5011 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5012 return success;
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Jake Hambye994d462014-02-03 13:10:13 -08005016 }
5017
5018 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005019 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005020 * Used for device configuration by some CDMA operators.
5021 *
chen xu6dac5ab2018-10-26 17:39:23 -07005022 * @param slotIndex - device slot.
5023 *
Jake Hambye994d462014-02-03 13:10:13 -08005024 * @return true on success; false on any failure
5025 */
5026 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005027 public boolean resetModemConfig(int slotIndex) {
5028 Phone phone = PhoneFactory.getPhone(slotIndex);
5029 if (phone != null) {
5030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5031 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032
chen xu6dac5ab2018-10-26 17:39:23 -07005033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5036 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5037 return success;
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 }
chen xu6dac5ab2018-10-26 17:39:23 -07005042 return false;
5043 }
5044
5045 /**
5046 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5047 *
5048 * @param slotIndex - device slot.
5049 *
5050 * @return true on success; false on any failure
5051 */
5052 @Override
5053 public boolean rebootModem(int slotIndex) {
5054 Phone phone = PhoneFactory.getPhone(slotIndex);
5055 if (phone != null) {
5056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5057 mApp, phone.getSubId(), "rebootModem");
5058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5062 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5063 return success;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005069 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005070
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005071 public String[] getPcscfAddress(String apnType, String callingPackage,
5072 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005073 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5075 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005076 return new String[0];
5077 }
5078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005081 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
Wink Saville36469e72014-06-11 15:17:00 -07005085 }
5086
Brad Ebinger51f743a2017-01-23 13:50:20 -08005087 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005088 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5089 * {@link #disableIms(int)}.
5090 * @param slotIndex device slot.
5091 */
5092 public void resetIms(int slotIndex) {
5093 enforceModifyPermission();
5094
5095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 if (mImsResolver == null) {
5098 // may happen if the does not support IMS.
5099 return;
5100 }
5101 mImsResolver.disableIms(slotIndex);
5102 mImsResolver.enableIms(slotIndex);
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
5106 }
5107
5108 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005109 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5110 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005111 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005112 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005117 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005118 // may happen if the device does not support IMS.
5119 return;
5120 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005121 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005125 }
5126
5127 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005128 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5129 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005130 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005131 public void disableIms(int slotId) {
5132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133
5134 final long identity = Binder.clearCallingIdentity();
5135 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005136 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005137 // may happen if the device does not support IMS.
5138 return;
5139 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005140 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005144 }
5145
5146 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005147 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5148 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005149 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005150 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005151 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005156 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5158 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005159 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005160 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005164 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005165 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005166 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5167 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005168 @Override
5169 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005170 enforceModifyPermission();
5171
5172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005175 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005182 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005183 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005184 */
5185 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005190 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005191 // may happen if the device does not support IMS.
5192 return null;
5193 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005194 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005198 }
5199
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005200 /**
5201 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005202 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005203 */
5204 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005209 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005210 // may happen if the device does not support IMS.
5211 return null;
5212 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005213 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005217 }
5218
Brad Ebinger884c07b2018-02-15 16:17:40 -08005219 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005220 * Sets the ImsService Package Name that Telephony will bind to.
5221 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005222 * @param slotIndex the slot ID that the ImsService should bind for.
5223 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005224 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005225 * @param featureTypes An integer array of feature types associated with a packageName.
5226 * @param packageName The name of the package that the current configuration will be replaced
5227 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005228 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005229 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005230 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5231 int[] featureTypes, String packageName) {
5232 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5235 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005236 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005240 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005241 // may happen if the device does not support IMS.
5242 return false;
5243 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005244 Map<Integer, String> featureConfig = new HashMap<>();
5245 for (int featureType : featureTypes) {
5246 featureConfig.put(featureType, packageName);
5247 }
5248 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5249 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005253 }
5254
5255 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005256 * Clears any carrier ImsService overrides for the slot index specified that were previously
5257 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5258 *
5259 * This should only be used for testing.
5260 *
5261 * @param slotIndex the slot ID that the ImsService should bind for.
5262 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5263 */
5264 @Override
5265 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5266 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5268 "clearCarrierImsServiceOverride");
5269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5270 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5271 "clearCarrierImsServiceOverride");
5272
5273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (mImsResolver == null) {
5276 // may happen if the device does not support IMS.
5277 return false;
5278 }
5279 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
5285 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005286 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005287 *
5288 * @param slotId The slot that the ImsService is associated with.
5289 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5290 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005291 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005292 * @return the package name of the ImsService configuration.
5293 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005294 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5295 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005296 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005297 TelephonyPermissions
5298 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5299 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5300 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005304 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005305 // may happen if the device does not support IMS.
5306 return "";
5307 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005308 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005309 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5310 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005314 }
5315
Brad Ebinger77b832e2019-10-17 17:03:22 -07005316 /**
5317 * Get the MmTelFeature state associated with the requested subscription id.
5318 * @param subId The subscription that the MmTelFeature is associated with.
5319 * @param callback A callback with an integer containing the
5320 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5321 */
5322 @Override
5323 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5324 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5325 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5326 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5327 "IMS not available on device.");
5328 }
5329 final long token = Binder.clearCallingIdentity();
5330 try {
5331 int slotId = getSlotIndex(subId);
5332 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5333 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5334 + subId + "'");
5335 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5336 }
5337 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5338 try {
5339 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5340 } catch (RemoteException e) {
5341 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5342 + "Ignore");
5343 }
5344 });
5345 } finally {
5346 Binder.restoreCallingIdentity(token);
5347 }
5348 }
5349
Wink Saville36469e72014-06-11 15:17:00 -07005350 public void setImsRegistrationState(boolean registered) {
5351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005355 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Wink Saville36469e72014-06-11 15:17:00 -07005359 }
5360
5361 /**
Stuart Scott54788802015-03-30 13:18:01 -07005362 * Set the network selection mode to automatic.
5363 *
5364 */
5365 @Override
5366 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5368 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369
5370 final long identity = Binder.clearCallingIdentity();
5371 try {
shilufc958392020-01-20 11:36:01 -08005372 if (!isActiveSubscription(subId)) {
5373 return;
5374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5376 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
Stuart Scott54788802015-03-30 13:18:01 -07005380 }
5381
Jack Yud10cdd42020-09-28 20:28:01 -07005382 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005383 * Ask the radio to connect to the input network and change selection mode to manual.
5384 *
5385 * @param subId the id of the subscription.
5386 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5387 * the operator to attach to.
5388 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5389 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5390 * normal network selection next time.
5391 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005392 */
5393 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005394 public boolean setNetworkSelectionModeManual(
5395 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005398
5399 if (!isActiveSubscription(subId)) {
5400 return false;
5401 }
5402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005405 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005407 if (DBG) {
5408 log("setNetworkSelectionModeManual: subId: " + subId
5409 + " operator: " + operatorInfo);
5410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005415 }
shilu84f6e8b2019-12-19 13:58:01 -08005416 /**
5417 * Get the manual network selection
5418 *
5419 * @param subId the id of the subscription.
5420 *
5421 * @return the previously saved user selected PLMN
5422 */
5423 @Override
5424 public String getManualNetworkSelectionPlmn(int subId) {
5425 TelephonyPermissions
5426 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5427 mApp, subId, "getManualNetworkSelectionPlmn");
5428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 if (!isActiveSubscription(subId)) {
5432 return "";
5433 }
5434
5435 final Phone phone = getPhone(subId);
5436 if (phone == null) {
5437 return "";
5438 }
5439 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5440 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5441 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
5445 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005446
5447 /**
5448 * Scans for available networks.
5449 */
5450 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005451 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5452 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005455 LocationAccessPolicy.LocationPermissionResult locationResult =
5456 LocationAccessPolicy.checkLocationPermission(mApp,
5457 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5458 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005459 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005460 .setCallingPid(Binder.getCallingPid())
5461 .setCallingUid(Binder.getCallingUid())
5462 .setMethod("getCellNetworkScanResults")
5463 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5464 .build());
5465 switch (locationResult) {
5466 case DENIED_HARD:
5467 throw new SecurityException("Not allowed to access scan results -- location");
5468 case DENIED_SOFT:
5469 return null;
5470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471
Pengquan Menga1bb6272018-09-06 09:59:22 -07005472 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 try {
5474 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005475 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005480 }
5481
5482 /**
sqian80370722020-01-29 15:02:51 -08005483 * Get the call forwarding info, given the call forwarding reason.
5484 */
5485 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005486 public void getCallForwarding(int subId, int callForwardingReason,
5487 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005488 enforceReadPrivilegedPermission("getCallForwarding");
5489 long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (DBG) {
5492 log("getCallForwarding: subId " + subId
5493 + " callForwardingReason" + callForwardingReason);
5494 }
Hall Liua1acea22020-09-18 19:04:59 -07005495
5496 Phone phone = getPhone(subId);
5497 if (phone == null) {
5498 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005499 callback.onError(
5500 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005501 } catch (RemoteException e) {
5502 // ignore
5503 }
5504 return;
5505 }
5506
5507 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5508 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5509 @Override
5510 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5511 try {
5512 callback.onCallForwardingInfoAvailable(info);
5513 } catch (RemoteException e) {
5514 // ignore
5515 }
5516 }
5517
5518 @Override
5519 public void onError(int error) {
5520 try {
5521 callback.onError(error);
5522 } catch (RemoteException e) {
5523 // ignore
5524 }
5525 }
5526 });
5527 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
5531 }
5532
5533 /**
5534 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5535 * reason, the number to forward, and the timeout before the forwarding is attempted.
5536 */
5537 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005538 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5539 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005540 enforceModifyPermission();
5541 long identity = Binder.clearCallingIdentity();
5542 try {
5543 if (DBG) {
5544 log("setCallForwarding: subId " + subId
5545 + " callForwardingInfo" + callForwardingInfo);
5546 }
Hall Liua1acea22020-09-18 19:04:59 -07005547
5548 Phone phone = getPhone(subId);
5549 if (phone == null) {
5550 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005551 callback.accept(
5552 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005553 } catch (RemoteException e) {
5554 // ignore
5555 }
5556 return;
5557 }
5558
5559 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5560 FunctionalUtils.ignoreRemoteException(callback::accept));
5561
5562 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
5566 }
5567
5568 /**
Hall Liua1acea22020-09-18 19:04:59 -07005569 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005570 */
5571 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005572 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005573 enforceReadPrivilegedPermission("getCallForwarding");
5574 long identity = Binder.clearCallingIdentity();
5575 try {
Hall Liua1acea22020-09-18 19:04:59 -07005576
5577 Phone phone = getPhone(subId);
5578 if (phone == null) {
5579 try {
5580 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5581 } catch (RemoteException e) {
5582 // ignore
5583 }
5584 return;
5585 }
5586
5587 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5588
sqian80370722020-01-29 15:02:51 -08005589 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005590 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
5594 }
5595
5596 /**
Hall Liua1acea22020-09-18 19:04:59 -07005597 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005598 */
5599 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005600 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005601 enforceModifyPermission();
5602 long identity = Binder.clearCallingIdentity();
5603 try {
Hall Liua1acea22020-09-18 19:04:59 -07005604 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5605
5606 Phone phone = getPhone(subId);
5607 if (phone == null) {
5608 try {
5609 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5610 } catch (RemoteException e) {
5611 // ignore
5612 }
5613 return;
5614 }
5615
5616 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5617 FunctionalUtils.ignoreRemoteException(callback::accept));
5618
5619 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
5623 }
5624
5625 /**
yinxub1bed742017-04-17 11:45:04 -07005626 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005627 *
yinxub1bed742017-04-17 11:45:04 -07005628 * @param subId id of the subscription
5629 * @param request contains the radio access networks with bands/channels to scan
5630 * @param messenger callback messenger for scan results or errors
5631 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005632 * @return the id of the requested scan which can be used to stop the scan.
5633 */
5634 @Override
5635 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005636 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5638 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005639 LocationAccessPolicy.LocationPermissionResult locationResult =
5640 LocationAccessPolicy.checkLocationPermission(mApp,
5641 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5642 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005643 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005644 .setCallingPid(Binder.getCallingPid())
5645 .setCallingUid(Binder.getCallingUid())
5646 .setMethod("requestNetworkScan")
5647 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5648 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005649 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005650 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5651 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005652 if (e != null) {
5653 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5654 throw e;
5655 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005656 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005657 return TelephonyScanManager.INVALID_SCAN_ID;
5658 }
5659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 }
Hall Liu912dfd32019-04-25 14:02:26 -07005661 int callingUid = Binder.getCallingUid();
5662 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 return mNetworkScanRequestTracker.startNetworkScan(
5666 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005667 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
yinxu504e1392017-04-12 16:03:22 -07005671 }
5672
Hall Liub2ac8ef2019-02-28 15:56:23 -08005673 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005674 NetworkScanRequest request, int subId, String callingPackage) {
5675 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005676 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5677 boolean hasNetworkScanPermission =
5678 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5679 == PERMISSION_GRANTED;
5680
5681 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5682 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5683 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005684 }
5685
5686 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5687 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005688 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5689 return new SecurityException("Specific channels must not be"
5690 + " scanned without location access.");
5691 }
5692 }
5693 }
5694
Hall Liub2ac8ef2019-02-28 15:56:23 -08005695 return null;
5696 }
5697
yinxu504e1392017-04-12 16:03:22 -07005698 /**
5699 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005700 *
5701 * @param subId id of the subscription
5702 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005703 */
5704 @Override
5705 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5707 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
Hall Liu912dfd32019-04-25 14:02:26 -07005709 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005712 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
yinxu504e1392017-04-12 16:03:22 -07005716 }
5717
5718 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005719 * Get the calculated preferred network type.
5720 * Used for debugging incorrect network type.
5721 *
5722 * @return the preferred network type, defined in RILConstants.java.
5723 */
5724 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005725 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005726 final Phone defaultPhone = getDefaultPhone();
5727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005728 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005729 return RILConstants.PREFERRED_NETWORK_MODE;
5730 }
5731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Junda Liu84d15a22014-07-02 11:21:04 -07005739 }
5740
5741 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005742 * Get the preferred network type.
5743 * Used for device configuration by some CDMA operators.
5744 *
5745 * @return the preferred network type, defined in RILConstants.java.
5746 */
5747 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005748 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005749 TelephonyPermissions
5750 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5751 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 if (DBG) log("getPreferredNetworkType");
5756 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5757 int networkType = (result != null ? result[0] : -1);
5758 if (DBG) log("getPreferredNetworkType: " + networkType);
5759 return networkType;
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005763 }
5764
5765 /**
5766 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005767 *
5768 * @param networkType the preferred network type, defined in RILConstants.java.
5769 * @return true on success; false on any failure.
5770 */
5771 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005772 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5774 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005778 Settings.Global.putInt(mApp.getContentResolver(),
5779 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005780
5781 Boolean success = (Boolean) sendRequest(
5782 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5783 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5784 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005787 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005788 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005789
5790 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005791 * Get the allowed network types that store in the telephony provider.
5792 *
5793 * @param subId the id of the subscription.
5794 * @return allowedNetworkTypes the allowed network types.
5795 */
5796 @Override
5797 public long getAllowedNetworkTypes(int subId) {
5798 TelephonyPermissions
5799 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5800 mApp, subId, "getAllowedNetworkTypes");
5801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 return SubscriptionManager.getLongSubscriptionProperty(
5805 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
5810
5811 /**
5812 * Set the allowed network types.
5813 *
5814 * @param subId the id of the subscription.
5815 * @param allowedNetworkTypes the allowed network types.
5816 * @return true on success; false on any failure.
5817 */
5818 @Override
5819 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5821 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005822
calvinpan089c2a62020-03-12 14:17:55 +08005823 SubscriptionManager.setSubscriptionProperty(subId,
5824 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5825 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005826
calvinpan089c2a62020-03-12 14:17:55 +08005827 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5828 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5829 RILConstants.PREFERRED_NETWORK_MODE);
5830 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005831 }
5832
5833 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005834 * Get the allowed network types for certain reason.
5835 *
5836 * @param subId the id of the subscription.
5837 * @param reason the reason the allowed network type change is taking place
5838 * @return the allowed network types.
5839 */
5840 @Override
5841 public long getAllowedNetworkTypesForReason(int subId,
5842 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5843 TelephonyPermissions
5844 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5845 mApp, subId, "getAllowedNetworkTypesForReason");
5846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005855 * Enable/Disable E-UTRA-NR Dual Connectivity
5856 * @param subId subscription id of the sim card
5857 * @param nrDualConnectivityState expected NR dual connectivity state
5858 * This can be passed following states
5859 * <ol>
5860 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5861 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5862 * <li>Disable NR dual connectivity and force secondary cell to be released
5863 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5864 * </ol>
5865 * @return operation result.
5866 */
5867 @Override
5868 public int setNrDualConnectivityState(int subId,
5869 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, subId, "enableNRDualConnectivity");
5872 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5876 nrDualConnectivityState, subId,
5877 workSource);
5878 if (DBG) log("enableNRDualConnectivity result: " + result);
5879 return result;
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
5883 }
5884
5885 /**
5886 * Is E-UTRA-NR Dual Connectivity enabled
5887 * @return true if dual connectivity is enabled else false
5888 */
5889 @Override
5890 public boolean isNrDualConnectivityEnabled(int subId) {
5891 TelephonyPermissions
5892 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5893 mApp, subId, "isNRDualConnectivityEnabled");
5894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
5897 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5898 null, subId, workSource);
5899 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5900 return isEnabled;
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
5904 }
5905
5906 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07005907 * get carrier bandwidth per primary and secondary carrier
5908 * @param subId subscription id of the sim card
5909 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5910 */
5911 @Override
5912 public CarrierBandwidth getCarrierBandwidth(int subId) {
5913 TelephonyPermissions
5914 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5915 mApp, subId, "isNRDualConnectivityEnabled");
5916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 CarrierBandwidth carrierBandwidth =
5920 getPhoneFromSubId(subId).getCarrierBandwidth();
5921 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5922 return carrierBandwidth;
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
5926 }
5927
5928 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005929 * Get the effective allowed network types on the device.
5930 * This API will return an intersection of allowed network types for all reasons,
5931 * including the configuration done through setAllowedNetworkTypes
5932 *
5933 * @param subId the id of the subscription.
5934 * @return the allowed network types
5935 */
5936 @Override
5937 public long getEffectiveAllowedNetworkTypes(int subId) {
5938 TelephonyPermissions
5939 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5940 mApp, subId, "getEffectiveAllowedNetworkTypes");
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
5947 }
5948
5949 /**
5950 * Set the allowed network types of the device and
5951 * provide the reason triggering the allowed network change.
5952 *
5953 * @param subId the id of the subscription.
5954 * @param reason the reason the allowed network type change is taking place
5955 * @param allowedNetworkTypes the allowed network types.
5956 * @return true on success; false on any failure.
5957 */
5958 @Override
5959 public boolean setAllowedNetworkTypesForReason(int subId,
5960 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5962 mApp, subId, "setAllowedNetworkTypesForReason");
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5966 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5967 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5968 RILConstants.PREFERRED_NETWORK_MODE);
5969 return setPreferredNetworkType(subId, preferredNetworkMode);
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
5973 }
5974
5975 /**
Miaoa84611c2019-03-15 09:21:10 +08005976 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005977 *
Miaoa84611c2019-03-15 09:21:10 +08005978 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005979 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005980 * @hide
5981 */
5982 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005983 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005986 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 try {
Miaoa84611c2019-03-15 09:21:10 +08005988 if (phone != null) {
5989 return phone.hasMatchedTetherApnSetting();
5990 } else {
5991 return false;
5992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005995 }
Junda Liu475951f2014-11-07 16:45:03 -08005996 }
5997
5998 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005999 * Enable or disable always reporting signal strength changes from radio.
6000 *
6001 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6002 */
6003 @Override
6004 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6005 enforceModifyPermission();
6006 enforceSystemCaller();
6007
6008 final long identity = Binder.clearCallingIdentity();
6009 final Phone phone = getPhone(subId);
6010 try {
6011 if (phone != null) {
6012 if (DBG) {
6013 log("setAlwaysReportSignalStrength: subId=" + subId
6014 + " isEnable=" + isEnable);
6015 }
6016 phone.setAlwaysReportSignalStrength(isEnable);
6017 } else {
6018 loge("setAlwaysReportSignalStrength: no phone found for subId="
6019 + subId);
6020 }
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 }
6025
6026 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006027 * Get the user enabled state of Mobile Data.
6028 *
6029 * TODO: remove and use isUserDataEnabled.
6030 * This can't be removed now because some vendor codes
6031 * calls through ITelephony directly while they should
6032 * use TelephonyManager.
6033 *
6034 * @return true on enabled
6035 */
6036 @Override
6037 public boolean getDataEnabled(int subId) {
6038 return isUserDataEnabled(subId);
6039 }
6040
6041 /**
6042 * Get whether mobile data is enabled per user setting.
6043 *
6044 * There are other factors deciding whether mobile data is actually enabled, but they are
6045 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006046 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006047 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006048 *
6049 * @return {@code true} if data is enabled else {@code false}
6050 */
6051 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006052 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006053 try {
6054 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6055 null);
6056 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6058 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 int phoneId = mSubscriptionController.getPhoneId(subId);
6064 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6065 Phone phone = PhoneFactory.getPhone(phoneId);
6066 if (phone != null) {
6067 boolean retVal = phone.isUserDataEnabled();
6068 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6069 return retVal;
6070 } else {
6071 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6072 return false;
6073 }
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006076 }
6077 }
6078
6079 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006080 * Checks if the device is capable of mobile data by considering whether whether the
6081 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6082 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006083 *
Shuo Qian985d1232020-01-08 14:30:06 -08006084 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006085 */
6086 @Override
6087 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006088 try {
6089 try {
6090 mApp.enforceCallingOrSelfPermission(
6091 android.Manifest.permission.ACCESS_NETWORK_STATE,
6092 null);
6093 } catch (Exception e) {
6094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6095 "isDataEnabled");
6096 }
6097 } catch (Exception e) {
6098 enforceReadPrivilegedPermission("isDataEnabled");
6099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 int phoneId = mSubscriptionController.getPhoneId(subId);
6104 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6105 Phone phone = PhoneFactory.getPhone(phoneId);
6106 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006107 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6109 return retVal;
6110 } else {
6111 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6112 return false;
6113 }
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006116 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006117 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006118
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006119 /**
6120 * Check if data is enabled for a specific reason
6121 * @param subId Subscription index
6122 * @param reason the reason the data enable change is taking place
6123 * @return {@code true} if the overall data is enabled; {@code false} if not.
6124 */
6125 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006126 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006127 @TelephonyManager.DataEnabledReason int reason) {
6128 try {
6129 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6130 null);
6131 } catch (Exception e) {
6132 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006133 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006134 }
6135
6136
6137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 int phoneId = mSubscriptionController.getPhoneId(subId);
6140 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006141 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006142 + " reason=" + reason);
6143 }
6144 Phone phone = PhoneFactory.getPhone(phoneId);
6145 if (phone != null) {
6146 boolean retVal;
6147 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6148 retVal = phone.isUserDataEnabled();
6149 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006150 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006151 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006152 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006153 return retVal;
6154 } else {
6155 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006156 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006157 + subId + " retVal=false");
6158 }
6159 return false;
6160 }
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
6164 }
6165
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006166 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006167 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006168 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6169 // Skip the check if it's one of these special uids
6170 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6171 }
6172
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006173 //load access rules from carrier configs, and check those as well: b/139133814
6174 SubscriptionController subController = SubscriptionController.getInstance();
6175 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6176 || subController == null) return privilegeFromSim;
6177
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006178 PackageManager pkgMgr = phone.getContext().getPackageManager();
6179 String[] packages = pkgMgr.getPackagesForUid(uid);
6180
6181 final long identity = Binder.clearCallingIdentity();
6182 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006183 int subId = phone.getSubId();
6184 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6185 // A test override is in place for the privileges for this subId, so don't try to
6186 // read the subscription privileges.
6187 return privilegeFromSim;
6188 }
6189 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006190 SubscriptionManager subManager = (SubscriptionManager)
6191 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6192 for (String pkg : packages) {
6193 if (subManager.canManageSubscription(subInfo, pkg)) {
6194 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6195 }
6196 }
6197 return privilegeFromSim;
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6204 String pkgName) {
6205 //load access rules from carrier configs, and check those as well: b/139133814
6206 SubscriptionController subController = SubscriptionController.getInstance();
6207 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6208 || subController == null) return privilegeFromSim;
6209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006212 int subId = phone.getSubId();
6213 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6214 // A test override is in place for the privileges for this subId, so don't try to
6215 // read the subscription privileges.
6216 return privilegeFromSim;
6217 }
6218 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006219 SubscriptionManager subManager = (SubscriptionManager)
6220 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6221 return subManager.canManageSubscription(subInfo, pkgName)
6222 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006228 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006229 public int getCarrierPrivilegeStatus(int subId) {
6230 final Phone phone = getPhone(subId);
6231 if (phone == null) {
6232 loge("getCarrierPrivilegeStatus: Invalid subId");
6233 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6234 }
6235 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006236 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006237 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006238 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6239 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006240
6241 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6242 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006243 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006244 }
Junda Liu29340342014-07-10 15:23:27 -07006245
6246 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006247 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006248 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006249 final Phone phone = getPhone(subId);
6250 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006251 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6253 }
6254 UiccProfile profile =
6255 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6256 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006257 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006258 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6259 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006260 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006261 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006262 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006263 }
6264
6265 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006266 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6267 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006268 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006269 }
6270
6271 int phoneId = SubscriptionManager.getPhoneId(subId);
6272 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006273 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006274 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006275 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6276 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006277 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6278 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6279 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006280 }
6281
6282 @Override
6283 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006284 if (TextUtils.isEmpty(pkgName))
6285 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006286 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6287 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6288 UiccCard card = UiccController.getInstance().getUiccCard(i);
6289 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006290 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006291 continue;
6292 }
6293
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006294 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6295 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6296 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006297 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6298 break;
6299 }
6300 }
6301
6302 return result;
Junda Liu29340342014-07-10 15:23:27 -07006303 }
Derek Tan89e89d42014-07-08 17:00:10 -07006304
6305 @Override
Junda Liue64de782015-04-16 17:19:16 -07006306 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6307 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6308 loge("phoneId " + phoneId + " is not valid.");
6309 return null;
6310 }
6311 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006312 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006313 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006314 return null ;
6315 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006317 }
6318
Amith Yamasani6e118872016-02-19 12:53:51 -08006319 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006320 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006321 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006322 List<String> privilegedPackages = new ArrayList<>();
6323 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006324 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6325 // has UICC in that slot.
6326 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006327 if (card.hasCarrierPrivilegeRules()) {
6328 if (packages == null) {
6329 // Only check packages in user 0 for now
6330 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006331 PackageManager.MATCH_DISABLED_COMPONENTS
6332 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006333 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006334 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006335 }
6336 for (int p = packages.size() - 1; p >= 0; p--) {
6337 PackageInfo pkgInfo = packages.get(p);
6338 if (pkgInfo != null && pkgInfo.packageName != null
6339 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006340 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006341 privilegedPackages.add(pkgInfo.packageName);
6342 }
6343 }
6344 }
6345 }
6346 return privilegedPackages;
6347 }
6348
chen xuf7e9fe82019-05-09 19:31:02 -07006349 @Override
6350 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006351 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6352
6353 final long identity = Binder.clearCallingIdentity();
6354
chen xuf7e9fe82019-05-09 19:31:02 -07006355 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006356 try {
6357 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6358 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6359 }
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006362 }
6363 return privilegedPackages;
6364 }
6365
Wink Savilleb564aae2014-10-23 10:18:09 -07006366 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006367 final Phone phone = getPhone(subId);
6368 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006369 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006370 return null;
6371 }
6372 String iccId = card.getIccId();
6373 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006374 return null;
6375 }
6376 return iccId;
6377 }
6378
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006379 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006380 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6381 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006382 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006383 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 final String iccId = getIccId(subId);
6388 final Phone phone = getPhone(subId);
6389 if (phone == null) {
6390 return false;
6391 }
6392 final String subscriberId = phone.getSubscriberId();
6393
6394 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006395 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 + subscriberId + " to " + number);
6397 }
6398
6399 if (TextUtils.isEmpty(iccId)) {
6400 return false;
6401 }
6402
6403 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6404
6405 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6406 if (alphaTag == null) {
6407 editor.remove(alphaTagPrefKey);
6408 } else {
6409 editor.putString(alphaTagPrefKey, alphaTag);
6410 }
6411
6412 // Record both the line number and IMSI for this ICCID, since we need to
6413 // track all merged IMSIs based on line number
6414 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6415 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6416 if (number == null) {
6417 editor.remove(numberPrefKey);
6418 editor.remove(subscriberPrefKey);
6419 } else {
6420 editor.putString(numberPrefKey, number);
6421 editor.putString(subscriberPrefKey, subscriberId);
6422 }
6423
6424 editor.commit();
6425 return true;
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006428 }
Derek Tan7226c842014-07-02 17:42:23 -07006429 }
6430
6431 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006432 public String getLine1NumberForDisplay(int subId, String callingPackage,
6433 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006434 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006436 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006437 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006438 return null;
6439 }
Derek Tan97ebb422014-09-05 16:55:38 -07006440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 String iccId = getIccId(subId);
6444 if (iccId != null) {
6445 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6446 if (DBG_MERGE) {
6447 log("getLine1NumberForDisplay returning "
6448 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6449 }
6450 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6453 return null;
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006456 }
Derek Tan7226c842014-07-02 17:42:23 -07006457 }
6458
6459 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006460 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6461 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006463 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006464 return null;
6465 }
Derek Tan97ebb422014-09-05 16:55:38 -07006466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 String iccId = getIccId(subId);
6470 if (iccId != null) {
6471 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6472 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6473 }
6474 return null;
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006477 }
Derek Tan7226c842014-07-02 17:42:23 -07006478 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006479
6480 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006481 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6482 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006483 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6484 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006486 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006487 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006488 return null;
6489 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006490
Jordan Liub49b04b2019-05-06 14:45:15 -07006491 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6492 // the process, where TelephonyManager was instantiated.
6493 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006494 final long identity = Binder.clearCallingIdentity();
6495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006496 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 final TelephonyManager tele = TelephonyManager.from(context);
6498 final SubscriptionManager sub = SubscriptionManager.from(context);
6499
6500 // Figure out what subscribers are currently active
6501 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
Jordan Liub49b04b2019-05-06 14:45:15 -07006503 // Only consider subs which match the current subId
6504 // This logic can be simplified. See b/131189269 for progress.
6505 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006506 activeSubscriberIds.add(tele.getSubscriberId(subId));
6507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508
6509 // First pass, find a number override for an active subscriber
6510 String mergeNumber = null;
6511 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6512 for (String key : prefs.keySet()) {
6513 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6514 final String subscriberId = (String) prefs.get(key);
6515 if (activeSubscriberIds.contains(subscriberId)) {
6516 final String iccId = key.substring(
6517 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6518 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6519 mergeNumber = (String) prefs.get(numberKey);
6520 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006521 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 + " for active subscriber " + subscriberId);
6523 }
6524 if (!TextUtils.isEmpty(mergeNumber)) {
6525 break;
6526 }
6527 }
6528 }
6529 }
6530
6531 // Shortcut when no active merged subscribers
6532 if (TextUtils.isEmpty(mergeNumber)) {
6533 return null;
6534 }
6535
6536 // Second pass, find all subscribers under that line override
6537 final ArraySet<String> result = new ArraySet<>();
6538 for (String key : prefs.keySet()) {
6539 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6540 final String number = (String) prefs.get(key);
6541 if (mergeNumber.equals(number)) {
6542 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6543 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6544 final String subscriberId = (String) prefs.get(subscriberKey);
6545 if (!TextUtils.isEmpty(subscriberId)) {
6546 result.add(subscriberId);
6547 }
6548 }
6549 }
6550 }
6551
6552 final String[] resultArray = result.toArray(new String[result.size()]);
6553 Arrays.sort(resultArray);
6554 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006555 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6557 }
6558 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006561 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006562 }
6563
6564 @Override
zoey chen38003472019-12-13 17:16:31 +08006565 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6566 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 final TelephonyManager telephonyManager = mApp.getSystemService(
6571 TelephonyManager.class);
6572 String subscriberId = telephonyManager.getSubscriberId(subId);
6573 if (subscriberId == null) {
6574 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006575 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006576 + subId);
6577 }
6578 return null;
6579 }
6580
6581 final SubscriptionInfo info = SubscriptionController.getInstance()
6582 .getSubscriptionInfo(subId);
6583 final ParcelUuid groupUuid = info.getGroupUuid();
6584 // If it doesn't belong to any group, return just subscriberId of itself.
6585 if (groupUuid == null) {
6586 return new String[]{subscriberId};
6587 }
6588
6589 // Get all subscriberIds from the group.
6590 final List<String> mergedSubscriberIds = new ArrayList<>();
6591 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006592 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006593 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006594 for (SubscriptionInfo subInfo : groupInfos) {
6595 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6596 if (subscriberId != null) {
6597 mergedSubscriberIds.add(subscriberId);
6598 }
6599 }
6600
6601 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604
6605 }
6606 }
6607
6608 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006609 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006610 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006611 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 final Phone phone = getPhone(subId);
6616 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006620 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006621
6622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006623 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006624 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6625 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006626 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6627 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 final Phone phone = getPhone(subId);
6632 if (phone == null) {
6633 return false;
6634 }
6635 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6636 cdmaNonRoamingList);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006639 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006640 }
6641
6642 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006643 @Deprecated
6644 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6645 enforceModifyPermission();
6646
6647 int returnValue = 0;
6648 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006649 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006650 if(result.exception == null) {
6651 if (result.result != null) {
6652 byte[] responseData = (byte[])(result.result);
6653 if(responseData.length > oemResp.length) {
6654 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6655 responseData.length + "bytes. Buffer Size is " +
6656 oemResp.length + "bytes.");
6657 }
6658 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6659 returnValue = responseData.length;
6660 }
6661 } else {
6662 CommandException ex = (CommandException) result.exception;
6663 returnValue = ex.getCommandError().ordinal();
6664 if(returnValue > 0) returnValue *= -1;
6665 }
6666 } catch (RuntimeException e) {
6667 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6668 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6669 if(returnValue > 0) returnValue *= -1;
6670 }
6671
6672 return returnValue;
6673 }
6674
6675 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006676 public void setRadioCapability(RadioAccessFamily[] rafs) {
6677 try {
6678 ProxyController.getInstance().setRadioCapability(rafs);
6679 } catch (RuntimeException e) {
6680 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6681 }
6682 }
6683
6684 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006685 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006686 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006687 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006688 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006689 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 final long identity = Binder.clearCallingIdentity();
6692 try {
chen xub97461a2018-10-26 14:17:57 -07006693 TelephonyPermissions
6694 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6695 mApp, phone.getSubId(), "getRadioAccessFamily");
6696 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
chen xub97461a2018-10-26 14:17:57 -07006700 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006701 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006702
6703 @Override
6704 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006705 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006710 ImsManager.getInstance(defaultPhone.getContext(),
6711 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006715 }
6716
6717 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006718 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006719 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6721 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006722 return false;
6723 }
Svet Ganovb320e182015-04-16 12:30:10 -07006724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 // Check the user preference and the system-level IMS setting. Even if the user has
6728 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6729 // In the long run, we may instead need to check if there exists a connection service
6730 // which can support video calling.
6731 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006732 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 return imsManager.isVtEnabledByPlatform()
6734 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6735 && imsManager.isVtEnabledByUser();
6736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006739 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006740
Andrew Leea1239f22015-03-02 17:44:07 -08006741 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006742 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6743 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006745 mApp, subId, callingPackage, callingFeatureId,
6746 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 return false;
6748 }
6749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 CarrierConfigManager configManager =
6753 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006754 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
Andrew Leea1239f22015-03-02 17:44:07 -08006759 }
6760
6761 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006762 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006764 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 return false;
6766 }
6767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 CarrierConfigManager configManager =
6771 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006772 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
Andrew Leea1239f22015-03-02 17:44:07 -08006777 }
6778
Andrew Lee9431b832015-03-09 18:46:45 -07006779 @Override
6780 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006781 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006782 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006783 }
6784
6785 @Override
6786 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006789 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
Andrew Lee9431b832015-03-09 18:46:45 -07006793 }
6794
Hall Liuf6668912018-10-31 17:05:23 -07006795 /**
6796 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6797 * support for the feature and device firmware support.
6798 *
6799 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6800 */
6801 @Override
6802 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006804 final Phone phone = getPhone(subscriptionId);
6805 if (phone == null) {
6806 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6807 return false;
6808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006810 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6812 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 return isCarrierSupported && isDeviceSupported;
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
Hall Liu98187582018-01-22 19:15:32 -08006818 }
6819
Hall Liuf6668912018-10-31 17:05:23 -07006820 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006821 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6822 * RTT setting, will return true if the device and carrier both support RTT.
6823 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006824 */
6825 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 final long identity = Binder.clearCallingIdentity();
6827 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006828 boolean isRttSupported = isRttSupported(subscriptionId);
6829 boolean isUserRttSettingOn = Settings.Secure.getInt(
6830 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6831 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6832 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6833 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006837 }
6838
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006839 @Deprecated
6840 @Override
6841 public String getDeviceId(String callingPackage) {
6842 return getDeviceIdWithFeature(callingPackage, null);
6843 }
6844
Sanket Padawe7310cc72015-01-14 09:53:20 -08006845 /**
6846 * Returns the unique device ID of phone, for example, the IMEI for
6847 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6848 *
6849 * <p>Requires Permission:
6850 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6851 */
6852 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006853 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006854 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006855 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006856 return null;
6857 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006858 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006859 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006860 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006861 return null;
6862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 return phone.getDeviceId();
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006870 }
6871
Ping Sunc67b7c22016-03-02 19:16:45 +08006872 /**
6873 * {@hide}
6874 * Returns the IMS Registration Status on a particular subid
6875 *
6876 * @param subId
6877 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006878 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006879 Phone phone = getPhone(subId);
6880 if (phone != null) {
6881 return phone.isImsRegistered();
6882 } else {
6883 return false;
6884 }
6885 }
6886
Santos Cordon7a1885b2015-02-03 11:15:19 -08006887 @Override
6888 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006895 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006896
Tyler Gunnf70ed162019-04-03 15:28:53 -07006897 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006898 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006899 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006901 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006902 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6903 }
6904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6907 } finally {
6908 Binder.restoreCallingIdentity(identity);
6909 }
6910 }
6911
6912 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006913 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006914 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6915 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 Phone phone = getPhone(subscriptionId);
6919 if (phone == null) {
6920 return null;
6921 }
6922 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
6926 }
6927
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006928 /**
6929 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006930 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006931 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 Phone phone = getPhone(subId);
6935 if (phone != null) {
6936 return phone.isWifiCallingEnabled();
6937 } else {
6938 return false;
6939 }
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006942 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006943 }
6944
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006945 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006946 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006947 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006948 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 Phone phone = getPhone(subId);
6952 if (phone != null) {
6953 return phone.isVideoEnabled();
6954 } else {
6955 return false;
6956 }
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006959 }
6960 }
6961
6962 /**
6963 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6964 * defined in {@link ImsRegistrationImplBase}.
6965 */
6966 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 Phone phone = getPhone(subId);
6970 if (phone != null) {
6971 return phone.getImsRegistrationTech();
6972 } else {
6973 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6974 }
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006977 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006978 }
6979
Stuart Scott8eef64f2015-04-08 15:13:54 -07006980 @Override
6981 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006982 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006983 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6984 return;
6985 }
6986
Svet Ganovcc087f82015-05-12 20:35:54 -07006987 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006988
Svet Ganovcc087f82015-05-12 20:35:54 -07006989 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006990 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6991 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006992 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006993 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006994 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006995 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006996 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6997 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006998 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006999 // There has been issues when Sms raw table somehow stores orphan
7000 // fragments. They lead to garbled message when new fragments come
7001 // in and combined with those stale ones. In case this happens again,
7002 // user can reset all network settings which will clean up this table.
7003 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007004 // Clean up IMS settings as well here.
7005 int slotId = getSlotIndex(subId);
7006 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7007 ImsManager.getInstance(mApp, slotId).factoryReset();
7008 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007009
7010 // Erase modem config if erase modem on network setting is enabled.
7011 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7012 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7013 if (configValue != null && Boolean.parseBoolean(configValue)) {
7014 sendEraseModemConfig(getDefaultPhone());
7015 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007016 } finally {
7017 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007018 }
7019 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007020
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007021 private void cleanUpSmsRawTable(Context context) {
7022 ContentResolver resolver = context.getContentResolver();
7023 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7024 resolver.delete(uri, null, null);
7025 }
7026
Narayan Kamath1c496c22015-04-16 14:40:19 +01007027 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007028 public String getSimLocaleForSubscriber(int subId) {
7029 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7030 final Phone phone = getPhone(subId);
7031 if (phone == null) {
7032 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007033 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
7036 try {
chen xu5d3637b2019-01-21 23:31:38 -08007037 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007038 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007039 if (info == null) {
7040 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7041 return null;
7042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 // Try and fetch the locale from the carrier properties or from the SIM language
7044 // preferences (EF-PL and EF-LI)...
7045 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007047 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7048 if (localeFromDefaultSim != null) {
7049 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7050 if (DBG) log("Using locale from subId: " + subId + " locale: "
7051 + localeFromDefaultSim);
7052 return localeFromDefaultSim.toLanguageTag();
7053 } else {
7054 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 }
7056 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 // The SIM language preferences only store a language (e.g. fr = French), not an
7059 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7060 // the SIM and carrier preferences does not include a country we add the country
7061 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007062 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007064 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 return mccLocale.toLanguageTag();
7066 }
7067
7068 if (DBG) log("No locale found - returning null");
7069 return null;
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007073 }
7074
7075 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007076 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007077 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007078 }
7079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 /**
7081 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7082 */
7083 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007084 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007085 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007086 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007087
Chenjie Yu1ba97252018-01-11 18:16:20 -08007088 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007089 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007090
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007091 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007092 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7093 * representing the state of the modem.
7094 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007095 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7096 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007097 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007098 */
7099 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007100 public void requestModemActivityInfo(ResultReceiver result) {
7101 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
sqian1a1be542020-03-05 11:37:28 -08007106 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007109 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007110 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007111
Siddharth Rayb8114062018-06-17 15:02:38 -07007112 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7113 // less than total activity duration.
7114 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7115 if (info == null) {
7116 return false;
7117 }
7118 int activityDurationMs =
7119 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7120 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007121 int[] txTimeMs = info.getTransmitTimeMillis();
7122 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7123 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007124 }
7125 return (info.isValid()
7126 && (info.getSleepTimeMillis() <= activityDurationMs)
7127 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007128 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007129 && (totalTxTimeMs <= activityDurationMs));
7130 }
7131
Jack Yu85bd38a2015-11-09 11:34:32 -08007132 /**
7133 * {@hide}
7134 * Returns the service state information on specified subscription.
7135 */
7136 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007137 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7138 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007140 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007141 return null;
7142 }
7143
Hall Liuf19c44f2018-11-27 14:38:17 -08007144 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
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 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7154 .build());
7155
7156 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7157 LocationAccessPolicy.checkLocationPermission(mApp,
7158 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7159 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007160 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007161 .setCallingPid(Binder.getCallingPid())
7162 .setCallingUid(Binder.getCallingUid())
7163 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007164 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007165 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7166 .build());
7167 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7168 boolean hasFinePermission =
7169 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7170 boolean hasCoarsePermission =
7171 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 final Phone phone = getPhone(subId);
7176 if (phone == null) {
7177 return null;
7178 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007179
Hall Liuf19c44f2018-11-27 14:38:17 -08007180 ServiceState ss = phone.getServiceState();
7181
7182 // Scrub out the location info in ServiceState depending on what level of access
7183 // the caller has.
7184 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007185 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7186 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007190 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007191
7192 /**
7193 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7194 *
7195 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7196 * voicemail ringtone.
7197 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7198 * PhoneAccount.
7199 */
7200 @Override
7201 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7205 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007206 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
7212 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007213 }
7214
7215 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007216 * Sets the per-account voicemail ringtone.
7217 *
7218 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7219 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7220 *
7221 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7222 * voicemail ringtone.
7223 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7224 * PhoneAccount.
7225 */
7226 @Override
7227 public void setVoicemailRingtoneUri(String callingPackage,
7228 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007229 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007230 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007231 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7232 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7234 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7235 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7241 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007242 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 }
7244 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007247 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007248 }
7249
7250 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007251 * Returns whether vibration is set for voicemail notification in Phone settings.
7252 *
7253 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7254 * voicemail vibration setting.
7255 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7256 */
7257 @Override
7258 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7262 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007263 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007270 }
7271
Youhan Wange64578a2016-05-02 15:32:42 -07007272 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007273 * Sets the per-account voicemail vibration.
7274 *
7275 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7276 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7277 *
7278 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7279 * voicemail vibration setting.
7280 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7281 * specific PhoneAccount.
7282 */
7283 @Override
7284 public void setVoicemailVibrationEnabled(String callingPackage,
7285 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007286 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007288 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7289 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7291 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7292 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007293 }
7294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7298 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007299 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300 }
7301 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007304 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007305 }
7306
7307 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007308 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7309 *
7310 * @throws SecurityException if the caller does not have the required permission
7311 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007312 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007313 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007314 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007315 }
7316
7317 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007318 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7319 * permission.
7320 *
7321 * @throws SecurityException if the caller does not have the required permission
7322 */
7323 private void enforceSendSmsPermission() {
7324 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7325 }
7326
7327 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007328 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007329 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007330 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007331 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007332 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007336 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (componentName == null) {
7338 throw new SecurityException(
7339 "Caller not current active visual voicemail package[null]");
7340 }
7341 String vvmPackage = componentName.getPackageName();
7342 if (!callingPackage.equals(vvmPackage)) {
7343 throw new SecurityException("Caller not current active visual voicemail package["
7344 + vvmPackage + "]");
7345 }
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007348 }
7349 }
7350
7351 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007352 * Return the application ID for the app type.
7353 *
7354 * @param subId the subscription ID that this request applies to.
7355 * @param appType the uicc app type.
7356 * @return Application ID for specificied app type, or null if no uicc.
7357 */
7358 @Override
7359 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007360 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007361 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362
7363 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007364 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 if (phone == null) {
7366 return null;
7367 }
7368 String aid = null;
7369 try {
7370 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7371 .getApplicationByType(appType).getAid();
7372 } catch (Exception e) {
7373 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7374 }
7375 return aid;
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007378 }
Youhan Wange64578a2016-05-02 15:32:42 -07007379 }
7380
Youhan Wang4001d252016-05-11 10:29:41 -07007381 /**
7382 * Return the Electronic Serial Number.
7383 *
7384 * @param subId the subscription ID that this request applies to.
7385 * @return ESN or null if error.
7386 */
7387 @Override
7388 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007389 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007390 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391
7392 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007393 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 if (phone == null) {
7395 return null;
7396 }
7397 String esn = null;
7398 try {
7399 esn = phone.getEsn();
7400 } catch (Exception e) {
7401 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7402 }
7403 return esn;
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007406 }
Youhan Wang4001d252016-05-11 10:29:41 -07007407 }
7408
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007409 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007410 * Return the Preferred Roaming List Version.
7411 *
7412 * @param subId the subscription ID that this request applies to.
7413 * @return PRLVersion or null if error.
7414 */
7415 @Override
7416 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007417 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007418 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419
7420 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007421 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 if (phone == null) {
7423 return null;
7424 }
7425 String cdmaPrlVersion = null;
7426 try {
7427 cdmaPrlVersion = phone.getCdmaPrlVersion();
7428 } catch (Exception e) {
7429 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7430 }
7431 return cdmaPrlVersion;
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007434 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007435 }
7436
7437 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007438 * Get snapshot of Telephony histograms
7439 * @return List of Telephony histograms
7440 * @hide
7441 */
7442 @Override
7443 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7445 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 return RIL.getTelephonyRILTimingHistograms();
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007453 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007454
7455 /**
7456 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007457 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7458 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007459 * Require system privileges. In the future we may add this to carrier APIs.
7460 *
Michele Berionne482f8202018-11-27 18:57:59 -08007461 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007462 */
7463 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007464 @TelephonyManager.SetCarrierRestrictionResult
7465 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007466 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007468
Michele Berionne482f8202018-11-27 18:57:59 -08007469 if (carrierRestrictionRules == null) {
7470 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007471 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 final long identity = Binder.clearCallingIdentity();
7474 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007475 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007476 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007480 }
7481
7482 /**
7483 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007484 * Get the allowed carrier list and the excluded carrier list, including the priority between
7485 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007486 * Require system privileges. In the future we may add this to carrier APIs.
7487 *
Michele Berionne482f8202018-11-27 18:57:59 -08007488 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007489 */
7490 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007491 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007492 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007497 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7498 if (response instanceof CarrierRestrictionRules) {
7499 return (CarrierRestrictionRules) response;
7500 }
7501 // Response is an Exception of some kind,
7502 // which is signalled to the user as a NULL retval
7503 return null;
7504 } catch (Exception e) {
7505 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7506 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007510 }
7511
fionaxu59545b42016-05-25 15:53:37 -07007512 /**
fionaxu59545b42016-05-25 15:53:37 -07007513 * Action set from carrier signalling broadcast receivers to enable/disable radio
7514 * @param subId the subscription ID that this action applies to.
7515 * @param enabled control enable or disable radio.
7516 * {@hide}
7517 */
7518 @Override
7519 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7520 enforceModifyPermission();
7521 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522
7523 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007524 if (phone == null) {
7525 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7526 return;
7527 }
7528 try {
7529 phone.carrierActionSetRadioEnabled(enabled);
7530 } catch (Exception e) {
7531 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007534 }
7535 }
7536
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007537 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007538 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7539 * network status based on which carrier apps could apply actions accordingly,
7540 * enable/disable default url handler for example.
7541 *
7542 * @param subId the subscription ID that this action applies to.
7543 * @param report control start/stop reporting the default network status.
7544 * {@hide}
7545 */
7546 @Override
7547 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7548 enforceModifyPermission();
7549 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550
7551 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007552 if (phone == null) {
7553 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7554 return;
7555 }
7556 try {
7557 phone.carrierActionReportDefaultNetworkStatus(report);
7558 } catch (Exception e) {
7559 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 } finally {
7561 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007562 }
7563 }
7564
7565 /**
fionaxud9622282017-07-17 17:51:30 -07007566 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7567 * @param subId the subscription ID that this action applies to.
7568 * {@hide}
7569 */
7570 @Override
7571 public void carrierActionResetAll(int subId) {
7572 enforceModifyPermission();
7573 final Phone phone = getPhone(subId);
7574 if (phone == null) {
7575 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7576 return;
7577 }
7578 try {
7579 phone.carrierActionResetAll();
7580 } catch (Exception e) {
7581 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7582 }
7583 }
7584
7585 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007586 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7587 * bug report is being generated.
7588 */
7589 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007590 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007591 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7592 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007593 writer.println("Permission Denial: can't dump Phone from pid="
7594 + Binder.getCallingPid()
7595 + ", uid=" + Binder.getCallingUid()
7596 + "without permission "
7597 + android.Manifest.permission.DUMP);
7598 return;
7599 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007600 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007601 }
Jack Yueb89b242016-06-22 13:27:47 -07007602
Brad Ebingerdac2f002018-04-03 15:17:52 -07007603 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007604 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7605 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7606 @NonNull String[] args) {
7607 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7608 this, in.getFileDescriptor(), out.getFileDescriptor(),
7609 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007610 }
7611
Jack Yueb89b242016-06-22 13:27:47 -07007612 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007613 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007614 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007615 * @param reason the reason the data enable change is taking place
7616 * @param enabled True if enabling the data, otherwise disabling.
7617 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007618 */
7619 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007620 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007621 boolean enabled) {
7622 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7623 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7624 try {
7625 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007626 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007627 } catch (SecurityException se) {
7628 enforceModifyPermission();
7629 }
7630 } else {
7631 enforceModifyPermission();
7632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = getPhone(subId);
7637 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007638 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7639 phone.carrierActionSetMeteredApnsEnabled(enabled);
7640 } else {
7641 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 }
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007646 }
7647 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007648
7649 /**
7650 * Get Client request stats
7651 * @return List of Client Request Stats
7652 * @hide
7653 */
7654 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007655 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7656 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007658 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007659 return null;
7660 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007661 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 if (phone != null) {
7666 return phone.getClientRequestStats();
7667 }
7668
7669 return null;
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
7672 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007673 }
7674
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007675 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007676 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007677 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007678 }
Jack Yueb4124c2017-02-16 15:32:43 -08007679
7680 /**
Grace Chen70990072017-03-24 17:21:30 -07007681 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007682 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007683 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007684 * @param state State of SIM (power down, power up, pass through)
7685 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7686 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7687 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007688 *
7689 **/
7690 @Override
Grace Chen70990072017-03-24 17:21:30 -07007691 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007692 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007693 Phone phone = PhoneFactory.getPhone(slotIndex);
7694
vagdeviaf9a5b92018-08-15 16:01:53 -07007695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007700 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 }
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007704 }
7705 }
Shuo Qiandd210312017-04-12 22:11:33 +00007706
Tyler Gunn65d45c22017-06-05 11:22:26 -07007707 private boolean isUssdApiAllowed(int subId) {
7708 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007710 if (configManager == null) {
7711 return false;
7712 }
7713 PersistableBundle pb = configManager.getConfigForSubId(subId);
7714 if (pb == null) {
7715 return false;
7716 }
7717 return pb.getBoolean(
7718 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7719 }
7720
Shuo Qiandd210312017-04-12 22:11:33 +00007721 /**
7722 * Check if phone is in emergency callback mode
7723 * @return true if phone is in emergency callback mode
7724 * @param subId sub id
7725 */
goneil9c5f4872017-12-05 14:07:56 -08007726 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007727 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007728 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730
7731 final long identity = Binder.clearCallingIdentity();
7732 try {
7733 if (phone != null) {
7734 return phone.isInEcm();
7735 } else {
7736 return false;
7737 }
7738 } finally {
7739 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007740 }
7741 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007742
7743 /**
7744 * Get the current signal strength information for the given subscription.
7745 * Because this information is not updated when the device is in a low power state
7746 * it should not be relied-upon to be current.
7747 * @param subId Subscription index
7748 * @return the most recent cached signal strength info from the modem
7749 */
7750 @Override
7751 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 Phone p = getPhone(subId);
7755 if (p == null) {
7756 return null;
7757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 return p.getSignalStrength();
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
7762 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007763 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007764
Pengquan Meng77b7f132018-08-22 14:49:57 -07007765 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007766 * Get the current modem radio state for the given slot.
7767 * @param slotIndex slot index.
7768 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007769 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007770 * @return the current radio power state from the modem
7771 */
7772 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007773 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007774 Phone phone = PhoneFactory.getPhone(slotIndex);
7775 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7777 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007778 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7779 }
7780
7781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 return phone.getRadioPowerState();
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
7787 }
7788 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7789 }
7790
7791 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007792 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7793 *
7794 * <p>Requires one of the following permissions:
7795 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7796 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7797 * privileges.
7798 *
7799 * @param subId subscription id
7800 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7801 * {@code false}.
7802 */
7803 @Override
7804 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007805 try {
7806 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7807 null);
7808 } catch (Exception e) {
7809 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7810 mApp, subId, "isDataRoamingEnabled");
7811 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007812
Pengquan Menga1bb6272018-09-06 09:59:22 -07007813 boolean isEnabled = false;
7814 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007815 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007816 Phone phone = getPhone(subId);
7817 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007818 } finally {
7819 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007820 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007821 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007822 }
7823
7824
7825 /**
7826 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7827 *
7828 * <p> Requires permission:
7829 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7830 * privileges.
7831 *
7832 * @param subId subscription id
7833 * @param isEnabled {@code true} means enable, {@code false} means disable.
7834 */
7835 @Override
7836 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7838 mApp, subId, "setDataRoamingEnabled");
7839
Pengquan Menga1bb6272018-09-06 09:59:22 -07007840 final long identity = Binder.clearCallingIdentity();
7841 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007842 Phone phone = getPhone(subId);
7843 if (phone != null) {
7844 phone.setDataRoamingEnabled(isEnabled);
7845 }
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007848 }
7849 }
7850
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007851 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007852 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007853 TelephonyPermissions
7854 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007855 mApp, subId, "isManualNetworkSelectionAllowed");
7856
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007857 boolean isAllowed = true;
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007860 Phone phone = getPhone(subId);
7861 if (phone != null) {
7862 isAllowed = phone.isCspPlmnEnabled();
7863 }
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
7867 return isAllowed;
7868 }
7869
7870 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007871 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007872 // Verify that tha callingPackage belongs to the calling UID
7873 mApp.getSystemService(AppOpsManager.class)
7874 .checkPackage(Binder.getCallingUid(), callingPackage);
7875
Jordan Liu1e142fc2019-04-22 15:10:43 -07007876 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007877 try {
7878 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007879 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007880 } catch (SecurityException e) {
7881 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7882 // has carrier privileges on an active UICC
7883 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7884 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007885 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007886 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007887 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007891 UiccController uiccController = UiccController.getInstance();
7892 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007893 if (hasReadPermission) {
7894 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007895 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007896
7897 // Remove private info if the caller doesn't have access
7898 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7899 for (UiccCardInfo cardInfo : cardInfos) {
7900 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7901 // is available
7902 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7903 if (card == null || card.getUiccProfile() == null) {
7904 // assume no access if the card or profile is unavailable
7905 filteredInfos.add(cardInfo.getUnprivileged());
7906 continue;
7907 }
7908 UiccProfile profile = card.getUiccProfile();
7909 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7910 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7911 filteredInfos.add(cardInfo);
7912 } else {
7913 filteredInfos.add(cardInfo.getUnprivileged());
7914 }
7915 }
7916 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919 }
7920 }
7921
7922 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007923 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007924 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7929 if (slots == null) {
7930 Rlog.i(LOG_TAG, "slots is null.");
7931 return null;
7932 }
7933
7934 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7935 for (int i = 0; i < slots.length; i++) {
7936 UiccSlot slot = slots[i];
7937 if (slot == null) {
7938 continue;
7939 }
7940
Jordan Liu7be7e652019-05-06 18:55:02 +00007941 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 UiccCard card = slot.getUiccCard();
7943 if (card != null) {
7944 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007945 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007946 cardId = slot.getEid();
7947 if (TextUtils.isEmpty(cardId)) {
7948 cardId = slot.getIccId();
7949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 }
7951
Jordan Liu857451f2019-05-09 16:35:35 -07007952 if (cardId != null) {
7953 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7954 // if cardId is an EID, it's all digits so this is fine
7955 cardId = IccUtils.stripTrailingFs(cardId);
7956 }
7957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 int cardState = 0;
7959 switch (slot.getCardState()) {
7960 case CARDSTATE_ABSENT:
7961 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7962 break;
7963 case CARDSTATE_PRESENT:
7964 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7965 break;
7966 case CARDSTATE_ERROR:
7967 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7968 break;
7969 case CARDSTATE_RESTRICTED:
7970 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7971 break;
7972 default:
7973 break;
7974
7975 }
7976
7977 infos[i] = new UiccSlotInfo(
7978 slot.isActive(),
7979 slot.isEuicc(),
7980 cardId,
7981 cardState,
7982 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007983 slot.isExtendedApduSupported(),
7984 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 }
7986 return infos;
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007990 }
7991
7992 @Override
7993 public boolean switchSlots(int[] physicalSlots) {
7994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995
7996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
8001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008002 }
Jack Yu4c988042018-02-27 15:30:01 -08008003
8004 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008005 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 return UiccController.getInstance().getCardIdForDefaultEuicc();
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
8011 }
8012 }
8013
Pengquan Meng85728fb2018-03-12 16:31:21 -07008014 /**
goneil47ffb6e2018-04-06 15:40:58 -07008015 * A test API to reload the UICC profile.
8016 *
8017 * <p>Requires that the calling app has permission
8018 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8019 * @hide
8020 */
8021 @Override
8022 public void refreshUiccProfile(int subId) {
8023 enforceModifyPermission();
8024
8025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 Phone phone = getPhone(subId);
8028 if (phone == null) {
8029 return;
8030 }
8031 UiccCard uiccCard = phone.getUiccCard();
8032 if (uiccCard == null) {
8033 return;
8034 }
8035 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8036 if (uiccProfile == null) {
8037 return;
8038 }
8039 uiccProfile.refresh();
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
8042 }
8043 }
8044
8045 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008046 * Returns false if the mobile data is disabled by default, otherwise return true.
8047 */
8048 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008049 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008050 }
8051
8052 /**
8053 * Returns true if the data roaming is enabled by default, i.e the system property
8054 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8055 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8056 */
8057 private boolean getDefaultDataRoamingEnabled(int subId) {
8058 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008059 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008060 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008061 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8062 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8063 return isDataRoamingEnabled;
8064 }
8065
8066 /**
8067 * Returns the default network type for the given {@code subId}, if the default network type is
8068 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8069 */
8070 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008071 List<Integer> list = TelephonyProperties.default_network();
8072 int phoneId = mSubscriptionController.getPhoneId(subId);
8073 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8074 return list.get(phoneId);
8075 }
8076 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008077 }
fionaxua13278b2018-03-21 00:08:13 -07008078
8079 @Override
8080 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008081 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083
8084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 final Phone phone = getPhone(subId);
8087 if (phone == null) {
8088 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8089 return;
8090 }
chen xueaba88a2019-03-15 13:15:10 -07008091 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8092 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008093 if (carrierPrivilegeRules == null) {
8094 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8095 } else {
8096 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 } finally {
8099 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008100 }
fionaxua13278b2018-03-21 00:08:13 -07008101 }
8102
8103 @Override
8104 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008105 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106
8107 final long identity = Binder.clearCallingIdentity();
8108 try {
8109 final Phone phone = getPhone(subId);
8110 if (phone == null) {
8111 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8112 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8113 }
8114 return phone.getCarrierIdListVersion();
8115 } finally {
8116 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008117 }
fionaxua13278b2018-03-21 00:08:13 -07008118 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008119
8120 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008121 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8122 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008124 mApp, subId, callingPackage, callingFeatureId,
8125 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008126 return -1;
8127 }
8128
8129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
8135 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008136
8137 @Override
8138 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008139 TelephonyPermissions
8140 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008141 mApp, subId, "getCdmaRoamingMode");
8142
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
8145 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
8149 }
8150
8151 @Override
8152 public boolean setCdmaRoamingMode(int subId, int mode) {
8153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8154 mApp, subId, "setCdmaRoamingMode");
8155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
8161 }
8162 }
8163
8164 @Override
8165 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8167 mApp, subId, "setCdmaSubscriptionMode");
8168
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
8171 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
8175 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008176
sqianc5eccab2018-10-19 18:46:41 -07008177 @Override
sqian8c685422019-02-22 15:55:18 -08008178 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008179 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008181 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8182 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008183 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8184 }
8185 final long identity = Binder.clearCallingIdentity();
8186 try {
sqian854d44b2018-12-12 16:48:18 -08008187 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8188 for (Phone phone: PhoneFactory.getPhones()) {
8189 if (phone.getEmergencyNumberTracker() != null
8190 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8191 emergencyNumberListInternal.put(
8192 phone.getSubId(),
8193 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8194 }
sqian11b7a0e2018-12-05 18:48:28 -08008195 }
sqian854d44b2018-12-12 16:48:18 -08008196 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
sqianc5eccab2018-10-19 18:46:41 -07008200 }
8201
8202 @Override
sqian8c685422019-02-22 15:55:18 -08008203 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008205 if (!exactMatch) {
8206 TelephonyPermissions
8207 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008208 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008209 }
8210 final long identity = Binder.clearCallingIdentity();
8211 try {
sqian854d44b2018-12-12 16:48:18 -08008212 for (Phone phone: PhoneFactory.getPhones()) {
8213 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008214 && phone.getEmergencyNumberTracker()
8215 .isEmergencyNumber(number, exactMatch)) {
8216 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008217 }
sqian11b7a0e2018-12-05 18:48:28 -08008218 }
8219 return false;
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 }
8224
sqianf4ca7ed2019-01-15 18:32:07 -08008225 /**
8226 * Update emergency number list for test mode.
8227 */
8228 @Override
8229 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8231 "updateEmergencyNumberListTestMode");
8232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 for (Phone phone: PhoneFactory.getPhones()) {
8236 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8237 if (tracker != null) {
8238 tracker.executeEmergencyNumberTestModeCommand(action, num);
8239 }
8240 }
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
8244 }
8245
8246 /**
8247 * Get the full emergency number list for test mode.
8248 */
8249 @Override
8250 public List<String> getEmergencyNumberListTestMode() {
8251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8252 "getEmergencyNumberListTestMode");
8253
8254 final long identity = Binder.clearCallingIdentity();
8255 try {
8256 Set<String> emergencyNumbers = new HashSet<>();
8257 for (Phone phone: PhoneFactory.getPhones()) {
8258 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8259 if (tracker != null) {
8260 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8261 emergencyNumbers.add(num.getNumber());
8262 }
8263 }
8264 }
8265 return new ArrayList<>(emergencyNumbers);
8266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
8269 }
8270
chen xud6b45bd2018-10-30 22:27:10 -07008271 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008272 public int getEmergencyNumberDbVersion(int subId) {
8273 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 final Phone phone = getPhone(subId);
8278 if (phone == null) {
8279 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8280 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8281 }
8282 return phone.getEmergencyNumberDbVersion();
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
8287
8288 @Override
8289 public void notifyOtaEmergencyNumberDbInstalled() {
8290 enforceModifyPermission();
8291
8292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 for (Phone phone: PhoneFactory.getPhones()) {
8295 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8296 if (tracker != null) {
8297 tracker.updateOtaEmergencyNumberDatabase();
8298 }
8299 }
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
8305 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008306 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008307 enforceActiveEmergencySessionPermission();
8308
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 for (Phone phone: PhoneFactory.getPhones()) {
8312 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8313 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008314 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8315 }
8316 }
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
8321
8322 @Override
8323 public void resetOtaEmergencyNumberDbFilePath() {
8324 enforceActiveEmergencySessionPermission();
8325
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 for (Phone phone: PhoneFactory.getPhones()) {
8329 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8330 if (tracker != null) {
8331 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008332 }
8333 }
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
8337 }
8338
8339 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008340 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8341 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8342 Phone phone = getPhone(subId);
8343 if (phone == null) {
8344 return null;
8345 }
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 UiccProfile profile = UiccController.getInstance()
8349 .getUiccProfileForPhone(phone.getPhoneId());
8350 if (profile != null) {
8351 return profile.getCertsFromCarrierPrivilegeAccessRules();
8352 }
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
8356 return null;
8357 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008358
8359 /**
8360 * Enable or disable a modem stack.
8361 */
8362 @Override
8363 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8364 enforceModifyPermission();
8365
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 Phone phone = PhoneFactory.getPhone(slotIndex);
8369 if (phone == null) {
8370 return false;
8371 } else {
8372 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8373 }
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
8377 }
Michelecea4cf22018-12-21 15:00:11 -08008378
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008379 /**
8380 * Whether a modem stack is enabled or not.
8381 */
8382 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008383 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8384 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008385 Phone phone = PhoneFactory.getPhone(slotIndex);
8386 if (phone == null) return false;
8387
8388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008389 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8390 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008391 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8392 }
8393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008396 try {
8397 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8398 } catch (NoSuchElementException ex) {
8399 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8400 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
8404 }
8405
Michelecea4cf22018-12-21 15:00:11 -08008406 @Override
Michele0ea7d782019-03-19 14:58:42 -07008407 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008408 enforceModifyPermission();
8409
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008413 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008414 .commit();
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
8418 }
8419
8420 @Override
Michele0ea7d782019-03-19 14:58:42 -07008421 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008422 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008423 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008424 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8425 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008426 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008427 }
Michelecea4cf22018-12-21 15:00:11 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
Michele0ea7d782019-03-19 14:58:42 -07008431 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008436
Michele0ea7d782019-03-19 14:58:42 -07008437 @TelephonyManager.IsMultiSimSupportedResult
8438 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008439 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8440 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8441 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008442 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8443 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008444 }
8445 // Check if the hardware supports multisim functionality. If usage of multisim is not
8446 // supported by the modem, indicate that it is restricted.
8447 PhoneCapability staticCapability =
8448 mPhoneConfigurationManager.getStaticPhoneCapability();
8449 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008450 loge("isMultiSimSupportedInternal: no static configuration available");
8451 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008452 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008453 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008454 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8455 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008456 }
8457 // Check if support of multiple SIMs is restricted by carrier
8458 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008459 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008460 }
8461
Michele0ea7d782019-03-19 14:58:42 -07008462 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008463 }
8464
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008465 /**
8466 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008467 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8468 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8469 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008470 * @param numOfSims number of active sims we want to switch to
8471 */
8472 @Override
8473 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008474 if (numOfSims == 1) {
8475 enforceModifyPermission();
8476 } else {
8477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8478 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8479 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008480 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008481
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008482 try {
Michele30b57b22019-03-01 12:01:14 -08008483 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008484 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008485 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8486 return;
8487 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008488 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008494 @Override
8495 public boolean isApplicationOnUicc(int subId, int appType) {
8496 enforceReadPrivilegedPermission("isApplicationOnUicc");
8497 Phone phone = getPhone(subId);
8498 if (phone == null) {
8499 return false;
8500 }
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 UiccCard uiccCard = phone.getUiccCard();
8504 if (uiccCard == null) {
8505 return false;
8506 }
8507 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8508 if (uiccProfile == null) {
8509 return false;
8510 }
8511 if (TelephonyManager.APPTYPE_SIM <= appType
8512 && appType <= TelephonyManager.APPTYPE_ISIM) {
8513 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8514 }
8515 return false;
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008521 /**
chen xub4baa772019-04-03 10:23:41 -07008522 * Get whether making changes to modem configurations will trigger reboot.
8523 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008524 */
8525 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008526 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8527 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008529 mApp, subId, callingPackage, callingFeatureId,
8530 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008531 return false;
8532 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
8538 }
8539 }
8540
Nathan Harold29f5f052019-02-15 13:41:57 -08008541 private void updateModemStateMetrics() {
8542 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8543 // TODO: check the state for each modem if the api is ready.
8544 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8545 }
8546
Pengquan Meng3889a572019-01-23 11:16:29 -08008547 @Override
8548 public int[] getSlotsMapping() {
8549 enforceReadPrivilegedPermission("getSlotsMapping");
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8554 // All logical slots should have a mapping to a physical slot.
8555 int[] logicalSlotsMapping = new int[phoneCount];
8556 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8557 for (int i = 0; i < slotInfos.length; i++) {
8558 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8559 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8560 }
8561 }
8562 return logicalSlotsMapping;
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
8565 }
8566 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008567
8568 /**
8569 * Get the IRadio HAL Version
8570 */
8571 @Override
8572 public int getRadioHalVersion() {
8573 Phone phone = getDefaultPhone();
8574 if (phone == null) return -1;
8575 HalVersion hv = phone.getHalVersion();
8576 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8577 return hv.major * 100 + hv.minor;
8578 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008579
8580 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008581 * Get the current calling package name.
8582 * @return the current calling package name
8583 */
8584 @Override
8585 public String getCurrentPackageName() {
8586 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8587 }
8588
8589 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008590 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8591 * corresponding network requests on a subId.
8592 *
8593 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008594 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008595 * 2) APN is un-metered for this subscription, or
8596 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008597 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008598 *
8599 * @return whether data is allowed for a apn type.
8600 *
8601 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008602 */
8603 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008604 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008605 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8606 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008607
8608 // Now that all security checks passes, perform the operation as ourselves.
8609 final long identity = Binder.clearCallingIdentity();
8610 try {
8611 Phone phone = getPhone(subId);
8612 if (phone == null) return false;
8613
Jack Yu41407ee2019-05-13 16:54:09 -07008614 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008615 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
8621 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008622 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008623 enforceReadPrivilegedPermission("isApnMetered");
8624
8625 // Now that all security checks passes, perform the operation as ourselves.
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 Phone phone = getPhone(subId);
8629 if (phone == null) return true; // By default return true.
8630
Jack Yu41407ee2019-05-13 16:54:09 -07008631 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008636
8637 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008638 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8639 int subscriptionId, IBooleanConsumer resultCallback) {
8640 enforceModifyPermission();
8641 long token = Binder.clearCallingIdentity();
8642 try {
8643 Phone phone = getPhone(subscriptionId);
8644 if (phone == null) {
8645 try {
8646 if (resultCallback != null) {
8647 resultCallback.accept(false);
8648 }
8649 } catch (RemoteException e) {
8650 // ignore
8651 }
8652 return;
8653 }
8654 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8655 Pair.create(specifiers, (x) -> {
8656 try {
8657 if (resultCallback != null) {
8658 resultCallback.accept(x);
8659 }
8660 } catch (RemoteException e) {
8661 // ignore
8662 }
8663 });
8664 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8665 } finally {
8666 Binder.restoreCallingIdentity(token);
8667 }
8668 }
8669
8670 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008671 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008672 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008673 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8674 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8675 if (iccRecords == null) {
8676 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8677 return false;
8678 }
8679 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8680 }
8681
8682 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008683 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8684 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008685 if (callingPackage == null) {
8686 callingPackage = getCurrentPackageName();
8687 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008688 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8689 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008690 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8691 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008692 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8693 }
8694 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8695 Intent intent = new Intent();
8696 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8697 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8698 // Bring up choose default SMS subscription dialog right now
8699 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8700 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8701 mApp.startActivity(intent);
8702 }
chen xud5ca2d52019-05-28 15:20:57 -07008703
8704 @Override
8705 public String getMmsUAProfUrl(int subId) {
8706 //TODO investigate if this API should require proper permission check in R b/133791609
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008709 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8710 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8711 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8712 return carrierUAProfUrl;
8713 }
chen xud5ca2d52019-05-28 15:20:57 -07008714 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8715 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8716 } finally {
8717 Binder.restoreCallingIdentity(identity);
8718 }
8719 }
8720
8721 @Override
8722 public String getMmsUserAgent(int subId) {
8723 //TODO investigate if this API should require proper permission check in R b/133791609
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008726 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8727 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8728 if (!TextUtils.isEmpty(carrierUserAgent)) {
8729 return carrierUserAgent;
8730 }
chen xud5ca2d52019-05-28 15:20:57 -07008731 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8732 .getString(com.android.internal.R.string.config_mms_user_agent);
8733 } finally {
8734 Binder.restoreCallingIdentity(identity);
8735 }
8736 }
Jack Yub07d4972019-05-28 16:12:25 -07008737
8738 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008739 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8740 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8741
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
8744 Phone phone = getPhone(subscriptionId);
8745 if (phone == null) return false;
8746
8747 switch (policy) {
8748 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8749 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8750 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8751 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8752 default:
8753 throw new IllegalArgumentException(policy + " is not a valid policy");
8754 }
8755 } finally {
8756 Binder.restoreCallingIdentity(identity);
8757 }
8758 }
8759
8760 @Override
8761 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8762 boolean enabled) {
8763 enforceModifyPermission();
8764
8765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 Phone phone = getPhone(subscriptionId);
8768 if (phone == null) return;
8769
8770 switch (policy) {
8771 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8772 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8773 break;
8774 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8775 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8776 break;
8777 default:
8778 throw new IllegalArgumentException(policy + " is not a valid policy");
8779 }
8780 } finally {
8781 Binder.restoreCallingIdentity(identity);
8782 }
8783 }
8784
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008785 /**
Hall Liub48cf452020-09-25 11:13:49 -07008786 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008787 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8788 * otherwise.
8789 */
8790 @Override
8791 public void setCepEnabled(boolean isCepEnabled) {
8792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8793
8794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8797 for (Phone phone : PhoneFactory.getPhones()) {
8798 Phone defaultPhone = phone.getImsPhone();
8799 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8800 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8801 ImsPhoneCallTracker imsPhoneCallTracker =
8802 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8803 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8804 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8805 + imsPhone.getMsisdn());
8806 }
8807 }
8808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
allenwtsu46dcc572020-01-08 18:24:03 +08008812
8813 /**
8814 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8815 *
8816 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8817 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8818 * before being read.
8819 */
8820 @Override
8821 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8822 isCompressed) {
8823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8824 mApp, subId, "notifyRcsAutoConfigurationReceived");
8825 try {
8826 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8827 if (configBinder == null) {
8828 Rlog.e(LOG_TAG, "null result for getImsConfig");
8829 } else {
8830 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8831 }
8832 } catch (RemoteException e) {
8833 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8834 }
8835 }
zoey chenf95ca592019-12-30 16:11:23 +08008836
8837 @Override
8838 public boolean isIccLockEnabled(int subId) {
8839 enforceReadPrivilegedPermission("isIccLockEnabled");
8840
8841 // Now that all security checks passes, perform the operation as ourselves.
8842 final long identity = Binder.clearCallingIdentity();
8843 try {
8844 Phone phone = getPhone(subId);
8845 if (phone != null && phone.getIccCard() != null) {
8846 return phone.getIccCard().getIccLockEnabled();
8847 } else {
8848 return false;
8849 }
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
8852 }
8853 }
8854
8855 /**
zoey chene02881a2019-12-30 16:11:23 +08008856 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008857 *
zoey chene02881a2019-12-30 16:11:23 +08008858 * @return an integer representing the status of IccLock enabled or disabled in the following
8859 * three cases:
8860 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8861 * successfully.
8862 * - Positive number and zero for remaining password attempts.
8863 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008864 *
8865 */
8866 @Override
8867 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8868 enforceModifyPermission();
8869
8870 Phone phone = getPhone(subId);
8871 if (phone == null) {
8872 return 0;
8873 }
8874 // Now that all security checks passes, perform the operation as ourselves.
8875 final long identity = Binder.clearCallingIdentity();
8876 try {
8877 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8878 new Pair<Boolean, String>(enabled, password), phone, null);
8879 return attemptsRemaining;
8880
8881 } catch (Exception e) {
8882 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8883 } finally {
8884 Binder.restoreCallingIdentity(identity);
8885 }
8886 return 0;
8887 }
8888
8889 /**
8890 * Change the ICC password used in ICC pin lock.
8891 *
zoey chene02881a2019-12-30 16:11:23 +08008892 * @return an integer representing the status of IccLock changed in the following three cases:
8893 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8894 * - Positive number and zero for remaining password attempts.
8895 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008896 *
8897 */
8898 @Override
8899 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8900 enforceModifyPermission();
8901
8902 Phone phone = getPhone(subId);
8903 if (phone == null) {
8904 return 0;
8905 }
8906 // Now that all security checks passes, perform the operation as ourselves.
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
8909 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8910 new Pair<String, String>(oldPassword, newPassword), phone, null);
8911 return attemptsRemaining;
8912
8913 } catch (Exception e) {
8914 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 return 0;
8919 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008920
Peter Wangdafb9ac2020-01-15 14:13:38 -08008921 /**
8922 * Request for receiving user activity notification
8923 */
8924 @Override
8925 public void requestUserActivityNotification() {
8926 if (!mNotifyUserActivity.get()
8927 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8928 mNotifyUserActivity.set(true);
8929 }
8930 }
8931
8932 /**
8933 * Called when userActivity is signalled in the power manager.
8934 * This is safe to call from any thread, with any window manager locks held or not.
8935 */
8936 @Override
8937 public void userActivity() {
8938 // ***************************************
8939 // * Inherited from PhoneWindowManager *
8940 // ***************************************
8941 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8942 // WITH ITS LOCKS HELD.
8943 //
8944 // This code must be VERY careful about the locks
8945 // it acquires.
8946 // In fact, the current code acquires way too many,
8947 // and probably has lurking deadlocks.
8948
8949 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8950 throw new SecurityException("Only the OS may call notifyUserActivity()");
8951 }
8952
8953 if (mNotifyUserActivity.getAndSet(false)) {
8954 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8955 USER_ACTIVITY_NOTIFICATION_DELAY);
8956 }
8957 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008958
Malcolm Chen884180b2020-04-13 11:59:40 -07008959 @Override
8960 public boolean canConnectTo5GInDsdsMode() {
8961 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8962 }
Jack Yud10cdd42020-09-28 20:28:01 -07008963
8964 @Override
8965 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8966 String callingFeatureId) {
8967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8968 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8969 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8970 }
8971
8972 Phone phone = getPhone(subId);
8973 if (phone == null) {
8974 throw new RuntimeException("phone is not available");
8975 }
8976 // Now that all security checks passes, perform the operation as ourselves.
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 return phone.getEquivalentHomePlmns();
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008984}