blob: be062cc0bf85ad713a77b1b95df76f34d53527b4 [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 Ebinger05f52c22019-12-05 13:03:21 -08005256 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005257 *
5258 * @param slotId The slot that the ImsService is associated with.
5259 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5260 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005261 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005262 * @return the package name of the ImsService configuration.
5263 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005264 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5265 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005266 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005267 TelephonyPermissions
5268 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5269 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5270 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 final long identity = Binder.clearCallingIdentity();
5273 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005274 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005275 // may happen if the device does not support IMS.
5276 return "";
5277 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005278 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005279 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5280 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005284 }
5285
Brad Ebinger77b832e2019-10-17 17:03:22 -07005286 /**
5287 * Get the MmTelFeature state associated with the requested subscription id.
5288 * @param subId The subscription that the MmTelFeature is associated with.
5289 * @param callback A callback with an integer containing the
5290 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5291 */
5292 @Override
5293 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5294 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5295 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5297 "IMS not available on device.");
5298 }
5299 final long token = Binder.clearCallingIdentity();
5300 try {
5301 int slotId = getSlotIndex(subId);
5302 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5303 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5304 + subId + "'");
5305 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5306 }
5307 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5308 try {
5309 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5310 } catch (RemoteException e) {
5311 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5312 + "Ignore");
5313 }
5314 });
5315 } finally {
5316 Binder.restoreCallingIdentity(token);
5317 }
5318 }
5319
Wink Saville36469e72014-06-11 15:17:00 -07005320 public void setImsRegistrationState(boolean registered) {
5321 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322
5323 final long identity = Binder.clearCallingIdentity();
5324 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005325 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Wink Saville36469e72014-06-11 15:17:00 -07005329 }
5330
5331 /**
Stuart Scott54788802015-03-30 13:18:01 -07005332 * Set the network selection mode to automatic.
5333 *
5334 */
5335 @Override
5336 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5338 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339
5340 final long identity = Binder.clearCallingIdentity();
5341 try {
shilufc958392020-01-20 11:36:01 -08005342 if (!isActiveSubscription(subId)) {
5343 return;
5344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5346 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
Stuart Scott54788802015-03-30 13:18:01 -07005350 }
5351
Jack Yud10cdd42020-09-28 20:28:01 -07005352 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005353 * Ask the radio to connect to the input network and change selection mode to manual.
5354 *
5355 * @param subId the id of the subscription.
5356 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5357 * the operator to attach to.
5358 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5359 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5360 * normal network selection next time.
5361 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005362 */
5363 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005364 public boolean setNetworkSelectionModeManual(
5365 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5367 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005368
5369 if (!isActiveSubscription(subId)) {
5370 return false;
5371 }
5372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005375 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005377 if (DBG) {
5378 log("setNetworkSelectionModeManual: subId: " + subId
5379 + " operator: " + operatorInfo);
5380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005385 }
shilu84f6e8b2019-12-19 13:58:01 -08005386 /**
5387 * Get the manual network selection
5388 *
5389 * @param subId the id of the subscription.
5390 *
5391 * @return the previously saved user selected PLMN
5392 */
5393 @Override
5394 public String getManualNetworkSelectionPlmn(int subId) {
5395 TelephonyPermissions
5396 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5397 mApp, subId, "getManualNetworkSelectionPlmn");
5398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 if (!isActiveSubscription(subId)) {
5402 return "";
5403 }
5404
5405 final Phone phone = getPhone(subId);
5406 if (phone == null) {
5407 return "";
5408 }
5409 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5410 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5411 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
5415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005416
5417 /**
5418 * Scans for available networks.
5419 */
5420 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005421 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5422 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5424 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005425 LocationAccessPolicy.LocationPermissionResult locationResult =
5426 LocationAccessPolicy.checkLocationPermission(mApp,
5427 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5428 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005429 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005430 .setCallingPid(Binder.getCallingPid())
5431 .setCallingUid(Binder.getCallingUid())
5432 .setMethod("getCellNetworkScanResults")
5433 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5434 .build());
5435 switch (locationResult) {
5436 case DENIED_HARD:
5437 throw new SecurityException("Not allowed to access scan results -- location");
5438 case DENIED_SOFT:
5439 return null;
5440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
Pengquan Menga1bb6272018-09-06 09:59:22 -07005442 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 try {
5444 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005445 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005450 }
5451
5452 /**
sqian80370722020-01-29 15:02:51 -08005453 * Get the call forwarding info, given the call forwarding reason.
5454 */
5455 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005456 public void getCallForwarding(int subId, int callForwardingReason,
5457 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005458 enforceReadPrivilegedPermission("getCallForwarding");
5459 long identity = Binder.clearCallingIdentity();
5460 try {
5461 if (DBG) {
5462 log("getCallForwarding: subId " + subId
5463 + " callForwardingReason" + callForwardingReason);
5464 }
Hall Liua1acea22020-09-18 19:04:59 -07005465
5466 Phone phone = getPhone(subId);
5467 if (phone == null) {
5468 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005469 callback.onError(
5470 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005471 } catch (RemoteException e) {
5472 // ignore
5473 }
5474 return;
5475 }
5476
5477 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5478 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5479 @Override
5480 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5481 try {
5482 callback.onCallForwardingInfoAvailable(info);
5483 } catch (RemoteException e) {
5484 // ignore
5485 }
5486 }
5487
5488 @Override
5489 public void onError(int error) {
5490 try {
5491 callback.onError(error);
5492 } catch (RemoteException e) {
5493 // ignore
5494 }
5495 }
5496 });
5497 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500 }
5501 }
5502
5503 /**
5504 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5505 * reason, the number to forward, and the timeout before the forwarding is attempted.
5506 */
5507 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005508 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5509 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005510 enforceModifyPermission();
5511 long identity = Binder.clearCallingIdentity();
5512 try {
5513 if (DBG) {
5514 log("setCallForwarding: subId " + subId
5515 + " callForwardingInfo" + callForwardingInfo);
5516 }
Hall Liua1acea22020-09-18 19:04:59 -07005517
5518 Phone phone = getPhone(subId);
5519 if (phone == null) {
5520 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005521 callback.accept(
5522 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005523 } catch (RemoteException e) {
5524 // ignore
5525 }
5526 return;
5527 }
5528
5529 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5530 FunctionalUtils.ignoreRemoteException(callback::accept));
5531
5532 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
5536 }
5537
5538 /**
Hall Liua1acea22020-09-18 19:04:59 -07005539 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005540 */
5541 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005542 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005543 enforceReadPrivilegedPermission("getCallForwarding");
5544 long identity = Binder.clearCallingIdentity();
5545 try {
Hall Liua1acea22020-09-18 19:04:59 -07005546
5547 Phone phone = getPhone(subId);
5548 if (phone == null) {
5549 try {
5550 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5551 } catch (RemoteException e) {
5552 // ignore
5553 }
5554 return;
5555 }
5556
5557 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5558
sqian80370722020-01-29 15:02:51 -08005559 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005560 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
5564 }
5565
5566 /**
Hall Liua1acea22020-09-18 19:04:59 -07005567 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005568 */
5569 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005570 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005571 enforceModifyPermission();
5572 long identity = Binder.clearCallingIdentity();
5573 try {
Hall Liua1acea22020-09-18 19:04:59 -07005574 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5575
5576 Phone phone = getPhone(subId);
5577 if (phone == null) {
5578 try {
5579 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5580 } catch (RemoteException e) {
5581 // ignore
5582 }
5583 return;
5584 }
5585
5586 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5587 FunctionalUtils.ignoreRemoteException(callback::accept));
5588
5589 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
5593 }
5594
5595 /**
yinxub1bed742017-04-17 11:45:04 -07005596 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005597 *
yinxub1bed742017-04-17 11:45:04 -07005598 * @param subId id of the subscription
5599 * @param request contains the radio access networks with bands/channels to scan
5600 * @param messenger callback messenger for scan results or errors
5601 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005602 * @return the id of the requested scan which can be used to stop the scan.
5603 */
5604 @Override
5605 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005606 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005609 LocationAccessPolicy.LocationPermissionResult locationResult =
5610 LocationAccessPolicy.checkLocationPermission(mApp,
5611 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5612 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005613 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005614 .setCallingPid(Binder.getCallingPid())
5615 .setCallingUid(Binder.getCallingUid())
5616 .setMethod("requestNetworkScan")
5617 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5618 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005619 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005620 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5621 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005622 if (e != null) {
5623 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5624 throw e;
5625 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005626 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005627 return TelephonyScanManager.INVALID_SCAN_ID;
5628 }
5629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 }
Hall Liu912dfd32019-04-25 14:02:26 -07005631 int callingUid = Binder.getCallingUid();
5632 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 return mNetworkScanRequestTracker.startNetworkScan(
5636 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005637 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
yinxu504e1392017-04-12 16:03:22 -07005641 }
5642
Hall Liub2ac8ef2019-02-28 15:56:23 -08005643 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005644 NetworkScanRequest request, int subId, String callingPackage) {
5645 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005646 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5647 boolean hasNetworkScanPermission =
5648 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5649 == PERMISSION_GRANTED;
5650
5651 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5652 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5653 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005654 }
5655
5656 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5657 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005658 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5659 return new SecurityException("Specific channels must not be"
5660 + " scanned without location access.");
5661 }
5662 }
5663 }
5664
Hall Liub2ac8ef2019-02-28 15:56:23 -08005665 return null;
5666 }
5667
yinxu504e1392017-04-12 16:03:22 -07005668 /**
5669 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005670 *
5671 * @param subId id of the subscription
5672 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005673 */
5674 @Override
5675 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5677 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
Hall Liu912dfd32019-04-25 14:02:26 -07005679 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005682 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
yinxu504e1392017-04-12 16:03:22 -07005686 }
5687
5688 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005689 * Get the calculated preferred network type.
5690 * Used for debugging incorrect network type.
5691 *
5692 * @return the preferred network type, defined in RILConstants.java.
5693 */
5694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005695 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005696 final Phone defaultPhone = getDefaultPhone();
5697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005698 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005699 return RILConstants.PREFERRED_NETWORK_MODE;
5700 }
5701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
Junda Liu84d15a22014-07-02 11:21:04 -07005709 }
5710
5711 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005712 * Get the preferred network type.
5713 * Used for device configuration by some CDMA operators.
5714 *
5715 * @return the preferred network type, defined in RILConstants.java.
5716 */
5717 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005718 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005719 TelephonyPermissions
5720 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5721 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 if (DBG) log("getPreferredNetworkType");
5726 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5727 int networkType = (result != null ? result[0] : -1);
5728 if (DBG) log("getPreferredNetworkType: " + networkType);
5729 return networkType;
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005733 }
5734
5735 /**
5736 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005737 *
5738 * @param networkType the preferred network type, defined in RILConstants.java.
5739 * @return true on success; false on any failure.
5740 */
5741 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005742 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5744 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005748 Settings.Global.putInt(mApp.getContentResolver(),
5749 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005750
5751 Boolean success = (Boolean) sendRequest(
5752 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5753 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5754 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005757 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005758 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005759
5760 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005761 * Get the allowed network types that store in the telephony provider.
5762 *
5763 * @param subId the id of the subscription.
5764 * @return allowedNetworkTypes the allowed network types.
5765 */
5766 @Override
5767 public long getAllowedNetworkTypes(int subId) {
5768 TelephonyPermissions
5769 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5770 mApp, subId, "getAllowedNetworkTypes");
5771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 return SubscriptionManager.getLongSubscriptionProperty(
5775 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
5781 /**
5782 * Set the allowed network types.
5783 *
5784 * @param subId the id of the subscription.
5785 * @param allowedNetworkTypes the allowed network types.
5786 * @return true on success; false on any failure.
5787 */
5788 @Override
5789 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5791 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005792
calvinpan089c2a62020-03-12 14:17:55 +08005793 SubscriptionManager.setSubscriptionProperty(subId,
5794 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5795 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005796
calvinpan089c2a62020-03-12 14:17:55 +08005797 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5798 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5799 RILConstants.PREFERRED_NETWORK_MODE);
5800 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005801 }
5802
5803 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005804 * Get the allowed network types for certain reason.
5805 *
5806 * @param subId the id of the subscription.
5807 * @param reason the reason the allowed network type change is taking place
5808 * @return the allowed network types.
5809 */
5810 @Override
5811 public long getAllowedNetworkTypesForReason(int subId,
5812 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5813 TelephonyPermissions
5814 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5815 mApp, subId, "getAllowedNetworkTypesForReason");
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
5822 }
5823
5824 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005825 * Enable/Disable E-UTRA-NR Dual Connectivity
5826 * @param subId subscription id of the sim card
5827 * @param nrDualConnectivityState expected NR dual connectivity state
5828 * This can be passed following states
5829 * <ol>
5830 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5831 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5832 * <li>Disable NR dual connectivity and force secondary cell to be released
5833 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5834 * </ol>
5835 * @return operation result.
5836 */
5837 @Override
5838 public int setNrDualConnectivityState(int subId,
5839 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5841 mApp, subId, "enableNRDualConnectivity");
5842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5846 nrDualConnectivityState, subId,
5847 workSource);
5848 if (DBG) log("enableNRDualConnectivity result: " + result);
5849 return result;
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
5855 /**
5856 * Is E-UTRA-NR Dual Connectivity enabled
5857 * @return true if dual connectivity is enabled else false
5858 */
5859 @Override
5860 public boolean isNrDualConnectivityEnabled(int subId) {
5861 TelephonyPermissions
5862 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5863 mApp, subId, "isNRDualConnectivityEnabled");
5864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5868 null, subId, workSource);
5869 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5870 return isEnabled;
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
5874 }
5875
5876 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07005877 * get carrier bandwidth per primary and secondary carrier
5878 * @param subId subscription id of the sim card
5879 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5880 */
5881 @Override
5882 public CarrierBandwidth getCarrierBandwidth(int subId) {
5883 TelephonyPermissions
5884 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5885 mApp, subId, "isNRDualConnectivityEnabled");
5886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 CarrierBandwidth carrierBandwidth =
5890 getPhoneFromSubId(subId).getCarrierBandwidth();
5891 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5892 return carrierBandwidth;
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
5896 }
5897
5898 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005899 * Get the effective allowed network types on the device.
5900 * This API will return an intersection of allowed network types for all reasons,
5901 * including the configuration done through setAllowedNetworkTypes
5902 *
5903 * @param subId the id of the subscription.
5904 * @return the allowed network types
5905 */
5906 @Override
5907 public long getEffectiveAllowedNetworkTypes(int subId) {
5908 TelephonyPermissions
5909 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5910 mApp, subId, "getEffectiveAllowedNetworkTypes");
5911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
5917 }
5918
5919 /**
5920 * Set the allowed network types of the device and
5921 * provide the reason triggering the allowed network change.
5922 *
5923 * @param subId the id of the subscription.
5924 * @param reason the reason the allowed network type change is taking place
5925 * @param allowedNetworkTypes the allowed network types.
5926 * @return true on success; false on any failure.
5927 */
5928 @Override
5929 public boolean setAllowedNetworkTypesForReason(int subId,
5930 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5932 mApp, subId, "setAllowedNetworkTypesForReason");
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5936 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5937 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5938 RILConstants.PREFERRED_NETWORK_MODE);
5939 return setPreferredNetworkType(subId, preferredNetworkMode);
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
5943 }
5944
5945 /**
Miaoa84611c2019-03-15 09:21:10 +08005946 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005947 *
Miaoa84611c2019-03-15 09:21:10 +08005948 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005949 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005950 * @hide
5951 */
5952 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005953 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 try {
Miaoa84611c2019-03-15 09:21:10 +08005958 if (phone != null) {
5959 return phone.hasMatchedTetherApnSetting();
5960 } else {
5961 return false;
5962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005965 }
Junda Liu475951f2014-11-07 16:45:03 -08005966 }
5967
5968 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005969 * Enable or disable always reporting signal strength changes from radio.
5970 *
5971 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5972 */
5973 @Override
5974 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5975 enforceModifyPermission();
5976 enforceSystemCaller();
5977
5978 final long identity = Binder.clearCallingIdentity();
5979 final Phone phone = getPhone(subId);
5980 try {
5981 if (phone != null) {
5982 if (DBG) {
5983 log("setAlwaysReportSignalStrength: subId=" + subId
5984 + " isEnable=" + isEnable);
5985 }
5986 phone.setAlwaysReportSignalStrength(isEnable);
5987 } else {
5988 loge("setAlwaysReportSignalStrength: no phone found for subId="
5989 + subId);
5990 }
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
5994 }
5995
5996 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005997 * Get the user enabled state of Mobile Data.
5998 *
5999 * TODO: remove and use isUserDataEnabled.
6000 * This can't be removed now because some vendor codes
6001 * calls through ITelephony directly while they should
6002 * use TelephonyManager.
6003 *
6004 * @return true on enabled
6005 */
6006 @Override
6007 public boolean getDataEnabled(int subId) {
6008 return isUserDataEnabled(subId);
6009 }
6010
6011 /**
6012 * Get whether mobile data is enabled per user setting.
6013 *
6014 * There are other factors deciding whether mobile data is actually enabled, but they are
6015 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006016 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006017 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006018 *
6019 * @return {@code true} if data is enabled else {@code false}
6020 */
6021 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006022 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006023 try {
6024 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6025 null);
6026 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6028 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
6033 int phoneId = mSubscriptionController.getPhoneId(subId);
6034 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6035 Phone phone = PhoneFactory.getPhone(phoneId);
6036 if (phone != null) {
6037 boolean retVal = phone.isUserDataEnabled();
6038 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6039 return retVal;
6040 } else {
6041 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6042 return false;
6043 }
6044 } finally {
6045 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006046 }
6047 }
6048
6049 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006050 * Checks if the device is capable of mobile data by considering whether whether the
6051 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6052 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006053 *
Shuo Qian985d1232020-01-08 14:30:06 -08006054 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006055 */
6056 @Override
6057 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006058 try {
6059 try {
6060 mApp.enforceCallingOrSelfPermission(
6061 android.Manifest.permission.ACCESS_NETWORK_STATE,
6062 null);
6063 } catch (Exception e) {
6064 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6065 "isDataEnabled");
6066 }
6067 } catch (Exception e) {
6068 enforceReadPrivilegedPermission("isDataEnabled");
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 int phoneId = mSubscriptionController.getPhoneId(subId);
6074 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6075 Phone phone = PhoneFactory.getPhone(phoneId);
6076 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006077 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6079 return retVal;
6080 } else {
6081 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6082 return false;
6083 }
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006086 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006087 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006088
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006089 /**
6090 * Check if data is enabled for a specific reason
6091 * @param subId Subscription index
6092 * @param reason the reason the data enable change is taking place
6093 * @return {@code true} if the overall data is enabled; {@code false} if not.
6094 */
6095 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006096 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006097 @TelephonyManager.DataEnabledReason int reason) {
6098 try {
6099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6100 null);
6101 } catch (Exception e) {
6102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006103 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006104 }
6105
6106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 int phoneId = mSubscriptionController.getPhoneId(subId);
6110 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006111 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006112 + " reason=" + reason);
6113 }
6114 Phone phone = PhoneFactory.getPhone(phoneId);
6115 if (phone != null) {
6116 boolean retVal;
6117 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6118 retVal = phone.isUserDataEnabled();
6119 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006120 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006121 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006122 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006123 return retVal;
6124 } else {
6125 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006126 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006127 + subId + " retVal=false");
6128 }
6129 return false;
6130 }
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
6134 }
6135
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006136 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006137 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006138 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6139 // Skip the check if it's one of these special uids
6140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6141 }
6142
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006143 //load access rules from carrier configs, and check those as well: b/139133814
6144 SubscriptionController subController = SubscriptionController.getInstance();
6145 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6146 || subController == null) return privilegeFromSim;
6147
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006148 PackageManager pkgMgr = phone.getContext().getPackageManager();
6149 String[] packages = pkgMgr.getPackagesForUid(uid);
6150
6151 final long identity = Binder.clearCallingIdentity();
6152 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006153 int subId = phone.getSubId();
6154 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6155 // A test override is in place for the privileges for this subId, so don't try to
6156 // read the subscription privileges.
6157 return privilegeFromSim;
6158 }
6159 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006160 SubscriptionManager subManager = (SubscriptionManager)
6161 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6162 for (String pkg : packages) {
6163 if (subManager.canManageSubscription(subInfo, pkg)) {
6164 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6165 }
6166 }
6167 return privilegeFromSim;
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
6171 }
6172
6173 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6174 String pkgName) {
6175 //load access rules from carrier configs, and check those as well: b/139133814
6176 SubscriptionController subController = SubscriptionController.getInstance();
6177 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6178 || subController == null) return privilegeFromSim;
6179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006182 int subId = phone.getSubId();
6183 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6184 // A test override is in place for the privileges for this subId, so don't try to
6185 // read the subscription privileges.
6186 return privilegeFromSim;
6187 }
6188 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006189 SubscriptionManager subManager = (SubscriptionManager)
6190 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6191 return subManager.canManageSubscription(subInfo, pkgName)
6192 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
6196 }
6197
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006198 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006199 public int getCarrierPrivilegeStatus(int subId) {
6200 final Phone phone = getPhone(subId);
6201 if (phone == null) {
6202 loge("getCarrierPrivilegeStatus: Invalid subId");
6203 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6204 }
6205 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006206 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006207 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6209 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006210
6211 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6212 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006213 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006214 }
Junda Liu29340342014-07-10 15:23:27 -07006215
6216 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006217 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006218 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006219 final Phone phone = getPhone(subId);
6220 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006221 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6223 }
6224 UiccProfile profile =
6225 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6226 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006227 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006228 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6229 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006230 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006231 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006232 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006233 }
6234
6235 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006236 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6237 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006238 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006239 }
6240
6241 int phoneId = SubscriptionManager.getPhoneId(subId);
6242 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006243 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006244 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006245 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6246 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006247 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6248 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6249 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006250 }
6251
6252 @Override
6253 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006254 if (TextUtils.isEmpty(pkgName))
6255 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006256 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6257 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6258 UiccCard card = UiccController.getInstance().getUiccCard(i);
6259 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006260 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006261 continue;
6262 }
6263
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006264 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6265 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6266 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006267 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6268 break;
6269 }
6270 }
6271
6272 return result;
Junda Liu29340342014-07-10 15:23:27 -07006273 }
Derek Tan89e89d42014-07-08 17:00:10 -07006274
6275 @Override
Junda Liue64de782015-04-16 17:19:16 -07006276 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6277 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6278 loge("phoneId " + phoneId + " is not valid.");
6279 return null;
6280 }
6281 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006282 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006283 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006284 return null ;
6285 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006286 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006287 }
6288
Amith Yamasani6e118872016-02-19 12:53:51 -08006289 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006290 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006291 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006292 List<String> privilegedPackages = new ArrayList<>();
6293 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006294 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6295 // has UICC in that slot.
6296 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006297 if (card.hasCarrierPrivilegeRules()) {
6298 if (packages == null) {
6299 // Only check packages in user 0 for now
6300 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006301 PackageManager.MATCH_DISABLED_COMPONENTS
6302 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006303 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006304 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006305 }
6306 for (int p = packages.size() - 1; p >= 0; p--) {
6307 PackageInfo pkgInfo = packages.get(p);
6308 if (pkgInfo != null && pkgInfo.packageName != null
6309 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006310 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006311 privilegedPackages.add(pkgInfo.packageName);
6312 }
6313 }
6314 }
6315 }
6316 return privilegedPackages;
6317 }
6318
chen xuf7e9fe82019-05-09 19:31:02 -07006319 @Override
6320 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006321 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6322
6323 final long identity = Binder.clearCallingIdentity();
6324
chen xuf7e9fe82019-05-09 19:31:02 -07006325 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006326 try {
6327 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6328 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6329 }
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006332 }
6333 return privilegedPackages;
6334 }
6335
Wink Savilleb564aae2014-10-23 10:18:09 -07006336 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006337 final Phone phone = getPhone(subId);
6338 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006339 if (card == null) {
6340 loge("getIccId: No UICC");
6341 return null;
6342 }
6343 String iccId = card.getIccId();
6344 if (TextUtils.isEmpty(iccId)) {
6345 loge("getIccId: ICC ID is null or empty.");
6346 return null;
6347 }
6348 return iccId;
6349 }
6350
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006351 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006352 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6353 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006354 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 final String iccId = getIccId(subId);
6360 final Phone phone = getPhone(subId);
6361 if (phone == null) {
6362 return false;
6363 }
6364 final String subscriberId = phone.getSubscriberId();
6365
6366 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006367 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 + subscriberId + " to " + number);
6369 }
6370
6371 if (TextUtils.isEmpty(iccId)) {
6372 return false;
6373 }
6374
6375 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6376
6377 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6378 if (alphaTag == null) {
6379 editor.remove(alphaTagPrefKey);
6380 } else {
6381 editor.putString(alphaTagPrefKey, alphaTag);
6382 }
6383
6384 // Record both the line number and IMSI for this ICCID, since we need to
6385 // track all merged IMSIs based on line number
6386 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6387 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6388 if (number == null) {
6389 editor.remove(numberPrefKey);
6390 editor.remove(subscriberPrefKey);
6391 } else {
6392 editor.putString(numberPrefKey, number);
6393 editor.putString(subscriberPrefKey, subscriberId);
6394 }
6395
6396 editor.commit();
6397 return true;
6398 } finally {
6399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006400 }
Derek Tan7226c842014-07-02 17:42:23 -07006401 }
6402
6403 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006404 public String getLine1NumberForDisplay(int subId, String callingPackage,
6405 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006406 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006408 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006409 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006410 return null;
6411 }
Derek Tan97ebb422014-09-05 16:55:38 -07006412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 String iccId = getIccId(subId);
6416 if (iccId != null) {
6417 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6418 if (DBG_MERGE) {
6419 log("getLine1NumberForDisplay returning "
6420 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6421 }
6422 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6425 return null;
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006428 }
Derek Tan7226c842014-07-02 17:42:23 -07006429 }
6430
6431 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006432 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6433 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006435 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006436 return null;
6437 }
Derek Tan97ebb422014-09-05 16:55:38 -07006438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 String iccId = getIccId(subId);
6442 if (iccId != null) {
6443 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6444 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6445 }
6446 return null;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006449 }
Derek Tan7226c842014-07-02 17:42:23 -07006450 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006451
6452 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006453 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6454 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006455 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6456 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006458 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006459 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006460 return null;
6461 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006462
Jordan Liub49b04b2019-05-06 14:45:15 -07006463 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6464 // the process, where TelephonyManager was instantiated.
6465 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006466 final long identity = Binder.clearCallingIdentity();
6467 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006468 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 final TelephonyManager tele = TelephonyManager.from(context);
6470 final SubscriptionManager sub = SubscriptionManager.from(context);
6471
6472 // Figure out what subscribers are currently active
6473 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474
Jordan Liub49b04b2019-05-06 14:45:15 -07006475 // Only consider subs which match the current subId
6476 // This logic can be simplified. See b/131189269 for progress.
6477 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006478 activeSubscriberIds.add(tele.getSubscriberId(subId));
6479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480
6481 // First pass, find a number override for an active subscriber
6482 String mergeNumber = null;
6483 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6484 for (String key : prefs.keySet()) {
6485 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6486 final String subscriberId = (String) prefs.get(key);
6487 if (activeSubscriberIds.contains(subscriberId)) {
6488 final String iccId = key.substring(
6489 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6490 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6491 mergeNumber = (String) prefs.get(numberKey);
6492 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006493 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 + " for active subscriber " + subscriberId);
6495 }
6496 if (!TextUtils.isEmpty(mergeNumber)) {
6497 break;
6498 }
6499 }
6500 }
6501 }
6502
6503 // Shortcut when no active merged subscribers
6504 if (TextUtils.isEmpty(mergeNumber)) {
6505 return null;
6506 }
6507
6508 // Second pass, find all subscribers under that line override
6509 final ArraySet<String> result = new ArraySet<>();
6510 for (String key : prefs.keySet()) {
6511 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6512 final String number = (String) prefs.get(key);
6513 if (mergeNumber.equals(number)) {
6514 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6515 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6516 final String subscriberId = (String) prefs.get(subscriberKey);
6517 if (!TextUtils.isEmpty(subscriberId)) {
6518 result.add(subscriberId);
6519 }
6520 }
6521 }
6522 }
6523
6524 final String[] resultArray = result.toArray(new String[result.size()]);
6525 Arrays.sort(resultArray);
6526 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006527 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6529 }
6530 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006533 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006534 }
6535
6536 @Override
zoey chen38003472019-12-13 17:16:31 +08006537 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6538 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006539
6540 final long identity = Binder.clearCallingIdentity();
6541 try {
6542 final TelephonyManager telephonyManager = mApp.getSystemService(
6543 TelephonyManager.class);
6544 String subscriberId = telephonyManager.getSubscriberId(subId);
6545 if (subscriberId == null) {
6546 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006547 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006548 + subId);
6549 }
6550 return null;
6551 }
6552
6553 final SubscriptionInfo info = SubscriptionController.getInstance()
6554 .getSubscriptionInfo(subId);
6555 final ParcelUuid groupUuid = info.getGroupUuid();
6556 // If it doesn't belong to any group, return just subscriberId of itself.
6557 if (groupUuid == null) {
6558 return new String[]{subscriberId};
6559 }
6560
6561 // Get all subscriberIds from the group.
6562 final List<String> mergedSubscriberIds = new ArrayList<>();
6563 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006564 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006565 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006566 for (SubscriptionInfo subInfo : groupInfos) {
6567 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6568 if (subscriberId != null) {
6569 mergedSubscriberIds.add(subscriberId);
6570 }
6571 }
6572
6573 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576
6577 }
6578 }
6579
6580 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006581 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006582 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006583 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
6587 final Phone phone = getPhone(subId);
6588 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006592 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006593
6594 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006595 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006596 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6597 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006598 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6599 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 final Phone phone = getPhone(subId);
6604 if (phone == null) {
6605 return false;
6606 }
6607 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6608 cdmaNonRoamingList);
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006611 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006612 }
6613
6614 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006615 @Deprecated
6616 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6617 enforceModifyPermission();
6618
6619 int returnValue = 0;
6620 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006621 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006622 if(result.exception == null) {
6623 if (result.result != null) {
6624 byte[] responseData = (byte[])(result.result);
6625 if(responseData.length > oemResp.length) {
6626 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6627 responseData.length + "bytes. Buffer Size is " +
6628 oemResp.length + "bytes.");
6629 }
6630 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6631 returnValue = responseData.length;
6632 }
6633 } else {
6634 CommandException ex = (CommandException) result.exception;
6635 returnValue = ex.getCommandError().ordinal();
6636 if(returnValue > 0) returnValue *= -1;
6637 }
6638 } catch (RuntimeException e) {
6639 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6640 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6641 if(returnValue > 0) returnValue *= -1;
6642 }
6643
6644 return returnValue;
6645 }
6646
6647 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006648 public void setRadioCapability(RadioAccessFamily[] rafs) {
6649 try {
6650 ProxyController.getInstance().setRadioCapability(rafs);
6651 } catch (RuntimeException e) {
6652 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6653 }
6654 }
6655
6656 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006657 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006658 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006659 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006660 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006661 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
6664 try {
chen xub97461a2018-10-26 14:17:57 -07006665 TelephonyPermissions
6666 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6667 mApp, phone.getSubId(), "getRadioAccessFamily");
6668 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
chen xub97461a2018-10-26 14:17:57 -07006672 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006673 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006674
6675 @Override
6676 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006677 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006682 ImsManager.getInstance(defaultPhone.getContext(),
6683 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006687 }
6688
6689 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006690 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006691 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6693 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006694 return false;
6695 }
Svet Ganovb320e182015-04-16 12:30:10 -07006696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 // Check the user preference and the system-level IMS setting. Even if the user has
6700 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6701 // In the long run, we may instead need to check if there exists a connection service
6702 // which can support video calling.
6703 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006704 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 return imsManager.isVtEnabledByPlatform()
6706 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6707 && imsManager.isVtEnabledByUser();
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006711 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006712
Andrew Leea1239f22015-03-02 17:44:07 -08006713 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006714 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6715 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006717 mApp, subId, callingPackage, callingFeatureId,
6718 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 return false;
6720 }
6721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 CarrierConfigManager configManager =
6725 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006726 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
Andrew Leea1239f22015-03-02 17:44:07 -08006731 }
6732
6733 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006734 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006736 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 return false;
6738 }
6739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 CarrierConfigManager configManager =
6743 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006744 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
Andrew Leea1239f22015-03-02 17:44:07 -08006749 }
6750
Andrew Lee9431b832015-03-09 18:46:45 -07006751 @Override
6752 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006753 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006754 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006755 }
6756
6757 @Override
6758 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 final long identity = Binder.clearCallingIdentity();
6760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006761 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
Andrew Lee9431b832015-03-09 18:46:45 -07006765 }
6766
Hall Liuf6668912018-10-31 17:05:23 -07006767 /**
6768 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6769 * support for the feature and device firmware support.
6770 *
6771 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6772 */
6773 @Override
6774 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006776 final Phone phone = getPhone(subscriptionId);
6777 if (phone == null) {
6778 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6779 return false;
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006782 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6784 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006785 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 return isCarrierSupported && isDeviceSupported;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
Hall Liu98187582018-01-22 19:15:32 -08006790 }
6791
Hall Liuf6668912018-10-31 17:05:23 -07006792 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006793 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6794 * RTT setting, will return true if the device and carrier both support RTT.
6795 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006796 */
6797 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 final long identity = Binder.clearCallingIdentity();
6799 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006800 boolean isRttSupported = isRttSupported(subscriptionId);
6801 boolean isUserRttSettingOn = Settings.Secure.getInt(
6802 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6803 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6804 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6805 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006809 }
6810
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006811 @Deprecated
6812 @Override
6813 public String getDeviceId(String callingPackage) {
6814 return getDeviceIdWithFeature(callingPackage, null);
6815 }
6816
Sanket Padawe7310cc72015-01-14 09:53:20 -08006817 /**
6818 * Returns the unique device ID of phone, for example, the IMEI for
6819 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6820 *
6821 * <p>Requires Permission:
6822 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6823 */
6824 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006825 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006826 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006827 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006828 return null;
6829 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006830 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006831 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006832 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006833 return null;
6834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835
6836 final long identity = Binder.clearCallingIdentity();
6837 try {
6838 return phone.getDeviceId();
6839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006842 }
6843
Ping Sunc67b7c22016-03-02 19:16:45 +08006844 /**
6845 * {@hide}
6846 * Returns the IMS Registration Status on a particular subid
6847 *
6848 * @param subId
6849 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006850 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006851 Phone phone = getPhone(subId);
6852 if (phone != null) {
6853 return phone.isImsRegistered();
6854 } else {
6855 return false;
6856 }
6857 }
6858
Santos Cordon7a1885b2015-02-03 11:15:19 -08006859 @Override
6860 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006867 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006868
Tyler Gunnf70ed162019-04-03 15:28:53 -07006869 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006870 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006871 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006873 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006874 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6875 }
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006885 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006886 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6887 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 Phone phone = getPhone(subscriptionId);
6891 if (phone == null) {
6892 return null;
6893 }
6894 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006900 /**
6901 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006902 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006903 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = getPhone(subId);
6907 if (phone != null) {
6908 return phone.isWifiCallingEnabled();
6909 } else {
6910 return false;
6911 }
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006914 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006915 }
6916
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006917 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006918 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006919 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006920 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 Phone phone = getPhone(subId);
6924 if (phone != null) {
6925 return phone.isVideoEnabled();
6926 } else {
6927 return false;
6928 }
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006931 }
6932 }
6933
6934 /**
6935 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6936 * defined in {@link ImsRegistrationImplBase}.
6937 */
6938 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 Phone phone = getPhone(subId);
6942 if (phone != null) {
6943 return phone.getImsRegistrationTech();
6944 } else {
6945 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6946 }
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006949 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006950 }
6951
Stuart Scott8eef64f2015-04-08 15:13:54 -07006952 @Override
6953 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006954 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006955 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6956 return;
6957 }
6958
Svet Ganovcc087f82015-05-12 20:35:54 -07006959 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006960
Svet Ganovcc087f82015-05-12 20:35:54 -07006961 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006962 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6963 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006964 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006965 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006966 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006967 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006968 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6969 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006970 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006971 // There has been issues when Sms raw table somehow stores orphan
6972 // fragments. They lead to garbled message when new fragments come
6973 // in and combined with those stale ones. In case this happens again,
6974 // user can reset all network settings which will clean up this table.
6975 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006976 // Clean up IMS settings as well here.
6977 int slotId = getSlotIndex(subId);
6978 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6979 ImsManager.getInstance(mApp, slotId).factoryReset();
6980 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006981
6982 // Erase modem config if erase modem on network setting is enabled.
6983 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6984 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6985 if (configValue != null && Boolean.parseBoolean(configValue)) {
6986 sendEraseModemConfig(getDefaultPhone());
6987 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006990 }
6991 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006992
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006993 private void cleanUpSmsRawTable(Context context) {
6994 ContentResolver resolver = context.getContentResolver();
6995 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6996 resolver.delete(uri, null, null);
6997 }
6998
Narayan Kamath1c496c22015-04-16 14:40:19 +01006999 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007000 public String getSimLocaleForSubscriber(int subId) {
7001 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7002 final Phone phone = getPhone(subId);
7003 if (phone == null) {
7004 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007005 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final long identity = Binder.clearCallingIdentity();
7008 try {
chen xu5d3637b2019-01-21 23:31:38 -08007009 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007010 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007011 if (info == null) {
7012 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7013 return null;
7014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 // Try and fetch the locale from the carrier properties or from the SIM language
7016 // preferences (EF-PL and EF-LI)...
7017 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007019 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7020 if (localeFromDefaultSim != null) {
7021 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7022 if (DBG) log("Using locale from subId: " + subId + " locale: "
7023 + localeFromDefaultSim);
7024 return localeFromDefaultSim.toLanguageTag();
7025 } else {
7026 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 }
7028 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 // The SIM language preferences only store a language (e.g. fr = French), not an
7031 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7032 // the SIM and carrier preferences does not include a country we add the country
7033 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007034 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007036 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 return mccLocale.toLanguageTag();
7038 }
7039
7040 if (DBG) log("No locale found - returning null");
7041 return null;
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007045 }
7046
7047 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007048 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007049 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007050 }
7051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 /**
7053 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7054 */
7055 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007056 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007057 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007058 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007059
Chenjie Yu1ba97252018-01-11 18:16:20 -08007060 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007061 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007062
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007063 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007064 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7065 * representing the state of the modem.
7066 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007067 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7068 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007069 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007070 */
7071 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007072 public void requestModemActivityInfo(ResultReceiver result) {
7073 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007074 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075
7076 final long identity = Binder.clearCallingIdentity();
7077 try {
sqian1a1be542020-03-05 11:37:28 -08007078 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007081 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007082 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007083
Siddharth Rayb8114062018-06-17 15:02:38 -07007084 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7085 // less than total activity duration.
7086 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7087 if (info == null) {
7088 return false;
7089 }
7090 int activityDurationMs =
7091 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7092 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007093 int[] txTimeMs = info.getTransmitTimeMillis();
7094 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7095 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007096 }
7097 return (info.isValid()
7098 && (info.getSleepTimeMillis() <= activityDurationMs)
7099 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007100 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007101 && (totalTxTimeMs <= activityDurationMs));
7102 }
7103
Jack Yu85bd38a2015-11-09 11:34:32 -08007104 /**
7105 * {@hide}
7106 * Returns the service state information on specified subscription.
7107 */
7108 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7110 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007112 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007113 return null;
7114 }
7115
Hall Liuf19c44f2018-11-27 14:38:17 -08007116 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7117 LocationAccessPolicy.checkLocationPermission(mApp,
7118 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7119 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007120 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007121 .setCallingPid(Binder.getCallingPid())
7122 .setCallingUid(Binder.getCallingUid())
7123 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007124 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007125 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7126 .build());
7127
7128 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7129 LocationAccessPolicy.checkLocationPermission(mApp,
7130 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7131 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007132 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007133 .setCallingPid(Binder.getCallingPid())
7134 .setCallingUid(Binder.getCallingUid())
7135 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007136 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007137 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7138 .build());
7139 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7140 boolean hasFinePermission =
7141 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7142 boolean hasCoarsePermission =
7143 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 final long identity = Binder.clearCallingIdentity();
7146 try {
7147 final Phone phone = getPhone(subId);
7148 if (phone == null) {
7149 return null;
7150 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007151
Hall Liuf19c44f2018-11-27 14:38:17 -08007152 ServiceState ss = phone.getServiceState();
7153
7154 // Scrub out the location info in ServiceState depending on what level of access
7155 // the caller has.
7156 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007157 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7158 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007162 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007163
7164 /**
7165 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7166 *
7167 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7168 * voicemail ringtone.
7169 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7170 * PhoneAccount.
7171 */
7172 @Override
7173 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7177 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007185 }
7186
7187 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007188 * Sets the per-account voicemail ringtone.
7189 *
7190 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7191 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7192 *
7193 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7194 * voicemail ringtone.
7195 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7196 * PhoneAccount.
7197 */
7198 @Override
7199 public void setVoicemailRingtoneUri(String callingPackage,
7200 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007201 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007203 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7204 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7206 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7207 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7213 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007214 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 }
7216 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7217 } finally {
7218 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007219 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007220 }
7221
7222 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007223 * Returns whether vibration is set for voicemail notification in Phone settings.
7224 *
7225 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7226 * voicemail vibration setting.
7227 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7228 */
7229 @Override
7230 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7234 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007242 }
7243
Youhan Wange64578a2016-05-02 15:32:42 -07007244 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007245 * Sets the per-account voicemail vibration.
7246 *
7247 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7248 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7249 *
7250 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7251 * voicemail vibration setting.
7252 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7253 * specific PhoneAccount.
7254 */
7255 @Override
7256 public void setVoicemailVibrationEnabled(String callingPackage,
7257 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007258 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007260 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7261 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7263 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7264 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007265 }
7266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7270 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007271 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 }
7273 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007276 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007277 }
7278
7279 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007280 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7281 *
7282 * @throws SecurityException if the caller does not have the required permission
7283 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007284 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007286 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007287 }
7288
7289 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007290 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7291 * permission.
7292 *
7293 * @throws SecurityException if the caller does not have the required permission
7294 */
7295 private void enforceSendSmsPermission() {
7296 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7297 }
7298
7299 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007300 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007301 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007302 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007303 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007304 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007308 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 if (componentName == null) {
7310 throw new SecurityException(
7311 "Caller not current active visual voicemail package[null]");
7312 }
7313 String vvmPackage = componentName.getPackageName();
7314 if (!callingPackage.equals(vvmPackage)) {
7315 throw new SecurityException("Caller not current active visual voicemail package["
7316 + vvmPackage + "]");
7317 }
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007320 }
7321 }
7322
7323 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007324 * Return the application ID for the app type.
7325 *
7326 * @param subId the subscription ID that this request applies to.
7327 * @param appType the uicc app type.
7328 * @return Application ID for specificied app type, or null if no uicc.
7329 */
7330 @Override
7331 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007332 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007333 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334
7335 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007336 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (phone == null) {
7338 return null;
7339 }
7340 String aid = null;
7341 try {
7342 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7343 .getApplicationByType(appType).getAid();
7344 } catch (Exception e) {
7345 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7346 }
7347 return aid;
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007350 }
Youhan Wange64578a2016-05-02 15:32:42 -07007351 }
7352
Youhan Wang4001d252016-05-11 10:29:41 -07007353 /**
7354 * Return the Electronic Serial Number.
7355 *
7356 * @param subId the subscription ID that this request applies to.
7357 * @return ESN or null if error.
7358 */
7359 @Override
7360 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007361 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007362 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363
7364 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007365 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 if (phone == null) {
7367 return null;
7368 }
7369 String esn = null;
7370 try {
7371 esn = phone.getEsn();
7372 } catch (Exception e) {
7373 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7374 }
7375 return esn;
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007378 }
Youhan Wang4001d252016-05-11 10:29:41 -07007379 }
7380
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007381 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007382 * Return the Preferred Roaming List Version.
7383 *
7384 * @param subId the subscription ID that this request applies to.
7385 * @return PRLVersion or null if error.
7386 */
7387 @Override
7388 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007389 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007390 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391
7392 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007393 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 if (phone == null) {
7395 return null;
7396 }
7397 String cdmaPrlVersion = null;
7398 try {
7399 cdmaPrlVersion = phone.getCdmaPrlVersion();
7400 } catch (Exception e) {
7401 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7402 }
7403 return cdmaPrlVersion;
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007406 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007407 }
7408
7409 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007410 * Get snapshot of Telephony histograms
7411 * @return List of Telephony histograms
7412 * @hide
7413 */
7414 @Override
7415 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7417 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 return RIL.getTelephonyRILTimingHistograms();
7422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007425 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007426
7427 /**
7428 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007429 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7430 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007431 * Require system privileges. In the future we may add this to carrier APIs.
7432 *
Michele Berionne482f8202018-11-27 18:57:59 -08007433 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007434 */
7435 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007436 @TelephonyManager.SetCarrierRestrictionResult
7437 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007438 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007440
Michele Berionne482f8202018-11-27 18:57:59 -08007441 if (carrierRestrictionRules == null) {
7442 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007443 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 final long identity = Binder.clearCallingIdentity();
7446 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007447 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007448 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007452 }
7453
7454 /**
7455 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007456 * Get the allowed carrier list and the excluded carrier list, including the priority between
7457 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007458 * Require system privileges. In the future we may add this to carrier APIs.
7459 *
Michele Berionne482f8202018-11-27 18:57:59 -08007460 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007461 */
7462 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007463 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007464 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466
7467 final long identity = Binder.clearCallingIdentity();
7468 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007469 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7470 if (response instanceof CarrierRestrictionRules) {
7471 return (CarrierRestrictionRules) response;
7472 }
7473 // Response is an Exception of some kind,
7474 // which is signalled to the user as a NULL retval
7475 return null;
7476 } catch (Exception e) {
7477 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7478 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007482 }
7483
fionaxu59545b42016-05-25 15:53:37 -07007484 /**
fionaxu59545b42016-05-25 15:53:37 -07007485 * Action set from carrier signalling broadcast receivers to enable/disable radio
7486 * @param subId the subscription ID that this action applies to.
7487 * @param enabled control enable or disable radio.
7488 * {@hide}
7489 */
7490 @Override
7491 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7492 enforceModifyPermission();
7493 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494
7495 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007496 if (phone == null) {
7497 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7498 return;
7499 }
7500 try {
7501 phone.carrierActionSetRadioEnabled(enabled);
7502 } catch (Exception e) {
7503 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 } finally {
7505 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007506 }
7507 }
7508
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007509 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007510 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7511 * network status based on which carrier apps could apply actions accordingly,
7512 * enable/disable default url handler for example.
7513 *
7514 * @param subId the subscription ID that this action applies to.
7515 * @param report control start/stop reporting the default network status.
7516 * {@hide}
7517 */
7518 @Override
7519 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7520 enforceModifyPermission();
7521 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522
7523 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007524 if (phone == null) {
7525 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7526 return;
7527 }
7528 try {
7529 phone.carrierActionReportDefaultNetworkStatus(report);
7530 } catch (Exception e) {
7531 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007534 }
7535 }
7536
7537 /**
fionaxud9622282017-07-17 17:51:30 -07007538 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7539 * @param subId the subscription ID that this action applies to.
7540 * {@hide}
7541 */
7542 @Override
7543 public void carrierActionResetAll(int subId) {
7544 enforceModifyPermission();
7545 final Phone phone = getPhone(subId);
7546 if (phone == null) {
7547 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7548 return;
7549 }
7550 try {
7551 phone.carrierActionResetAll();
7552 } catch (Exception e) {
7553 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7554 }
7555 }
7556
7557 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007558 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7559 * bug report is being generated.
7560 */
7561 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007562 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7564 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007565 writer.println("Permission Denial: can't dump Phone from pid="
7566 + Binder.getCallingPid()
7567 + ", uid=" + Binder.getCallingUid()
7568 + "without permission "
7569 + android.Manifest.permission.DUMP);
7570 return;
7571 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007572 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007573 }
Jack Yueb89b242016-06-22 13:27:47 -07007574
Brad Ebingerdac2f002018-04-03 15:17:52 -07007575 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007576 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7577 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7578 @NonNull String[] args) {
7579 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7580 this, in.getFileDescriptor(), out.getFileDescriptor(),
7581 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007582 }
7583
Jack Yueb89b242016-06-22 13:27:47 -07007584 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007585 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007586 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007587 * @param reason the reason the data enable change is taking place
7588 * @param enabled True if enabling the data, otherwise disabling.
7589 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007590 */
7591 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007592 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007593 boolean enabled) {
7594 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7595 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7596 try {
7597 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007598 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007599 } catch (SecurityException se) {
7600 enforceModifyPermission();
7601 }
7602 } else {
7603 enforceModifyPermission();
7604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 Phone phone = getPhone(subId);
7609 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007610 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7611 phone.carrierActionSetMeteredApnsEnabled(enabled);
7612 } else {
7613 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 }
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007618 }
7619 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007620
7621 /**
7622 * Get Client request stats
7623 * @return List of Client Request Stats
7624 * @hide
7625 */
7626 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007627 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7628 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007630 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007631 return null;
7632 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007633 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 final long identity = Binder.clearCallingIdentity();
7636 try {
7637 if (phone != null) {
7638 return phone.getClientRequestStats();
7639 }
7640
7641 return null;
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007645 }
7646
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007647 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007648 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007649 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007650 }
Jack Yueb4124c2017-02-16 15:32:43 -08007651
7652 /**
Grace Chen70990072017-03-24 17:21:30 -07007653 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007654 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007655 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007656 * @param state State of SIM (power down, power up, pass through)
7657 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7658 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7659 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007660 *
7661 **/
7662 @Override
Grace Chen70990072017-03-24 17:21:30 -07007663 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007664 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007665 Phone phone = PhoneFactory.getPhone(slotIndex);
7666
vagdeviaf9a5b92018-08-15 16:01:53 -07007667 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007672 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 }
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007676 }
7677 }
Shuo Qiandd210312017-04-12 22:11:33 +00007678
Tyler Gunn65d45c22017-06-05 11:22:26 -07007679 private boolean isUssdApiAllowed(int subId) {
7680 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007681 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007682 if (configManager == null) {
7683 return false;
7684 }
7685 PersistableBundle pb = configManager.getConfigForSubId(subId);
7686 if (pb == null) {
7687 return false;
7688 }
7689 return pb.getBoolean(
7690 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7691 }
7692
Shuo Qiandd210312017-04-12 22:11:33 +00007693 /**
7694 * Check if phone is in emergency callback mode
7695 * @return true if phone is in emergency callback mode
7696 * @param subId sub id
7697 */
goneil9c5f4872017-12-05 14:07:56 -08007698 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007699 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007700 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 if (phone != null) {
7706 return phone.isInEcm();
7707 } else {
7708 return false;
7709 }
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007712 }
7713 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007714
7715 /**
7716 * Get the current signal strength information for the given subscription.
7717 * Because this information is not updated when the device is in a low power state
7718 * it should not be relied-upon to be current.
7719 * @param subId Subscription index
7720 * @return the most recent cached signal strength info from the modem
7721 */
7722 @Override
7723 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone p = getPhone(subId);
7727 if (p == null) {
7728 return null;
7729 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 return p.getSignalStrength();
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
7734 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007735 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007736
Pengquan Meng77b7f132018-08-22 14:49:57 -07007737 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007738 * Get the current modem radio state for the given slot.
7739 * @param slotIndex slot index.
7740 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007741 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007742 * @return the current radio power state from the modem
7743 */
7744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007745 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007746 Phone phone = PhoneFactory.getPhone(slotIndex);
7747 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7749 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007750 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7751 }
7752
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 return phone.getRadioPowerState();
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
7759 }
7760 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7761 }
7762
7763 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007764 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7765 *
7766 * <p>Requires one of the following permissions:
7767 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7768 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7769 * privileges.
7770 *
7771 * @param subId subscription id
7772 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7773 * {@code false}.
7774 */
7775 @Override
7776 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007777 try {
7778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7779 null);
7780 } catch (Exception e) {
7781 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7782 mApp, subId, "isDataRoamingEnabled");
7783 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007784
Pengquan Menga1bb6272018-09-06 09:59:22 -07007785 boolean isEnabled = false;
7786 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007787 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007788 Phone phone = getPhone(subId);
7789 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007790 } finally {
7791 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007792 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007793 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007794 }
7795
7796
7797 /**
7798 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7799 *
7800 * <p> Requires permission:
7801 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7802 * privileges.
7803 *
7804 * @param subId subscription id
7805 * @param isEnabled {@code true} means enable, {@code false} means disable.
7806 */
7807 @Override
7808 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7810 mApp, subId, "setDataRoamingEnabled");
7811
Pengquan Menga1bb6272018-09-06 09:59:22 -07007812 final long identity = Binder.clearCallingIdentity();
7813 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007814 Phone phone = getPhone(subId);
7815 if (phone != null) {
7816 phone.setDataRoamingEnabled(isEnabled);
7817 }
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007820 }
7821 }
7822
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007823 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007824 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007825 TelephonyPermissions
7826 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007827 mApp, subId, "isManualNetworkSelectionAllowed");
7828
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007829 boolean isAllowed = true;
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007832 Phone phone = getPhone(subId);
7833 if (phone != null) {
7834 isAllowed = phone.isCspPlmnEnabled();
7835 }
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
7838 }
7839 return isAllowed;
7840 }
7841
7842 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007843 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007844 // Verify that tha callingPackage belongs to the calling UID
7845 mApp.getSystemService(AppOpsManager.class)
7846 .checkPackage(Binder.getCallingUid(), callingPackage);
7847
Jordan Liu1e142fc2019-04-22 15:10:43 -07007848 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007849 try {
7850 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007851 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007852 } catch (SecurityException e) {
7853 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7854 // has carrier privileges on an active UICC
7855 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7856 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007857 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007858 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007859 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007863 UiccController uiccController = UiccController.getInstance();
7864 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007865 if (hasReadPermission) {
7866 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007867 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007868
7869 // Remove private info if the caller doesn't have access
7870 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7871 for (UiccCardInfo cardInfo : cardInfos) {
7872 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7873 // is available
7874 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7875 if (card == null || card.getUiccProfile() == null) {
7876 // assume no access if the card or profile is unavailable
7877 filteredInfos.add(cardInfo.getUnprivileged());
7878 continue;
7879 }
7880 UiccProfile profile = card.getUiccProfile();
7881 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7882 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7883 filteredInfos.add(cardInfo);
7884 } else {
7885 filteredInfos.add(cardInfo.getUnprivileged());
7886 }
7887 }
7888 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007889 } finally {
7890 Binder.restoreCallingIdentity(identity);
7891 }
7892 }
7893
7894 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007895 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007896 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 final long identity = Binder.clearCallingIdentity();
7899 try {
7900 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7901 if (slots == null) {
7902 Rlog.i(LOG_TAG, "slots is null.");
7903 return null;
7904 }
7905
7906 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7907 for (int i = 0; i < slots.length; i++) {
7908 UiccSlot slot = slots[i];
7909 if (slot == null) {
7910 continue;
7911 }
7912
Jordan Liu7be7e652019-05-06 18:55:02 +00007913 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 UiccCard card = slot.getUiccCard();
7915 if (card != null) {
7916 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007917 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007918 cardId = slot.getEid();
7919 if (TextUtils.isEmpty(cardId)) {
7920 cardId = slot.getIccId();
7921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 }
7923
Jordan Liu857451f2019-05-09 16:35:35 -07007924 if (cardId != null) {
7925 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7926 // if cardId is an EID, it's all digits so this is fine
7927 cardId = IccUtils.stripTrailingFs(cardId);
7928 }
7929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 int cardState = 0;
7931 switch (slot.getCardState()) {
7932 case CARDSTATE_ABSENT:
7933 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7934 break;
7935 case CARDSTATE_PRESENT:
7936 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7937 break;
7938 case CARDSTATE_ERROR:
7939 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7940 break;
7941 case CARDSTATE_RESTRICTED:
7942 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7943 break;
7944 default:
7945 break;
7946
7947 }
7948
7949 infos[i] = new UiccSlotInfo(
7950 slot.isActive(),
7951 slot.isEuicc(),
7952 cardId,
7953 cardState,
7954 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007955 slot.isExtendedApduSupported(),
7956 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 }
7958 return infos;
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007961 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007962 }
7963
7964 @Override
7965 public boolean switchSlots(int[] physicalSlots) {
7966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967
7968 final long identity = Binder.clearCallingIdentity();
7969 try {
7970 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007974 }
Jack Yu4c988042018-02-27 15:30:01 -08007975
7976 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007977 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 return UiccController.getInstance().getCardIdForDefaultEuicc();
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
7985
Pengquan Meng85728fb2018-03-12 16:31:21 -07007986 /**
goneil47ffb6e2018-04-06 15:40:58 -07007987 * A test API to reload the UICC profile.
7988 *
7989 * <p>Requires that the calling app has permission
7990 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 * @hide
7992 */
7993 @Override
7994 public void refreshUiccProfile(int subId) {
7995 enforceModifyPermission();
7996
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 Phone phone = getPhone(subId);
8000 if (phone == null) {
8001 return;
8002 }
8003 UiccCard uiccCard = phone.getUiccCard();
8004 if (uiccCard == null) {
8005 return;
8006 }
8007 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8008 if (uiccProfile == null) {
8009 return;
8010 }
8011 uiccProfile.refresh();
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
8015 }
8016
8017 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008018 * Returns false if the mobile data is disabled by default, otherwise return true.
8019 */
8020 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008021 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008022 }
8023
8024 /**
8025 * Returns true if the data roaming is enabled by default, i.e the system property
8026 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8027 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8028 */
8029 private boolean getDefaultDataRoamingEnabled(int subId) {
8030 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008032 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008033 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8034 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8035 return isDataRoamingEnabled;
8036 }
8037
8038 /**
8039 * Returns the default network type for the given {@code subId}, if the default network type is
8040 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8041 */
8042 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008043 List<Integer> list = TelephonyProperties.default_network();
8044 int phoneId = mSubscriptionController.getPhoneId(subId);
8045 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8046 return list.get(phoneId);
8047 }
8048 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008049 }
fionaxua13278b2018-03-21 00:08:13 -07008050
8051 @Override
8052 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008053 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008054 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
8056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 final Phone phone = getPhone(subId);
8059 if (phone == null) {
8060 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8061 return;
8062 }
chen xueaba88a2019-03-15 13:15:10 -07008063 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8064 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008065 if (carrierPrivilegeRules == null) {
8066 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8067 } else {
8068 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 } finally {
8071 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008072 }
fionaxua13278b2018-03-21 00:08:13 -07008073 }
8074
8075 @Override
8076 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008077 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 final Phone phone = getPhone(subId);
8082 if (phone == null) {
8083 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8084 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8085 }
8086 return phone.getCarrierIdListVersion();
8087 } finally {
8088 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008089 }
fionaxua13278b2018-03-21 00:08:13 -07008090 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008091
8092 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008093 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8094 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008096 mApp, subId, callingPackage, callingFeatureId,
8097 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008098 return -1;
8099 }
8100
8101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106 }
8107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008108
8109 @Override
8110 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008111 TelephonyPermissions
8112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008113 mApp, subId, "getCdmaRoamingMode");
8114
8115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
8121 }
8122
8123 @Override
8124 public boolean setCdmaRoamingMode(int subId, int mode) {
8125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8126 mApp, subId, "setCdmaRoamingMode");
8127
8128 final long identity = Binder.clearCallingIdentity();
8129 try {
8130 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
8133 }
8134 }
8135
8136 @Override
8137 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8139 mApp, subId, "setCdmaSubscriptionMode");
8140
8141 final long identity = Binder.clearCallingIdentity();
8142 try {
8143 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008148
sqianc5eccab2018-10-19 18:46:41 -07008149 @Override
sqian8c685422019-02-22 15:55:18 -08008150 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008151 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008153 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8154 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008155 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8156 }
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
sqian854d44b2018-12-12 16:48:18 -08008159 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8160 for (Phone phone: PhoneFactory.getPhones()) {
8161 if (phone.getEmergencyNumberTracker() != null
8162 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8163 emergencyNumberListInternal.put(
8164 phone.getSubId(),
8165 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8166 }
sqian11b7a0e2018-12-05 18:48:28 -08008167 }
sqian854d44b2018-12-12 16:48:18 -08008168 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
sqianc5eccab2018-10-19 18:46:41 -07008172 }
8173
8174 @Override
sqian8c685422019-02-22 15:55:18 -08008175 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008176 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008177 if (!exactMatch) {
8178 TelephonyPermissions
8179 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008180 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008181 }
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
sqian854d44b2018-12-12 16:48:18 -08008184 for (Phone phone: PhoneFactory.getPhones()) {
8185 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008186 && phone.getEmergencyNumberTracker()
8187 .isEmergencyNumber(number, exactMatch)) {
8188 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008189 }
sqian11b7a0e2018-12-05 18:48:28 -08008190 }
8191 return false;
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
8195 }
8196
sqianf4ca7ed2019-01-15 18:32:07 -08008197 /**
8198 * Update emergency number list for test mode.
8199 */
8200 @Override
8201 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8203 "updateEmergencyNumberListTestMode");
8204
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 for (Phone phone: PhoneFactory.getPhones()) {
8208 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8209 if (tracker != null) {
8210 tracker.executeEmergencyNumberTestModeCommand(action, num);
8211 }
8212 }
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
8216 }
8217
8218 /**
8219 * Get the full emergency number list for test mode.
8220 */
8221 @Override
8222 public List<String> getEmergencyNumberListTestMode() {
8223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8224 "getEmergencyNumberListTestMode");
8225
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
8228 Set<String> emergencyNumbers = new HashSet<>();
8229 for (Phone phone: PhoneFactory.getPhones()) {
8230 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8231 if (tracker != null) {
8232 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8233 emergencyNumbers.add(num.getNumber());
8234 }
8235 }
8236 }
8237 return new ArrayList<>(emergencyNumbers);
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
8241 }
8242
chen xud6b45bd2018-10-30 22:27:10 -07008243 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008244 public int getEmergencyNumberDbVersion(int subId) {
8245 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8246
8247 final long identity = Binder.clearCallingIdentity();
8248 try {
8249 final Phone phone = getPhone(subId);
8250 if (phone == null) {
8251 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8252 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8253 }
8254 return phone.getEmergencyNumberDbVersion();
8255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
8258 }
8259
8260 @Override
8261 public void notifyOtaEmergencyNumberDbInstalled() {
8262 enforceModifyPermission();
8263
8264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 for (Phone phone: PhoneFactory.getPhones()) {
8267 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8268 if (tracker != null) {
8269 tracker.updateOtaEmergencyNumberDatabase();
8270 }
8271 }
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 }
8276
8277 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008278 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008279 enforceActiveEmergencySessionPermission();
8280
8281 final long identity = Binder.clearCallingIdentity();
8282 try {
8283 for (Phone phone: PhoneFactory.getPhones()) {
8284 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8285 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008286 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8287 }
8288 }
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
8294 @Override
8295 public void resetOtaEmergencyNumberDbFilePath() {
8296 enforceActiveEmergencySessionPermission();
8297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 for (Phone phone: PhoneFactory.getPhones()) {
8301 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8302 if (tracker != null) {
8303 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008304 }
8305 }
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
8310
8311 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008312 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8313 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8314 Phone phone = getPhone(subId);
8315 if (phone == null) {
8316 return null;
8317 }
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 UiccProfile profile = UiccController.getInstance()
8321 .getUiccProfileForPhone(phone.getPhoneId());
8322 if (profile != null) {
8323 return profile.getCertsFromCarrierPrivilegeAccessRules();
8324 }
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 return null;
8329 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008330
8331 /**
8332 * Enable or disable a modem stack.
8333 */
8334 @Override
8335 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8336 enforceModifyPermission();
8337
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 Phone phone = PhoneFactory.getPhone(slotIndex);
8341 if (phone == null) {
8342 return false;
8343 } else {
8344 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8345 }
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
8348 }
8349 }
Michelecea4cf22018-12-21 15:00:11 -08008350
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008351 /**
8352 * Whether a modem stack is enabled or not.
8353 */
8354 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008355 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8356 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008357 Phone phone = PhoneFactory.getPhone(slotIndex);
8358 if (phone == null) return false;
8359
8360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008361 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8362 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008363 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8364 }
8365
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008368 try {
8369 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8370 } catch (NoSuchElementException ex) {
8371 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8372 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008373 } finally {
8374 Binder.restoreCallingIdentity(identity);
8375 }
8376 }
8377
Michelecea4cf22018-12-21 15:00:11 -08008378 @Override
Michele0ea7d782019-03-19 14:58:42 -07008379 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008380 enforceModifyPermission();
8381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008385 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008386 .commit();
8387 } finally {
8388 Binder.restoreCallingIdentity(identity);
8389 }
8390 }
8391
8392 @Override
Michele0ea7d782019-03-19 14:58:42 -07008393 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008394 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008396 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8397 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008398 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008399 }
Michelecea4cf22018-12-21 15:00:11 -08008400
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
Michele0ea7d782019-03-19 14:58:42 -07008403 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008408
Michele0ea7d782019-03-19 14:58:42 -07008409 @TelephonyManager.IsMultiSimSupportedResult
8410 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008411 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8412 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8413 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008414 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8415 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008416 }
8417 // Check if the hardware supports multisim functionality. If usage of multisim is not
8418 // supported by the modem, indicate that it is restricted.
8419 PhoneCapability staticCapability =
8420 mPhoneConfigurationManager.getStaticPhoneCapability();
8421 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008422 loge("isMultiSimSupportedInternal: no static configuration available");
8423 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008424 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008425 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008426 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8427 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008428 }
8429 // Check if support of multiple SIMs is restricted by carrier
8430 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008431 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008432 }
8433
Michele0ea7d782019-03-19 14:58:42 -07008434 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008435 }
8436
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008437 /**
8438 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008439 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8440 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8441 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008442 * @param numOfSims number of active sims we want to switch to
8443 */
8444 @Override
8445 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008446 if (numOfSims == 1) {
8447 enforceModifyPermission();
8448 } else {
8449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8450 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8451 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008452 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008453
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008454 try {
Michele30b57b22019-03-01 12:01:14 -08008455 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008456 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008457 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8458 return;
8459 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008460 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008466 @Override
8467 public boolean isApplicationOnUicc(int subId, int appType) {
8468 enforceReadPrivilegedPermission("isApplicationOnUicc");
8469 Phone phone = getPhone(subId);
8470 if (phone == null) {
8471 return false;
8472 }
8473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 UiccCard uiccCard = phone.getUiccCard();
8476 if (uiccCard == null) {
8477 return false;
8478 }
8479 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8480 if (uiccProfile == null) {
8481 return false;
8482 }
8483 if (TelephonyManager.APPTYPE_SIM <= appType
8484 && appType <= TelephonyManager.APPTYPE_ISIM) {
8485 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8486 }
8487 return false;
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
8492
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008493 /**
chen xub4baa772019-04-03 10:23:41 -07008494 * Get whether making changes to modem configurations will trigger reboot.
8495 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008496 */
8497 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008498 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8499 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008501 mApp, subId, callingPackage, callingFeatureId,
8502 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008503 return false;
8504 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008505 final long identity = Binder.clearCallingIdentity();
8506 try {
8507 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
8510 }
8511 }
8512
Nathan Harold29f5f052019-02-15 13:41:57 -08008513 private void updateModemStateMetrics() {
8514 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8515 // TODO: check the state for each modem if the api is ready.
8516 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8517 }
8518
Pengquan Meng3889a572019-01-23 11:16:29 -08008519 @Override
8520 public int[] getSlotsMapping() {
8521 enforceReadPrivilegedPermission("getSlotsMapping");
8522
8523 final long identity = Binder.clearCallingIdentity();
8524 try {
8525 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8526 // All logical slots should have a mapping to a physical slot.
8527 int[] logicalSlotsMapping = new int[phoneCount];
8528 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8529 for (int i = 0; i < slotInfos.length; i++) {
8530 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8531 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8532 }
8533 }
8534 return logicalSlotsMapping;
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008539
8540 /**
8541 * Get the IRadio HAL Version
8542 */
8543 @Override
8544 public int getRadioHalVersion() {
8545 Phone phone = getDefaultPhone();
8546 if (phone == null) return -1;
8547 HalVersion hv = phone.getHalVersion();
8548 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8549 return hv.major * 100 + hv.minor;
8550 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008551
8552 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008553 * Get the current calling package name.
8554 * @return the current calling package name
8555 */
8556 @Override
8557 public String getCurrentPackageName() {
8558 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8559 }
8560
8561 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008562 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8563 * corresponding network requests on a subId.
8564 *
8565 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008566 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008567 * 2) APN is un-metered for this subscription, or
8568 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008569 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008570 *
8571 * @return whether data is allowed for a apn type.
8572 *
8573 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008574 */
8575 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008576 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008577 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8578 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008579
8580 // Now that all security checks passes, perform the operation as ourselves.
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 Phone phone = getPhone(subId);
8584 if (phone == null) return false;
8585
Jack Yu41407ee2019-05-13 16:54:09 -07008586 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008587 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
8590 }
8591 }
8592
8593 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008594 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008595 enforceReadPrivilegedPermission("isApnMetered");
8596
8597 // Now that all security checks passes, perform the operation as ourselves.
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 Phone phone = getPhone(subId);
8601 if (phone == null) return true; // By default return true.
8602
Jack Yu41407ee2019-05-13 16:54:09 -07008603 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
8607 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008608
8609 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008610 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8611 int subscriptionId, IBooleanConsumer resultCallback) {
8612 enforceModifyPermission();
8613 long token = Binder.clearCallingIdentity();
8614 try {
8615 Phone phone = getPhone(subscriptionId);
8616 if (phone == null) {
8617 try {
8618 if (resultCallback != null) {
8619 resultCallback.accept(false);
8620 }
8621 } catch (RemoteException e) {
8622 // ignore
8623 }
8624 return;
8625 }
8626 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8627 Pair.create(specifiers, (x) -> {
8628 try {
8629 if (resultCallback != null) {
8630 resultCallback.accept(x);
8631 }
8632 } catch (RemoteException e) {
8633 // ignore
8634 }
8635 });
8636 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8637 } finally {
8638 Binder.restoreCallingIdentity(token);
8639 }
8640 }
8641
8642 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008643 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008644 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008645 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8646 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8647 if (iccRecords == null) {
8648 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8649 return false;
8650 }
8651 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8652 }
8653
8654 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008655 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8656 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008657 if (callingPackage == null) {
8658 callingPackage = getCurrentPackageName();
8659 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008660 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8661 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008662 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8663 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008664 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8665 }
8666 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8667 Intent intent = new Intent();
8668 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8669 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8670 // Bring up choose default SMS subscription dialog right now
8671 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8672 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8673 mApp.startActivity(intent);
8674 }
chen xud5ca2d52019-05-28 15:20:57 -07008675
8676 @Override
8677 public String getMmsUAProfUrl(int subId) {
8678 //TODO investigate if this API should require proper permission check in R b/133791609
8679 final long identity = Binder.clearCallingIdentity();
8680 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008681 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8682 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8683 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8684 return carrierUAProfUrl;
8685 }
chen xud5ca2d52019-05-28 15:20:57 -07008686 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8687 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8688 } finally {
8689 Binder.restoreCallingIdentity(identity);
8690 }
8691 }
8692
8693 @Override
8694 public String getMmsUserAgent(int subId) {
8695 //TODO investigate if this API should require proper permission check in R b/133791609
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008698 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8699 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8700 if (!TextUtils.isEmpty(carrierUserAgent)) {
8701 return carrierUserAgent;
8702 }
chen xud5ca2d52019-05-28 15:20:57 -07008703 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8704 .getString(com.android.internal.R.string.config_mms_user_agent);
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
Jack Yub07d4972019-05-28 16:12:25 -07008709
8710 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008711 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8712 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8713
8714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 Phone phone = getPhone(subscriptionId);
8717 if (phone == null) return false;
8718
8719 switch (policy) {
8720 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8721 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8722 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8723 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8724 default:
8725 throw new IllegalArgumentException(policy + " is not a valid policy");
8726 }
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
8730 }
8731
8732 @Override
8733 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8734 boolean enabled) {
8735 enforceModifyPermission();
8736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
8739 Phone phone = getPhone(subscriptionId);
8740 if (phone == null) return;
8741
8742 switch (policy) {
8743 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8744 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8745 break;
8746 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8747 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8748 break;
8749 default:
8750 throw new IllegalArgumentException(policy + " is not a valid policy");
8751 }
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
8755 }
8756
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008757 /**
Hall Liub48cf452020-09-25 11:13:49 -07008758 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008759 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8760 * otherwise.
8761 */
8762 @Override
8763 public void setCepEnabled(boolean isCepEnabled) {
8764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8765
8766 final long identity = Binder.clearCallingIdentity();
8767 try {
8768 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8769 for (Phone phone : PhoneFactory.getPhones()) {
8770 Phone defaultPhone = phone.getImsPhone();
8771 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8772 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8773 ImsPhoneCallTracker imsPhoneCallTracker =
8774 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8775 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8776 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8777 + imsPhone.getMsisdn());
8778 }
8779 }
8780 } finally {
8781 Binder.restoreCallingIdentity(identity);
8782 }
8783 }
allenwtsu46dcc572020-01-08 18:24:03 +08008784
8785 /**
8786 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8787 *
8788 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8789 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8790 * before being read.
8791 */
8792 @Override
8793 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8794 isCompressed) {
8795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8796 mApp, subId, "notifyRcsAutoConfigurationReceived");
8797 try {
8798 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8799 if (configBinder == null) {
8800 Rlog.e(LOG_TAG, "null result for getImsConfig");
8801 } else {
8802 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8803 }
8804 } catch (RemoteException e) {
8805 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8806 }
8807 }
zoey chenf95ca592019-12-30 16:11:23 +08008808
8809 @Override
8810 public boolean isIccLockEnabled(int subId) {
8811 enforceReadPrivilegedPermission("isIccLockEnabled");
8812
8813 // Now that all security checks passes, perform the operation as ourselves.
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 Phone phone = getPhone(subId);
8817 if (phone != null && phone.getIccCard() != null) {
8818 return phone.getIccCard().getIccLockEnabled();
8819 } else {
8820 return false;
8821 }
8822 } finally {
8823 Binder.restoreCallingIdentity(identity);
8824 }
8825 }
8826
8827 /**
zoey chene02881a2019-12-30 16:11:23 +08008828 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008829 *
zoey chene02881a2019-12-30 16:11:23 +08008830 * @return an integer representing the status of IccLock enabled or disabled in the following
8831 * three cases:
8832 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8833 * successfully.
8834 * - Positive number and zero for remaining password attempts.
8835 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008836 *
8837 */
8838 @Override
8839 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8840 enforceModifyPermission();
8841
8842 Phone phone = getPhone(subId);
8843 if (phone == null) {
8844 return 0;
8845 }
8846 // Now that all security checks passes, perform the operation as ourselves.
8847 final long identity = Binder.clearCallingIdentity();
8848 try {
8849 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8850 new Pair<Boolean, String>(enabled, password), phone, null);
8851 return attemptsRemaining;
8852
8853 } catch (Exception e) {
8854 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8855 } finally {
8856 Binder.restoreCallingIdentity(identity);
8857 }
8858 return 0;
8859 }
8860
8861 /**
8862 * Change the ICC password used in ICC pin lock.
8863 *
zoey chene02881a2019-12-30 16:11:23 +08008864 * @return an integer representing the status of IccLock changed in the following three cases:
8865 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8866 * - Positive number and zero for remaining password attempts.
8867 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008868 *
8869 */
8870 @Override
8871 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8872 enforceModifyPermission();
8873
8874 Phone phone = getPhone(subId);
8875 if (phone == null) {
8876 return 0;
8877 }
8878 // Now that all security checks passes, perform the operation as ourselves.
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
8881 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8882 new Pair<String, String>(oldPassword, newPassword), phone, null);
8883 return attemptsRemaining;
8884
8885 } catch (Exception e) {
8886 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
8890 return 0;
8891 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008892
Peter Wangdafb9ac2020-01-15 14:13:38 -08008893 /**
8894 * Request for receiving user activity notification
8895 */
8896 @Override
8897 public void requestUserActivityNotification() {
8898 if (!mNotifyUserActivity.get()
8899 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8900 mNotifyUserActivity.set(true);
8901 }
8902 }
8903
8904 /**
8905 * Called when userActivity is signalled in the power manager.
8906 * This is safe to call from any thread, with any window manager locks held or not.
8907 */
8908 @Override
8909 public void userActivity() {
8910 // ***************************************
8911 // * Inherited from PhoneWindowManager *
8912 // ***************************************
8913 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8914 // WITH ITS LOCKS HELD.
8915 //
8916 // This code must be VERY careful about the locks
8917 // it acquires.
8918 // In fact, the current code acquires way too many,
8919 // and probably has lurking deadlocks.
8920
8921 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8922 throw new SecurityException("Only the OS may call notifyUserActivity()");
8923 }
8924
8925 if (mNotifyUserActivity.getAndSet(false)) {
8926 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8927 USER_ACTIVITY_NOTIFICATION_DELAY);
8928 }
8929 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008930
Malcolm Chen884180b2020-04-13 11:59:40 -07008931 @Override
8932 public boolean canConnectTo5GInDsdsMode() {
8933 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8934 }
Jack Yud10cdd42020-09-28 20:28:01 -07008935
8936 @Override
8937 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8938 String callingFeatureId) {
8939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8940 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8941 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8942 }
8943
8944 Phone phone = getPhone(subId);
8945 if (phone == null) {
8946 throw new RuntimeException("phone is not available");
8947 }
8948 // Now that all security checks passes, perform the operation as ourselves.
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 return phone.getEquivalentHomePlmns();
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
8955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008956}