blob: c552217ff554cae06968bd87710ee4d77bf4ae24 [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -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 Qiancd19c462020-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 Nallurid63128d2019-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 Kim14bb3d02018-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 Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-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 zhao2737e882019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wanga10e89e2019-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 Ebingera34a6c22019-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 Ebingerbc7dd582019-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 Liud60acc92020-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;
Shuo Qian4a594052020-01-23 11:59:30 -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;
Shuo Qian4a594052020-01-23 11:59:30 -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 Liu73f5d362020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-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;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-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 chenc730df82019-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 Liu27d24262020-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 Wang44b186e2020-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 Liu73f5d362020-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 zhao2737e882019-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 Nallurid63128d2019-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 chene02881a2019-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 Liu73f5d362020-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;
Shuo Qian4a594052020-01-23 11:59:30 -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 Sasindran37444802020-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 Ebinger24c29992019-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 Davidson8ab02b22020-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 Nallurid63128d2019-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 Sasindran37444802020-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 Liu27d24262020-09-18 19:04:59 -0700923 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-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);
Shuo Qian4a594052020-01-23 11:59:30 -0800931 break;
Hall Liu27d24262020-09-18 19:04:59 -0700932 }
933 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700936 TelephonyManager.CallForwardingInfoCallback callback =
937 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
938 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800939 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700940 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -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 Liu27d24262020-09-18 19:04:59 -0700947 callForwardingInfo = new CallForwardingInfo(true,
948 callForwardInfo.reason,
949 callForwardInfo.number,
950 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800951 break;
952 }
953 }
954 // Didn't find a call forward info for voice call.
955 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700956 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
957 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800958 }
Hall Liu27d24262020-09-18 19:04:59 -0700959 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -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 Liu940c4ca2020-09-29 17:10:18 -0700967 int errorCode = TelephonyManager
968 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700973 errorCode = TelephonyManager
974 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700976 errorCode = TelephonyManager
977 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800978 }
979 }
Hall Liu27d24262020-09-18 19:04:59 -0700980 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800981 }
Shuo Qian4a594052020-01-23 11:59:30 -0800982 break;
Hall Liu27d24262020-09-18 19:04:59 -0700983 }
Shuo Qian4a594052020-01-23 11:59:30 -0800984
Hall Liu27d24262020-09-18 19:04:59 -0700985 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700988 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800989 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-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,
Shuo Qian4a594052020-01-23 11:59:30 -0800996 callForwardingInfoToSet.getReason(),
997 callForwardingInfoToSet.getNumber(),
998 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
999 break;
Hall Liu27d24262020-09-18 19:04:59 -07001000 }
Shuo Qian4a594052020-01-23 11:59:30 -08001001
Hall Liu27d24262020-09-18 19:04:59 -07001002 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001005 Consumer<Integer> callback =
1006 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1007 request.argument).second;
1008 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001009 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001010 int errorCode = TelephonyManager.CallForwardingInfoCallback
1011 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-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 Liu940c4ca2020-09-29 17:10:18 -07001016 errorCode = TelephonyManager.CallForwardingInfoCallback
1017 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001018 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001019 errorCode = TelephonyManager.CallForwardingInfoCallback
1020 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001021 }
1022 }
1023 callback.accept(errorCode);
1024 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001025 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001026 }
Shuo Qian4a594052020-01-23 11:59:30 -08001027 break;
Hall Liu27d24262020-09-18 19:04:59 -07001028 }
Shuo Qian4a594052020-01-23 11:59:30 -08001029
Hall Liu27d24262020-09-18 19:04:59 -07001030 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1033 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1034 break;
Hall Liu27d24262020-09-18 19:04:59 -07001035 }
Shuo Qian4a594052020-01-23 11:59:30 -08001036
Hall Liu27d24262020-09-18 19:04:59 -07001037 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001040 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -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;
Shuo Qian4a594052020-01-23 11:59:30 -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 Liu27d24262020-09-18 19:04:59 -07001048 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001049 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001050 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1051 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001052 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001053 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -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 Liu27d24262020-09-18 19:04:59 -07001071 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001072 break;
Hall Liu27d24262020-09-18 19:04:59 -07001073 }
Shuo Qian4a594052020-01-23 11:59:30 -08001074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1079 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001080 break;
Hall Liu27d24262020-09-18 19:04:59 -07001081 }
Shuo Qian4a594052020-01-23 11:59:30 -08001082
Hall Liu27d24262020-09-18 19:04:59 -07001083 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-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) {
Shuo Qian4a594052020-01-23 11:59:30 -08001090 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-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);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 }
Shuo Qian4a594052020-01-23 11:59:30 -08001106 break;
Hall Liu27d24262020-09-18 19:04:59 -07001107 }
Shuo Qian4a594052020-01-23 11:59:30 -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);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001168 } else {
1169 ResultReceiver result = (ResultReceiver) request.argument;
1170 Bundle bundle = new Bundle();
1171 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001172 new ModemActivityInfo(0, 0, 0,
1173 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001174 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001175 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001176 break;
1177
Hall Liud0f208c2020-10-14 16:54:44 -07001178 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001181 ResultReceiver result = (ResultReceiver) request.argument;
1182
Hall Liud0f208c2020-10-14 16:54:44 -07001183 ModemActivityInfo ret = null;
1184 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001185 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001186 // Update the last modem activity info and the result of the request.
1187 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1188 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001189 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001190 int[] txTimeMs = info.getTransmitTimeMillis();
1191 int[] lastModemTxTimeMs = mLastModemActivityInfo
1192 .getTransmitTimeMillis();
1193 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1194 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1195 }
Hall Liu49656c02020-10-09 19:00:11 -07001196 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001197 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1198 + mLastModemActivityInfo.getSleepTimeMillis());
1199 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1200 + mLastModemActivityInfo.getIdleTimeMillis());
1201 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1202 mLastModemActivityInfo.setReceiveTimeMillis(
1203 info.getReceiveTimeMillis()
1204 + mLastModemActivityInfo.getReceiveTimeMillis());
1205 }
Hall Liu49656c02020-10-09 19:00:11 -07001206 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001207 mLastModemActivityInfo.getSleepTimeMillis(),
1208 mLastModemActivityInfo.getIdleTimeMillis(),
1209 mLastModemActivityInfo.getTransmitTimeMillis(),
1210 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001211 } else {
1212 if (ar.result == null) {
1213 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001214 error = TelephonyManager.ModemActivityInfoException
1215 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001216 } else if (ar.exception instanceof CommandException) {
1217 loge("queryModemActivityInfo: CommandException: " +
1218 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001219 error = TelephonyManager.ModemActivityInfoException
1220 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001221 } else {
1222 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001223 error = TelephonyManager.ModemActivityInfoException
1224 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 }
1226 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001227 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001228 if (ret != null) {
1229 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1230 } else {
1231 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1232 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001233 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001234 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001235 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001236 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237
Meng Wang1a7c35a2016-05-05 20:56:15 -07001238 case CMD_SET_ALLOWED_CARRIERS:
1239 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001240 CarrierRestrictionRules argument =
1241 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001242 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001243 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001244 break;
1245
1246 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1247 ar = (AsyncResult) msg.obj;
1248 request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null && ar.result != null) {
1250 request.result = ar.result;
1251 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001252 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1253 if (ar.exception instanceof CommandException) {
1254 loge("setAllowedCarriers: CommandException: " + ar.exception);
1255 CommandException.Error error =
1256 ((CommandException) (ar.exception)).getCommandError();
1257 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1258 request.result =
1259 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1260 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 } else {
1262 loge("setAllowedCarriers: Unknown exception");
1263 }
1264 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001265 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 break;
1267
1268 case CMD_GET_ALLOWED_CARRIERS:
1269 request = (MainThreadRequest) msg.obj;
1270 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001271 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 break;
1273
1274 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 if (ar.exception == null && ar.result != null) {
1278 request.result = ar.result;
1279 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001280 request.result = new IllegalStateException(
1281 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 if (ar.result == null) {
1283 loge("getAllowedCarriers: Empty response");
1284 } else if (ar.exception instanceof CommandException) {
1285 loge("getAllowedCarriers: CommandException: " +
1286 ar.exception);
1287 } else {
1288 loge("getAllowedCarriers: Unknown exception");
1289 }
1290 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001291 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 break;
1293
Nathan Haroldb3014052017-01-25 15:57:32 -08001294 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null && ar.result != null) {
1298 request.result = ar.result;
1299 } else {
1300 request.result = new IllegalArgumentException(
1301 "Failed to retrieve Forbidden Plmns");
1302 if (ar.result == null) {
1303 loge("getForbiddenPlmns: Empty response");
1304 } else {
1305 loge("getForbiddenPlmns: Unknown exception");
1306 }
1307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001308 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001309 break;
1310
1311 case CMD_GET_FORBIDDEN_PLMNS:
1312 request = (MainThreadRequest) msg.obj;
1313 uiccCard = getUiccCardFromRequest(request);
1314 if (uiccCard == null) {
1315 loge("getForbiddenPlmns() UiccCard is null");
1316 request.result = new IllegalArgumentException(
1317 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001319 break;
1320 }
1321 Integer appType = (Integer) request.argument;
1322 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1323 if (uiccApp == null) {
1324 loge("getForbiddenPlmns() no app with specified type -- "
1325 + appType);
1326 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 break;
1329 } else {
1330 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1331 + " specified type -- " + appType);
1332 }
1333 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1334 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1335 onCompleted);
1336 break;
1337
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001338 case CMD_SWITCH_SLOTS:
1339 request = (MainThreadRequest) msg.obj;
1340 int[] physicalSlots = (int[]) request.argument;
1341 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1342 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1343 break;
1344
1345 case EVENT_SWITCH_SLOTS_DONE:
1346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
1348 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
1350 break;
1351 case CMD_GET_NETWORK_SELECTION_MODE:
1352 request = (MainThreadRequest) msg.obj;
1353 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1354 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1355 break;
1356
1357 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception != null) {
1361 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1362 } else {
1363 int mode = ((int[]) ar.result)[0];
1364 if (mode == 0) {
1365 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1366 } else {
1367 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1368 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001369 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
1371 break;
1372 case CMD_GET_CDMA_ROAMING_MODE:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1375 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1376 break;
1377 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 if (ar.exception != null) {
1381 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1382 } else {
1383 request.result = ((int[]) ar.result)[0];
1384 }
1385 notifyRequester(request);
1386 break;
1387 case CMD_SET_CDMA_ROAMING_MODE:
1388 request = (MainThreadRequest) msg.obj;
1389 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1390 int mode = (int) request.argument;
1391 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1392 break;
1393 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 request.result = ar.exception == null;
1397 notifyRequester(request);
1398 break;
1399 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1400 request = (MainThreadRequest) msg.obj;
1401 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1402 int subscriptionMode = (int) request.argument;
1403 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1404 break;
1405 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 request.result = ar.exception == null;
1409 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001410 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001411 case CMD_GET_ALL_CELL_INFO:
1412 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001413 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001414 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001415 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001416 case EVENT_GET_ALL_CELL_INFO_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001419 // If a timeout occurs, the response will be null
1420 request.result = (ar.exception == null && ar.result != null)
1421 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001422 synchronized (request) {
1423 request.notifyAll();
1424 }
1425 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001426 case CMD_REQUEST_CELL_INFO_UPDATE:
1427 request = (MainThreadRequest) msg.obj;
1428 request.phone.requestCellInfoUpdate(request.workSource,
1429 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1430 break;
1431 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1435 try {
1436 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001437 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001438 cb.onError(
1439 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1440 ar.exception.getClass().getName(),
1441 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001442 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001443 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001444 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001445 } else {
1446 // use the result as returned
1447 cb.onCellInfo((List<CellInfo>) ar.result);
1448 }
1449 } catch (RemoteException re) {
1450 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1451 }
1452 break;
1453 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 request = (MainThreadRequest) msg.obj;
1455 WorkSource ws = (WorkSource) request.argument;
1456 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001457 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001459 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = ar.result;
1464 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001467 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001468 }
1469
1470 synchronized (request) {
1471 request.notifyAll();
1472 }
1473 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001474 case CMD_MODEM_REBOOT:
1475 request = (MainThreadRequest) msg.obj;
1476 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001477 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001478 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001479 case EVENT_CMD_MODEM_REBOOT_DONE:
1480 handleNullReturnEvent(msg, "rebootModem");
1481 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001482 case CMD_REQUEST_ENABLE_MODEM:
1483 request = (MainThreadRequest) msg.obj;
1484 boolean enable = (boolean) request.argument;
1485 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001486 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001487 PhoneConfigurationManager.getInstance()
1488 .enablePhone(request.phone, enable, onCompleted);
1489 break;
1490 case EVENT_ENABLE_MODEM_DONE:
1491 ar = (AsyncResult) msg.obj;
1492 request = (MainThreadRequest) ar.userObj;
1493 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001494 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001495 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001496 if ((boolean) request.result) {
1497 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1498 updateModemStateMetrics();
1499 } else {
1500 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1501 + ar.exception);
1502 }
1503 notifyRequester(request);
1504 break;
1505 case CMD_GET_MODEM_STATUS:
1506 request = (MainThreadRequest) msg.obj;
1507 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1508 PhoneConfigurationManager.getInstance()
1509 .getPhoneStatusFromModem(request.phone, onCompleted);
1510 break;
1511 case EVENT_GET_MODEM_STATUS_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 int id = request.phone.getPhoneId();
1515 if (ar.exception == null && ar.result != null) {
1516 request.result = ar.result;
1517 //update the cache as modem status has changed
1518 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1519 (boolean) request.result);
1520 } else {
1521 // Return true if modem status cannot be retrieved. For most cases,
1522 // modem status is on. And for older version modems, GET_MODEM_STATUS
1523 // and disable modem are not supported. Modem is always on.
1524 // TODO: this should be fixed in R to support a third
1525 // status UNKNOWN b/131631629
1526 request.result = true;
1527 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1528 + ar.exception);
1529 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001530 notifyRequester(request);
1531 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001532 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1533 request = (MainThreadRequest) msg.obj;
1534 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1535 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1536 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1537 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1538 break;
1539 }
1540 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1544 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1545 args.second.accept(ar.exception == null);
1546 notifyRequester(request);
1547 break;
1548 }
yincheng zhao2737e882019-09-06 17:06:54 -07001549 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
1555 request.result = -1;
1556 loge("Failed to set Forbidden Plmns");
1557 if (ar.result == null) {
1558 loge("setForbidenPlmns: Empty response");
1559 } else if (ar.exception != null) {
1560 loge("setForbiddenPlmns: Exception: " + ar.exception);
1561 request.result = -1;
1562 } else {
1563 loge("setForbiddenPlmns: Unknown exception");
1564 }
1565 }
1566 notifyRequester(request);
1567 break;
1568 case CMD_SET_FORBIDDEN_PLMNS:
1569 request = (MainThreadRequest) msg.obj;
1570 uiccCard = getUiccCardFromRequest(request);
1571 if (uiccCard == null) {
1572 loge("setForbiddenPlmns: UiccCard is null");
1573 request.result = -1;
1574 notifyRequester(request);
1575 break;
1576 }
1577 Pair<Integer, List<String>> setFplmnsArgs =
1578 (Pair<Integer, List<String>>) request.argument;
1579 appType = setFplmnsArgs.first;
1580 List<String> fplmns = setFplmnsArgs.second;
1581 uiccApp = uiccCard.getApplicationByType(appType);
1582 if (uiccApp == null) {
1583 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1584 request.result = -1;
1585 loge("Failed to get UICC App");
1586 notifyRequester(request);
1587 } else {
1588 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1589 ((SIMRecords) uiccApp.getIccRecords())
1590 .setForbiddenPlmns(onCompleted, fplmns);
1591 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001592 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001593 case CMD_ERASE_MODEM_CONFIG:
1594 request = (MainThreadRequest) msg.obj;
1595 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1596 defaultPhone.eraseModemConfig(onCompleted);
1597 break;
1598 case EVENT_ERASE_MODEM_CONFIG_DONE:
1599 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001600 break;
zoey chene02881a2019-12-30 16:11:23 +08001601
1602 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1603 request = (MainThreadRequest) msg.obj;
1604 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1605 Pair<String, String> changed = (Pair<String, String>) request.argument;
1606 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1607 changed.first, changed.second, onCompleted);
1608 break;
1609 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception == null) {
1613 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1614 } else {
1615 request.result = msg.arg1;
1616 }
1617 notifyRequester(request);
1618 break;
1619
1620 case CMD_SET_ICC_LOCK_ENABLED:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1623 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1624 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1625 enabled.first, enabled.second, onCompleted);
1626 break;
1627 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null) {
1631 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1632 } else {
1633 request.result = msg.arg1;
1634 }
1635 notifyRequester(request);
1636 break;
1637
Peter Wangdafb9ac2020-01-15 14:13:38 -08001638 case MSG_NOTIFY_USER_ACTIVITY:
1639 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001640 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001641 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1642 getDefaultPhone().getContext().sendBroadcastAsUser(
1643 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1644 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 default:
1646 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1647 break;
1648 }
1649 }
Jake Hambye994d462014-02-03 13:10:13 -08001650
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 private void notifyRequester(MainThreadRequest request) {
1652 synchronized (request) {
1653 request.notifyAll();
1654 }
1655 }
1656
Jake Hambye994d462014-02-03 13:10:13 -08001657 private void handleNullReturnEvent(Message msg, String command) {
1658 AsyncResult ar = (AsyncResult) msg.obj;
1659 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1660 if (ar.exception == null) {
1661 request.result = true;
1662 } else {
1663 request.result = false;
1664 if (ar.exception instanceof CommandException) {
1665 loge(command + ": CommandException: " + ar.exception);
1666 } else {
1667 loge(command + ": Unknown exception");
1668 }
1669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001670 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
1674 /**
1675 * Posts the specified command to be executed on the main thread,
1676 * waits for the request to complete, and returns the result.
1677 * @see #sendRequestAsync
1678 */
1679 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001680 return sendRequest(
1681 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001682 }
1683
1684 /**
1685 * Posts the specified command to be executed on the main thread,
1686 * waits for the request to complete, and returns the result.
1687 * @see #sendRequestAsync
1688 */
1689 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1690 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001691 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
1694 /**
1695 * Posts the specified command to be executed on the main thread,
1696 * waits for the request to complete, and returns the result.
1697 * @see #sendRequestAsync
1698 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001699 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001700 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001701 }
1702
1703 /**
1704 * Posts the specified command to be executed on the main thread,
1705 * waits for the request to complete, and returns the result.
1706 * @see #sendRequestAsync
1707 */
Nathan Harold92bed182018-10-12 18:16:49 -07001708 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1709 return sendRequest(command, argument, subId, null, workSource);
1710 }
1711
1712 /**
1713 * Posts the specified command to be executed on the main thread,
1714 * waits for the request to complete, and returns the result.
1715 * @see #sendRequestAsync
1716 */
1717 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1718 return sendRequest(
1719 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1720 }
1721
1722 /**
1723 * Posts the specified command to be executed on the main thread,
1724 * waits for the request to complete, and returns the result.
1725 * @see #sendRequestAsync
1726 */
1727 private Object sendRequest(
1728 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1730 throw new RuntimeException("This method will deadlock if called from the main thread.");
1731 }
1732
Nathan Harold92bed182018-10-12 18:16:49 -07001733 MainThreadRequest request = null;
1734 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1735 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1736 } else if (phone != null) {
1737 request = new MainThreadRequest(argument, phone, workSource);
1738 } else {
1739 request = new MainThreadRequest(argument, subId, workSource);
1740 }
1741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 Message msg = mMainThreadHandler.obtainMessage(command, request);
1743 msg.sendToTarget();
1744
1745 // Wait for the request to complete
1746 synchronized (request) {
1747 while (request.result == null) {
1748 try {
1749 request.wait();
1750 } catch (InterruptedException e) {
1751 // Do nothing, go back and wait until the request is complete
1752 }
1753 }
1754 }
1755 return request.result;
1756 }
1757
1758 /**
1759 * Asynchronous ("fire and forget") version of sendRequest():
1760 * Posts the specified command to be executed on the main thread, and
1761 * returns immediately.
1762 * @see #sendRequest
1763 */
1764 private void sendRequestAsync(int command) {
1765 mMainThreadHandler.sendEmptyMessage(command);
1766 }
1767
1768 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001769 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001770 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001771 */
1772 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 sendRequestAsync(command, argument, null, null);
1774 }
1775
1776 /**
1777 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1778 * @see {@link #sendRequest(int,Object)}
1779 */
1780 private void sendRequestAsync(
1781 int command, Object argument, Phone phone, WorkSource workSource) {
1782 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001783 Message msg = mMainThreadHandler.obtainMessage(command, request);
1784 msg.sendToTarget();
1785 }
1786
1787 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 * Initialize the singleton PhoneInterfaceManager instance.
1789 * This is only done once, at startup, from PhoneApp.onCreate().
1790 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001791 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 synchronized (PhoneInterfaceManager.class) {
1793 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001794 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 } else {
1796 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1797 }
1798 return sInstance;
1799 }
1800 }
1801
1802 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001803 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001806 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001807 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1809 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001810 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001811 mTelephonySharedPreferences =
1812 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001813 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001814 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001815 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 publish();
1818 }
1819
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001820 private Phone getDefaultPhone() {
1821 Phone thePhone = getPhone(getDefaultSubscription());
1822 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1823 }
1824
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 private void publish() {
1826 if (DBG) log("publish: " + this);
1827
Peter Wangc035ce42020-01-08 21:00:22 -08001828 TelephonyFrameworkInitializer
1829 .getTelephonyServiceManager()
1830 .getTelephonyServiceRegisterer()
1831 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Stuart Scott584921c2015-01-15 17:10:34 -08001834 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001835 if (request.phone != null) {
1836 return request.phone;
1837 } else {
1838 return getPhoneFromSubId(request.subId);
1839 }
1840 }
1841
1842 private Phone getPhoneFromSubId(int subId) {
1843 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1844 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001845 }
1846
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001847 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1848 Phone phone = getPhoneFromRequest(request);
1849 return phone == null ? null :
1850 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1851 }
1852
Wink Saville36469e72014-06-11 15:17:00 -07001853 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001854 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001855 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857
Naina Nallurid63128d2019-09-17 14:10:30 -07001858 private void sendEraseModemConfig(Phone phone) {
1859 if (phone != null) {
1860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1861 mApp, phone.getSubId(), "eraseModemConfig");
1862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1865 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1866 } finally {
1867 Binder.restoreCallingIdentity(identity);
1868 }
1869 }
1870 }
1871
Peter Wang44b186e2020-01-13 23:33:09 -08001872 private boolean isImsAvailableOnDevice() {
1873 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1874 if (pm == null) {
1875 // For some reason package manger is not available.. This will fail internally anyway,
1876 // so do not throw error and allow.
1877 return true;
1878 }
1879 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1880 }
1881
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001883 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001884 }
1885
Wink Savilleb564aae2014-10-23 10:18:09 -07001886 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 if (DBG) log("dial: " + number);
1888 // No permission check needed here: This is just a wrapper around the
1889 // ACTION_DIAL intent, which is available to any app since it puts up
1890 // the UI before it does anything.
1891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 String url = createTelUrl(number);
1895 if (url == null) {
1896 return;
1897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 // PENDING: should we just silently fail if phone is offhook or ringing?
1900 PhoneConstants.State state = mCM.getState(subId);
1901 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1902 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1903 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1904 mApp.startActivity(intent);
1905 }
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909 }
1910
1911 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Wink Savilleb564aae2014-10-23 10:18:09 -07001915 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 if (DBG) log("call: " + number);
1917
1918 // This is just a wrapper around the ACTION_CALL intent, but we still
1919 // need to do a permission check since we're calling startActivity()
1920 // from the context of the phone app.
1921 enforceCallPermission();
1922
Jordan Liu1617b712019-07-10 15:06:26 -07001923 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 != AppOpsManager.MODE_ALLOWED) {
1925 return;
1926 }
1927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 String url = createTelUrl(number);
1931 if (url == null) {
1932 return;
1933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 boolean isValid = false;
1936 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1937 if (slist != null) {
1938 for (SubscriptionInfo subInfoRecord : slist) {
1939 if (subInfoRecord.getSubscriptionId() == subId) {
1940 isValid = true;
1941 break;
1942 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001943 }
Wink Saville08874612014-08-31 19:19:58 -07001944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 if (!isValid) {
1946 return;
1947 }
Wink Saville08874612014-08-31 19:19:58 -07001948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1950 intent.putExtra(SUBSCRIPTION_KEY, subId);
1951 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1952 mApp.startActivity(intent);
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Wink Savilleb564aae2014-10-23 10:18:09 -07001958 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001959 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001960 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1961 }
1962
Wink Savilleb564aae2014-10-23 10:18:09 -07001963 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001964 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001965 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1966 }
1967
Wink Savilleb564aae2014-10-23 10:18:09 -07001968 public int[] supplyPinReportResultForSubscriber(int subId, 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 checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1974 checkSimPin.start();
1975 return checkSimPin.unlockSim(null, pin);
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
1978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983
1984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1987 checkSimPuk.start();
1988 return checkSimPuk.unlockSim(puk, pin);
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
1991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
1994 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001995 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 * a synchronous one.
1997 */
1998 private static class UnlockSim extends Thread {
1999
2000 private final IccCard mSimCard;
2001
2002 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002003 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2004 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005
2006 // For replies from SimCard interface
2007 private Handler mHandler;
2008
2009 // For async handler to identify request type
2010 private static final int SUPPLY_PIN_COMPLETE = 100;
2011
2012 public UnlockSim(IccCard simCard) {
2013 mSimCard = simCard;
2014 }
2015
2016 @Override
2017 public void run() {
2018 Looper.prepare();
2019 synchronized (UnlockSim.this) {
2020 mHandler = new Handler() {
2021 @Override
2022 public void handleMessage(Message msg) {
2023 AsyncResult ar = (AsyncResult) msg.obj;
2024 switch (msg.what) {
2025 case SUPPLY_PIN_COMPLETE:
2026 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2027 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002028 mRetryCount = msg.arg1;
2029 if (ar.exception != null) {
2030 if (ar.exception instanceof CommandException &&
2031 ((CommandException)(ar.exception)).getCommandError()
2032 == CommandException.Error.PASSWORD_INCORRECT) {
2033 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002034 } //When UiccCardApp dispose,handle message and return exception
2035 else if (ar.exception instanceof CommandException &&
2036 ((CommandException) (ar.exception)).getCommandError()
2037 == CommandException.Error.ABORTED) {
2038 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002039 } else {
2040 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2041 }
2042 } else {
2043 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 mDone = true;
2046 UnlockSim.this.notifyAll();
2047 }
2048 break;
2049 }
2050 }
2051 };
2052 UnlockSim.this.notifyAll();
2053 }
2054 Looper.loop();
2055 }
2056
2057 /*
2058 * Use PIN or PUK to unlock SIM card
2059 *
2060 * If PUK is null, unlock SIM card with PIN
2061 *
2062 * If PUK is not null, unlock SIM card with PUK and set PIN code
2063 */
Wink Saville9de0f752013-10-22 19:04:03 -07002064 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065
2066 while (mHandler == null) {
2067 try {
2068 wait();
2069 } catch (InterruptedException e) {
2070 Thread.currentThread().interrupt();
2071 }
2072 }
2073 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2074
2075 if (puk == null) {
2076 mSimCard.supplyPin(pin, callback);
2077 } else {
2078 mSimCard.supplyPuk(puk, pin, callback);
2079 }
2080
2081 while (!mDone) {
2082 try {
2083 Log.d(LOG_TAG, "wait for done");
2084 wait();
2085 } catch (InterruptedException e) {
2086 // Restore the interrupted status
2087 Thread.currentThread().interrupt();
2088 }
2089 }
2090 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002091 int[] resultArray = new int[2];
2092 resultArray[0] = mResult;
2093 resultArray[1] = mRetryCount;
2094 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096 }
2097
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002098 /**
2099 * This method has been removed due to privacy and stability concerns.
2100 */
2101 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002103 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2104 return;
Wink Saville36469e72014-06-11 15:17:00 -07002105 }
2106
Nathan Harold1f889d82020-06-04 17:05:26 -07002107 @Override
2108 public void updateServiceLocationWithPackageName(String callingPackage) {
2109 mApp.getSystemService(AppOpsManager.class)
2110 .checkPackage(Binder.getCallingUid(), callingPackage);
2111
2112 final int targetSdk = getTargetSdk(callingPackage);
2113 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2114 // Callers targeting S have no business invoking this method.
2115 return;
2116 }
2117
2118 LocationAccessPolicy.LocationPermissionResult locationResult =
2119 LocationAccessPolicy.checkLocationPermission(mApp,
2120 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2121 .setCallingPackage(callingPackage)
2122 .setCallingFeatureId(null)
2123 .setCallingPid(Binder.getCallingPid())
2124 .setCallingUid(Binder.getCallingUid())
2125 .setMethod("updateServiceLocation")
2126 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2127 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2128 .build());
2129 // Apps that lack location permission have no business calling this method;
2130 // however, because no permission was declared in the public API, denials must
2131 // all be "soft".
2132 switch (locationResult) {
2133 case DENIED_HARD: /* fall through */
2134 case DENIED_SOFT:
2135 return;
2136 }
2137
2138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002141 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002143 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002150 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002151 @Override
2152 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002153 return isRadioOnWithFeature(callingPackage, null);
2154 }
2155
2156
2157 @Override
2158 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2159 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2160 callingFeatureId);
2161 }
2162
2163 @Deprecated
2164 @Override
2165 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2166 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
2168
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002170 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2171 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002173 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002174 return false;
2175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 return isRadioOnForSubscriber(subId);
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002183 }
2184
2185 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 final Phone phone = getPhone(subId);
2189 if (phone != null) {
2190 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2191 } else {
2192 return false;
2193 }
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
2199 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002200 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
Wink Saville36469e72014-06-11 15:17:00 -07002202
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 final Phone phone = getPhone(subId);
2209 if (phone != null) {
2210 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Wink Saville36469e72014-06-11 15:17:00 -07002215 }
2216
2217 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002218 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002222 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 final Phone phone = getPhone(subId);
2227 if (phone == null) {
2228 return false;
2229 }
2230 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2231 toggleRadioOnOffForSubscriber(subId);
2232 }
2233 return true;
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
Wink Saville36469e72014-06-11 15:17:00 -07002238
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002239 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002240 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002241 /*
2242 * If any of the Radios are available, it will need to be
2243 * shutdown. So return true if any Radio is available.
2244 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2248 Phone phone = PhoneFactory.getPhone(i);
2249 if (phone != null && phone.isRadioAvailable()) return true;
2250 }
2251 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2252 return false;
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002255 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002256 }
2257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002259 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 enforceModifyPermission();
2261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2265 logv("Shutting down Phone " + i);
2266 shutdownRadioUsingPhoneId(i);
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002270 }
2271 }
2272
2273 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002274 Phone phone = PhoneFactory.getPhone(phoneId);
2275 if (phone != null && phone.isRadioAvailable()) {
2276 phone.shutdownRadio();
2277 }
2278 }
2279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2286 if (defaultPhone != null) {
2287 defaultPhone.setRadioPower(turnOn);
2288 return true;
2289 } else {
2290 loge("There's no default phone.");
2291 return false;
2292 }
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002295 }
Wink Saville36469e72014-06-11 15:17:00 -07002296 }
2297
Wink Savilleb564aae2014-10-23 10:18:09 -07002298 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone phone = getPhone(subId);
2304 if (phone != null) {
2305 phone.setRadioPower(turnOn);
2306 return true;
2307 } else {
2308 return false;
2309 }
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
Wink Saville36469e72014-06-11 15:17:00 -07002315 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 public boolean enableDataConnectivity() {
2318 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 int subId = mSubscriptionController.getDefaultDataSubId();
2323 final Phone phone = getPhone(subId);
2324 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002325 phone.getDataEnabledSettings().setDataEnabled(
2326 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327 return true;
2328 } else {
2329 return false;
2330 }
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
Wink Saville36469e72014-06-11 15:17:00 -07002336 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 public boolean disableDataConnectivity() {
2339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 int subId = mSubscriptionController.getDefaultDataSubId();
2344 final Phone phone = getPhone(subId);
2345 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002346 phone.getDataEnabledSettings().setDataEnabled(
2347 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 return true;
2349 } else {
2350 return false;
2351 }
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
2356
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002358 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
2362 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002363 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364 } else {
2365 return false;
2366 }
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
2371
2372 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002373 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002374 }
2375
pkanwarae03a6b2016-11-06 20:37:09 -08002376 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 enforceCallPermission();
2378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2382 return;
2383 }
2384 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2385 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
pkanwar32d516d2016-10-14 19:37:38 -07002389 };
2390
Wink Savilleb564aae2014-10-23 10:18:09 -07002391 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2397 return false;
2398 }
2399 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002406 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002409 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 Phone phone = PhoneFactory.getPhone(slotIndex);
2413 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2414 PhoneConstantConversions.convertCallState(phone.getState());
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002421 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002422 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2423 }
2424
2425 @Override
2426 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002429 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 if (phone != null) {
2431 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2432 } else {
2433 return PhoneConstantConversions.convertDataState(
2434 PhoneConstants.DataState.DISCONNECTED);
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
Sanket Padawe356d7632015-06-22 14:03:32 -07002441 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002442 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002443 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2444 }
2445
2446 @Override
2447 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002450 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 if (phone != null) {
2452 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2453 } else {
2454 return TelephonyManager.DATA_ACTIVITY_NONE;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 }
2460
2461 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002462 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002463 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002464 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002465
2466 LocationAccessPolicy.LocationPermissionResult locationResult =
2467 LocationAccessPolicy.checkLocationPermission(mApp,
2468 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2469 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002470 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002471 .setCallingPid(Binder.getCallingPid())
2472 .setCallingUid(Binder.getCallingUid())
2473 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002474 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2476 .build());
2477 switch (locationResult) {
2478 case DENIED_HARD:
2479 throw new SecurityException("Not allowed to access cell location");
2480 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002481 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2482 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002489 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002490 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
Svetoslav64fad262015-04-14 14:35:21 -07002494 }
2495
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002497 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002498 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2499 // registered cell info, so return a NULL country instead.
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002502 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2503 // Get default phone in this case.
2504 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2505 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002506 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002508 if (phone == null) return "";
2509 ServiceStateTracker sst = phone.getServiceStateTracker();
2510 if (sst == null) return "";
2511 LocaleTracker lt = sst.getLocaleTracker();
2512 if (lt == null) return "";
2513 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2514 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2515 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002516 } finally {
2517 Binder.restoreCallingIdentity(identity);
2518 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -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 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 public void enableLocationUpdates() {
2530 mApp.enforceCallingOrSelfPermission(
2531 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002534 /**
2535 * This method was removed due to potential issues caused by performing partial
2536 * updates of service state, and lack of a credible use case.
2537 *
2538 * This has the ability to break the telephony implementation by disabling notification of
2539 * changes in device connectivity. DO NOT USE THIS!
2540 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 @Override
2542 public void disableLocationUpdates() {
2543 mApp.enforceCallingOrSelfPermission(
2544 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
Nathan Harold31d7ff32018-10-15 20:20:30 -07002547 /**
2548 * Returns the target SDK version number for a given package name.
2549 *
Nathan Haroldec184742019-07-10 17:04:16 -07002550 * This call MUST be invoked before clearing the calling UID.
2551 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002552 * @return target SDK if the package is found or INT_MAX.
2553 */
2554 private int getTargetSdk(String packageName) {
2555 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002556 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002557 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002558 if (ai != null) return ai.targetSdkVersion;
2559 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002560 loge("Failed to get package info for pkg="
2561 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002562 }
2563 return Integer.MAX_VALUE;
2564 }
2565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 @Override
2567 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002568 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2569 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002570 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002571 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2572 throw new SecurityException(
2573 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2574 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002575
Jordan Liu1617b712019-07-10 15:06:26 -07002576 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2578 return null;
2579 }
Svetoslav64fad262015-04-14 14:35:21 -07002580
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002581 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002583 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002584 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585
Nathan Haroldf180aac2018-06-01 18:43:55 -07002586 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2587 for (CellInfo ci : info) {
2588 if (ci instanceof CellInfoGsm) {
2589 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2590 } else if (ci instanceof CellInfoWcdma) {
2591 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002594 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002597 private List<CellInfo> getCachedCellInfo() {
2598 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2599 for (Phone phone : PhoneFactory.getPhones()) {
2600 List<CellInfo> info = phone.getAllCellInfo();
2601 if (info != null) cellInfos.addAll(info);
2602 }
2603 return cellInfos;
2604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605
2606 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002607 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002609 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002610
2611 LocationAccessPolicy.LocationPermissionResult locationResult =
2612 LocationAccessPolicy.checkLocationPermission(mApp,
2613 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2614 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002615 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002616 .setCallingPid(Binder.getCallingPid())
2617 .setCallingUid(Binder.getCallingUid())
2618 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002619 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002620 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2621 .build());
2622 switch (locationResult) {
2623 case DENIED_HARD:
2624 throw new SecurityException("Not allowed to access cell info");
2625 case DENIED_SOFT:
2626 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002629 final int targetSdk = getTargetSdk(callingPackage);
2630 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2631 return getCachedCellInfo();
2632 }
2633
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002634 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2639 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002640 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002641 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 if (info != null) cellInfos.addAll(info);
2643 }
2644 return cellInfos;
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648 }
2649
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002650 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002651 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2652 String callingFeatureId) {
2653 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2654 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002655 }
2656
2657 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002658 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2659 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002660 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002661 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002662 }
2663
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002664 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2665 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002666 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002667 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002668
2669 LocationAccessPolicy.LocationPermissionResult locationResult =
2670 LocationAccessPolicy.checkLocationPermission(mApp,
2671 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2672 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002673 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002674 .setCallingPid(Binder.getCallingPid())
2675 .setCallingUid(Binder.getCallingUid())
2676 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002677 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2678 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002679 .build());
2680 switch (locationResult) {
2681 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002682 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2683 // Safetynet logging for b/154934934
2684 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2685 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002686 throw new SecurityException("Not allowed to access cell info");
2687 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002688 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2689 // Safetynet logging for b/154934934
2690 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2691 }
Nathan Harold5320c422019-05-09 10:26:08 -07002692 try {
2693 cb.onCellInfo(new ArrayList<CellInfo>());
2694 } catch (RemoteException re) {
2695 // Drop without consequences
2696 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002697 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002698 }
2699
Nathan Harolda939a962019-05-09 10:13:47 -07002700
2701 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002702 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2703
2704 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2705 }
2706
2707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002709 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Shishir Agrawala9f32182016-04-12 12:00:16 -07002720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002721 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002722 Phone phone = PhoneFactory.getPhone(slotIndex);
2723 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002724 return null;
2725 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002726 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002727 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002728 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002729 return null;
2730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731
2732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 return phone.getImei();
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002738 }
2739
2740 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002741 public String getTypeAllocationCodeForSlot(int slotIndex) {
2742 Phone phone = PhoneFactory.getPhone(slotIndex);
2743 String tac = null;
2744 if (phone != null) {
2745 String imei = phone.getImei();
2746 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2747 }
2748 return tac;
2749 }
2750
2751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002752 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002753 Phone phone = PhoneFactory.getPhone(slotIndex);
2754 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002755 return null;
2756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757
Jeff Davidson913390f2018-02-23 17:11:49 -08002758 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002759 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002760 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002761 return null;
2762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 return phone.getMeid();
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
Jack Yu2af8d712017-03-15 17:14:14 -07002770 }
2771
2772 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002773 public String getManufacturerCodeForSlot(int slotIndex) {
2774 Phone phone = PhoneFactory.getPhone(slotIndex);
2775 String manufacturerCode = null;
2776 if (phone != null) {
2777 String meid = phone.getMeid();
2778 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2779 }
2780 return manufacturerCode;
2781 }
2782
2783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002784 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2785 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002786 Phone phone = PhoneFactory.getPhone(slotIndex);
2787 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 return null;
2789 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002790 int subId = phone.getSubId();
2791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 mApp, subId, callingPackage, callingFeatureId,
2793 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002794 return null;
2795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 return phone.getDeviceSvn();
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002803 }
2804
fionaxu43304da2017-11-27 22:51:16 -08002805 @Override
2806 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 final Phone phone = getPhone(subId);
2810 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
fionaxu43304da2017-11-27 22:51:16 -08002814 }
2815
2816 @Override
2817 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 return phone == null ? null : phone.getCarrierName();
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
2824 }
fionaxu43304da2017-11-27 22:51:16 -08002825 }
2826
calvinpanffe225e2018-11-01 19:43:06 +08002827 @Override
chen xu0026ca62019-03-06 15:28:50 -08002828 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone phone = getPhone(subId);
2832 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002833 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002834 } finally {
2835 Binder.restoreCallingIdentity(identity);
2836 }
2837 }
2838
2839 @Override
chen xu0026ca62019-03-06 15:28:50 -08002840 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002844 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
2848 }
2849
chen xu651eec72018-11-11 19:03:44 -08002850 @Override
chen xu864e11c2018-12-06 22:10:03 -08002851 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2852 if (!isSubscriptionMccMnc) {
2853 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2854 }
chen xu651eec72018-11-11 19:03:44 -08002855 final Phone phone = PhoneFactory.getPhone(slotIndex);
2856 if (phone == null) {
2857 return TelephonyManager.UNKNOWN_CARRIER_ID;
2858 }
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
2865 }
2866
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 //
2868 // Internal helper methods.
2869 //
2870
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002871 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2873 *
2874 * @throws SecurityException if the caller does not have the required permission
2875 */
2876 private void enforceModifyPermission() {
2877 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2878 }
2879
Shuo Qiancd19c462020-01-16 20:51:11 -08002880 /**
2881 * Make sure the caller is system.
2882 *
2883 * @throws SecurityException if the caller is not system.
2884 */
2885 private void enforceSystemCaller() {
2886 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2887 throw new SecurityException("Caller must be system");
2888 }
2889 }
2890
Shuo Qian3b6ee772019-11-13 17:43:31 -08002891 private void enforceActiveEmergencySessionPermission() {
2892 mApp.enforceCallingOrSelfPermission(
2893 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2894 }
2895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 /**
2897 * Make sure the caller has the CALL_PHONE permission.
2898 *
2899 * @throws SecurityException if the caller does not have the required permission
2900 */
2901 private void enforceCallPermission() {
2902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2903 }
2904
paulhu5a773602019-08-23 19:17:33 +08002905 private void enforceSettingsPermission() {
2906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002907 }
2908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 private String createTelUrl(String number) {
2910 if (TextUtils.isEmpty(number)) {
2911 return null;
2912 }
2913
Jake Hambye994d462014-02-03 13:10:13 -08002914 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 }
2916
Ihab Awadf9e92732013-12-05 18:02:52 -08002917 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2919 }
2920
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002921 private static void logv(String msg) {
2922 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2923 }
2924
Ihab Awadf9e92732013-12-05 18:02:52 -08002925 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2927 }
2928
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002929 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002931 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002932 }
2933
Sanket Padawe356d7632015-06-22 14:03:32 -07002934 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002935 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 final Phone phone = PhoneFactory.getPhone(slotIndex);
2939 if (phone == null) {
2940 return PhoneConstants.PHONE_TYPE_NONE;
2941 } else {
2942 return phone.getPhoneType();
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 /**
2950 * Returns the CDMA ERI icon index to display
2951 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002953 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2954 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2955 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002956 }
2957
Sanket Padawe356d7632015-06-22 14:03:32 -07002958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002959 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002962 mApp, subId, callingPackage, callingFeatureId,
2963 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002964 return -1;
2965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 final Phone phone = getPhone(subId);
2970 if (phone != null) {
2971 return phone.getCdmaEriIconIndex();
2972 } else {
2973 return -1;
2974 }
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 }
2979
2980 /**
2981 * Returns the CDMA ERI icon mode,
2982 * 0 - ON
2983 * 1 - FLASHING
2984 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002986 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2987 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2988 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002989 }
2990
Sanket Padawe356d7632015-06-22 14:03:32 -07002991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002992 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2993 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002995 mApp, subId, callingPackage, callingFeatureId,
2996 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002997 return -1;
2998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 final Phone phone = getPhone(subId);
3003 if (phone != null) {
3004 return phone.getCdmaEriIconMode();
3005 } else {
3006 return -1;
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
3013 /**
3014 * Returns the CDMA ERI text,
3015 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003016 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003017 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3018 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3019 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003020 }
3021
Sanket Padawe356d7632015-06-22 14:03:32 -07003022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003023 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3024 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003026 mApp, subId, callingPackage, callingFeatureId,
3027 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003028 return null;
3029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 final Phone phone = getPhone(subId);
3034 if (phone != null) {
3035 return phone.getCdmaEriText();
3036 } else {
3037 return null;
3038 }
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 }
3043
3044 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003045 * Returns the CDMA MDN.
3046 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003047 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003048 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3050 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 return phone.getLine1Number();
3057 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 return null;
3060 }
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003063 }
3064 }
3065
3066 /**
3067 * Returns the CDMA MIN.
3068 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003069 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003070 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3072 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final Phone phone = getPhone(subId);
3077 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3078 return phone.getCdmaMin();
3079 } else {
3080 return null;
3081 }
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003084 }
3085 }
3086
Hall Liud892bec2018-11-30 14:51:45 -08003087 @Override
3088 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3089 INumberVerificationCallback callback, String callingPackage) {
3090 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3091 != PERMISSION_GRANTED) {
3092 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3093 }
3094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3095
3096 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3097 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3098 throw new SecurityException("Calling package must be configured in the device config");
3099 }
3100
3101 if (range == null) {
3102 throw new NullPointerException("Range must be non-null");
3103 }
3104
3105 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003106 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003107
3108 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3109 }
3110
Junda Liuca05d5d2014-08-14 22:36:34 -07003111 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 * Returns true if CDMA provisioning needs to run.
3113 */
3114 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003117 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003124 * Sets the voice mail number of a given subId.
3125 */
3126 @Override
3127 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3129 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3134 new Pair<String, String>(alphaTag, number), new Integer(subId));
3135 return success;
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003139 }
3140
Ta-wei Yen87c49842016-05-13 21:19:52 -07003141 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003142 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3143 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003144 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3145 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003146 if (!TextUtils.equals(callingPackage, systemDialer)) {
3147 throw new SecurityException("caller must be system dialer");
3148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3153 if (phoneAccountHandle == null) {
3154 return null;
3155 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003156 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003159 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003160 }
3161
3162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003163 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3164 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003167 mApp, subId, callingPackage, callingFeatureId,
3168 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003169 return null;
3170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003172 final long identity = Binder.clearCallingIdentity();
3173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003178 }
3179
3180 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003181 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3182 VisualVoicemailSmsFilterSettings settings) {
3183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 mApp, callingPackage, subId, settings);
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 void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003205 }
3206
3207 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003208 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3209 String callingPackage, int subId) {
3210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003219 }
3220
3221 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003222 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003232 }
3233
3234 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003235 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3236 String callingAttributionTag, int subId, String number, int port, String text,
3237 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003239 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003240 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003241 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003242 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3243 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003244 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003245
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003246 /**
fionaxu0152e512016-11-14 13:36:14 -08003247 * Sets the voice activation state of a given subId.
3248 */
3249 @Override
3250 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3252 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253
3254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 final Phone phone = getPhone(subId);
3257 if (phone != null) {
3258 phone.setVoiceActivationState(activationState);
3259 } else {
3260 loge("setVoiceActivationState fails with invalid subId: " + subId);
3261 }
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003264 }
3265 }
3266
3267 /**
3268 * Sets the data activation state of a given subId.
3269 */
3270 @Override
3271 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3273 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 final Phone phone = getPhone(subId);
3278 if (phone != null) {
3279 phone.setDataActivationState(activationState);
3280 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003281 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 }
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003285 }
3286 }
3287
3288 /**
3289 * Returns the voice activation state of a given subId.
3290 */
3291 @Override
3292 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
fionaxu0152e512016-11-14 13:36:14 -08003295 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (phone != null) {
3299 return phone.getVoiceActivationState();
3300 } else {
3301 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3302 }
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003305 }
3306 }
3307
3308 /**
3309 * Returns the data activation state of a given subId.
3310 */
3311 @Override
3312 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314
fionaxu0152e512016-11-14 13:36:14 -08003315 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 if (phone != null) {
3319 return phone.getDataActivationState();
3320 } else {
3321 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3322 }
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003325 }
3326 }
3327
3328 /**
Wink Saville36469e72014-06-11 15:17:00 -07003329 * Returns the unread count of voicemails for a subId
3330 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003331 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003332 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3333 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003335 mApp, subId, callingPackage, callingFeatureId,
3336 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003337 return 0;
3338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 final Phone phone = getPhone(subId);
3342 if (phone != null) {
3343 return phone.getVoiceMessageCount();
3344 } else {
3345 return 0;
3346 }
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
3352 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003353 * returns true, if the device is in a state where both voice and data
3354 * are supported simultaneously. This can change based on location or network condition.
3355 */
3356 @Override
3357 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = getPhone(subId);
3361 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003365 }
3366
3367 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003368 * Send the dialer code if called from the current default dialer or the caller has
3369 * carrier privilege.
3370 * @param inputCode The dialer code to send
3371 */
3372 @Override
3373 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003374 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003376 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3377 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003378 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003379 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003380 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
fionaxu235cc5e2017-03-06 22:25:57 -08003389 }
3390
Pengquan Menga1bb6272018-09-06 09:59:22 -07003391 @Override
3392 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003393 TelephonyPermissions
3394 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3395 mApp, subId, "getNetworkSelectionMode");
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 if (!isActiveSubscription(subId)) {
3399 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3400 }
3401 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3402 } finally {
3403 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003404 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003405 }
3406
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003408 public boolean isInEmergencySmsMode() {
3409 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 for (Phone phone : PhoneFactory.getPhones()) {
3413 if (phone.isInEmergencySmsMode()) {
3414 return true;
3415 }
3416 }
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 return false;
3421 }
3422
shilu366312e2019-12-17 09:28:10 -08003423 /**
3424 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3425 * @param subId The subscription to use to check the configuration.
3426 * @param c The callback that will be used to send the result.
3427 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003428 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003429 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3430 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003431 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3432 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003433
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003434 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3435 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3436 "IMS not available on device.");
3437 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003438 final long token = Binder.clearCallingIdentity();
3439 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
3444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 } finally {
3446 Binder.restoreCallingIdentity(token);
3447 }
3448 }
3449
shilu366312e2019-12-17 09:28:10 -08003450 /**
3451 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3452 * @param subId The subscription to use to check the configuration.
3453 * @param c The callback that will be used to send the result.
3454 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003456 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003457 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3458 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3460 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3461 }
Meng Wangafbc5852019-09-19 17:37:13 -07003462 final long token = Binder.clearCallingIdentity();
3463 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003464 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003465 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3466 .removeRegistrationCallbackForSubscription(c, subId);
3467 } catch (ImsException e) {
3468 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3469 + "is inactive, ignoring unregister.");
3470 // If the subscription is no longer active, just return, since the callback
3471 // will already have been removed internally.
3472 } finally {
3473 Binder.restoreCallingIdentity(token);
3474 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003475 }
3476
Brad Ebingera34a6c22019-10-22 17:36:18 -07003477 /**
3478 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3479 */
3480 @Override
3481 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3482 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3483 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3484 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3485 "IMS not available on device.");
3486 }
3487 final long token = Binder.clearCallingIdentity();
3488 try {
3489 Phone phone = getPhone(subId);
3490 if (phone == null) {
3491 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3492 + subId + "'");
3493 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3494 }
3495 phone.getImsRegistrationState(regState -> {
3496 try {
3497 consumer.accept((regState == null)
3498 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3499 } catch (RemoteException e) {
3500 // Ignore if the remote process is no longer available to call back.
3501 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3502 }
3503 });
3504 } finally {
3505 Binder.restoreCallingIdentity(token);
3506 }
3507 }
3508
3509 /**
3510 * Get the transport type for the IMS service registration state.
3511 */
3512 @Override
3513 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003514 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3515 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003516 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3517 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3518 "IMS not available on device.");
3519 }
3520 final long token = Binder.clearCallingIdentity();
3521 try {
3522 Phone phone = getPhone(subId);
3523 if (phone == null) {
3524 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3525 + subId + "'");
3526 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3527 }
3528 phone.getImsRegistrationTech(regTech -> {
3529 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3530 int regTechConverted = (regTech == null)
3531 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3532 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3533 regTechConverted);
3534 try {
3535 consumer.accept(regTechConverted);
3536 } catch (RemoteException e) {
3537 // Ignore if the remote process is no longer available to call back.
3538 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3539 }
3540 });
3541 } finally {
3542 Binder.restoreCallingIdentity(token);
3543 }
3544 }
3545
shilu366312e2019-12-17 09:28:10 -08003546 /**
3547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3548 * @param subId The subscription to use to check the configuration.
3549 * @param c The callback that will be used to send the result.
3550 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003552 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3553 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003554 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3555 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003556 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3557 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3558 "IMS not available on device.");
3559 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3561 final long token = Binder.clearCallingIdentity();
3562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003563 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003565 } catch (ImsException e) {
3566 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 } finally {
3568 Binder.restoreCallingIdentity(token);
3569 }
3570 }
3571
shilu366312e2019-12-17 09:28:10 -08003572 /**
3573 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3574 * @param subId The subscription to use to check the configuration.
3575 * @param c The callback that will be used to send the result.
3576 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003578 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003579 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3580 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003581 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3582 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3583 }
Meng Wangafbc5852019-09-19 17:37:13 -07003584
3585 final long token = Binder.clearCallingIdentity();
3586 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003587 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003589 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003590 } catch (ImsException e) {
3591 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3592 + "is inactive, ignoring unregister.");
3593 // If the subscription is no longer active, just return, since the callback
3594 // will already have been removed internally.
3595 } finally {
3596 Binder.restoreCallingIdentity(token);
3597 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 }
3599
3600 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003601 public boolean isCapable(int subId, int capability, int regTech) {
3602 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3604 final long token = Binder.clearCallingIdentity();
3605 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3610 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003612 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3613 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 } finally {
3615 Binder.restoreCallingIdentity(token);
3616 }
3617 }
3618
3619 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003620 public boolean isAvailable(int subId, int capability, int regTech) {
3621 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 final long token = Binder.clearCallingIdentity();
3623 try {
3624 Phone phone = getPhone(subId);
3625 if (phone == null) return false;
3626 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003627 } catch (com.android.ims.ImsException e) {
3628 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3629 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(token);
3632 }
3633 }
3634
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003635 /**
3636 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3637 * subscription.
3638 * @param subId The subscription to use to check the configuration.
3639 * @param callback The callback that will be used to send the result.
3640 * @param capability The MmTelFeature capability that will be used to send the result.
3641 * @param transportType The transport type of the MmTelFeature capability.
3642 */
3643 @Override
3644 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3645 int transportType) {
3646 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3647 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3649 "IMS not available on device.");
3650 }
3651 final long token = Binder.clearCallingIdentity();
3652 try {
3653 int slotId = getSlotIndex(subId);
3654 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3655 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3656 + subId + "'");
3657 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3658 }
3659 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3660 transportType, aBoolean -> {
3661 try {
3662 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3663 } catch (RemoteException e) {
3664 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3665 + "running. Ignore");
3666 }
3667 });
3668 } finally {
3669 Binder.restoreCallingIdentity(token);
3670 }
3671 }
3672
shilu366312e2019-12-17 09:28:10 -08003673 /**
3674 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3675 * @param subId The subscription to use to check the configuration.
3676 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 @Override
3678 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003679 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3680 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003681
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3683 final long token = Binder.clearCallingIdentity();
3684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003685 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003687 } catch (ImsException e) {
3688 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 } finally {
3690 Binder.restoreCallingIdentity(token);
3691 }
3692 }
3693
3694 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003695 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003697 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003703 } catch (ImsException e) {
3704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
shilu366312e2019-12-17 09:28:10 -08003710 /**
3711 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3712 * @param subId The subscription to use to check the configuration.
3713 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003715 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003716 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3717 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3722 } catch (ImsException e) {
3723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
3729 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003730 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003732 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003736 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003737 } catch (ImsException e) {
3738 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
3742 }
3743
shilu366312e2019-12-17 09:28:10 -08003744 /**
3745 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3746 * @param subId The subscription to use to check the configuration.
3747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 @Override
3749 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003750 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3751 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003757 } catch (ImsException e) {
3758 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 } finally {
3760 Binder.restoreCallingIdentity(identity);
3761 }
3762 }
3763
3764 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003765 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003767 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003772 } catch (ImsException e) {
3773 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
3777 }
3778
shilu366312e2019-12-17 09:28:10 -08003779 /**
3780 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3781 * @param subId The subscription to use to check the configuration.
3782 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 @Override
3784 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003785 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3786 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003792 } catch (ImsException e) {
3793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
3797 }
3798
3799 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003800 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003802 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003806 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003808 } catch (ImsException e) {
3809 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
3813 }
3814
3815 @Override
3816 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3818 "setVoWiFiNonPersistent");
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003823 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003824 } catch (ImsException e) {
3825 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
3829 }
3830
shilu366312e2019-12-17 09:28:10 -08003831 /**
3832 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3833 * @param subId The subscription to use to check the configuration.
3834 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 @Override
3836 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003837 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3838 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003842 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003844 } catch (ImsException e) {
3845 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
3849 }
3850
3851 @Override
3852 public void setVoWiFiModeSetting(int subId, int mode) {
3853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3854 "setVoWiFiModeSetting");
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003858 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003860 } catch (ImsException e) {
3861 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
3865 }
3866
3867 @Override
3868 public int getVoWiFiRoamingModeSetting(int subId) {
3869 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003873 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 } catch (ImsException e) {
3876 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
3880 }
3881
3882 @Override
3883 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3885 "setVoWiFiRoamingModeSetting");
3886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (ImsException e) {
3892 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
3896 }
3897
3898 @Override
3899 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3901 "setRttCapabilityEnabled");
3902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003905 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3906 } catch (ImsException e) {
3907 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
3911 }
3912
shilu366312e2019-12-17 09:28:10 -08003913 /**
3914 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3915 * @param subId The subscription to use to check the configuration.
3916 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 @Override
3918 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003919 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3920 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (ImsException e) {
3927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 }
3932
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003933 @Override
3934 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3935 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3936 final long identity = Binder.clearCallingIdentity();
3937 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003938 if (!isImsAvailableOnDevice()) {
3939 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3940 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003941 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003944 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003945 } catch (ImsException e) {
3946 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951
3952 @Override
3953 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3954 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3955 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003956 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3957 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3958 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003959 try {
3960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003961 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003962 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003963 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003964 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3965 + "is inactive, ignoring unregister.");
3966 // If the subscription is no longer active, just return, since the callback will already
3967 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
3971 }
3972
allenwtsu99c623b2020-01-03 18:24:23 +08003973
3974 private void checkModifyPhoneStatePermission(int subId, String message) {
3975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3976 message);
3977 }
3978
3979 private boolean isImsProvisioningRequired(int subId, int capability,
3980 boolean isMmtelCapability) {
3981 Phone phone = getPhone(subId);
3982 if (phone == null) {
3983 loge("phone instance null for subid " + subId);
3984 return false;
3985 }
3986 if (isMmtelCapability) {
3987 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3988 return false;
3989 }
3990 } else {
3991 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3992 return false;
3993 }
3994 }
3995 return true;
3996 }
3997
3998 @Override
3999 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4000 boolean isProvisioned) {
4001 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4006 if (!isImsProvisioningRequired(subId, capability, false)) {
4007 return;
4008 }
4009
4010 // this capability requires provisioning, route to the correct API.
4011 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4012 switch (capability) {
4013 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4014 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4015 ims.setEabProvisioned(isProvisioned);
4016 break;
4017 default: {
4018 throw new IllegalArgumentException("Tried to set provisioning for "
4019 + "rcs capability '" + capability + "', which does not require "
4020 + "provisioning.");
4021 }
4022 }
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
4026
4027 }
4028
4029
4030 @Override
4031 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4032 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4036 if (!isImsProvisioningRequired(subId, capability, false)) {
4037 return true;
4038 }
4039
4040 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4041 switch (capability) {
4042 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4043 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4044 return ims.isEabProvisionedOnDevice();
4045
4046 default: {
4047 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4048 + "capability '" + capability + "', which does not require "
4049 + "provisioning.");
4050 }
4051 }
4052
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
4056 }
4057
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004058 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004059 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4060 boolean isProvisioned) {
4061 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4062 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4063 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4064 }
allenwtsu99c623b2020-01-03 18:24:23 +08004065 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004069 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004070 return;
4071 }
4072
4073 // this capability requires provisioning, route to the correct API.
4074 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4075 switch (capability) {
4076 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4077 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4078 ims.setVolteProvisioned(isProvisioned);
4079 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4080 ims.setWfcProvisioned(isProvisioned);
4081 }
4082 break;
4083 }
4084 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4085 // There is currently no difference in VT provisioning type.
4086 ims.setVtProvisioned(isProvisioned);
4087 break;
4088 }
4089 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4090 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4091 // change the capability of the feature instead if needed.
4092 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4093 == isProvisioned) {
4094 // No change in provisioning.
4095 return;
4096 }
4097 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4098 try {
4099 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004100 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004101 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4102 + ", Exception" + e.getMessage());
4103 }
4104 break;
4105 }
4106 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004107 throw new IllegalArgumentException("Tried to set provisioning for "
4108 + "MmTel capability '" + capability + "', which does not require "
4109 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 }
4111 }
4112
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117
4118 @Override
4119 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4120 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4121 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4122 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4123 }
4124 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004128 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 return true;
4130 }
4131
4132 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4133 switch (capability) {
4134 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4135 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4136 return ims.isVolteProvisionedOnDevice();
4137 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4138 return ims.isWfcProvisionedOnDevice();
4139 }
4140 // This should never happen, since we are checking tech above to make sure it
4141 // is either LTE or IWLAN.
4142 throw new IllegalArgumentException("Invalid radio technology for voice "
4143 + "capability.");
4144 }
4145 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4146 // There is currently no difference in VT provisioning type.
4147 return ims.isVtProvisionedOnDevice();
4148 }
4149 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4150 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4151 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4152 }
4153 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004154 throw new IllegalArgumentException(
4155 "Tried to get provisioning for MmTel capability '" + capability
4156 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004157 }
4158 }
4159
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4167 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4168 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4169 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4170 }
4171 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4172 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4173 return (provisionedBits & capability) > 0;
4174 }
4175
4176 @Override
4177 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4178 boolean isProvisioned) {
4179 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4180 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4181 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4182 }
4183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4184 "setProvisioningStatusForCapability");
4185 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4186 // If the current provisioning status for capability already matches isProvisioned,
4187 // do nothing.
4188 if (((provisionedBits & capability) > 0) == isProvisioned) {
4189 return;
4190 }
4191 if (isProvisioned) {
4192 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4193 } else {
4194 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4195 }
4196 }
4197
4198 /**
4199 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4200 * technology. The bitfield should mirror the bitfield defined by
4201 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4202 */
4203 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4204 String key = getMmTelProvisioningKey(subId, tech);
4205 // Default is no capabilities are provisioned.
4206 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4207 }
4208
4209 /**
4210 * Sets the MmTel capability provisioning bitfield (defined by
4211 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4212 * technology specified.
4213 *
4214 * Note: This is a synchronous command and should not be called on UI thread.
4215 */
4216 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4217 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4218 String key = getMmTelProvisioningKey(subId, tech);
4219 editor.putInt(key, newField);
4220 editor.commit();
4221 }
4222
4223 private static String getMmTelProvisioningKey(int subId, int tech) {
4224 // resulting key is provision_ims_mmtel_{subId}_{tech}
4225 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4226 }
4227
4228 /**
4229 * Query CarrierConfig to see if the specified capability requires provisioning for the
4230 * carrier associated with the subscription id.
4231 */
4232 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4233 int capability) {
4234 CarrierConfigManager configManager = new CarrierConfigManager(context);
4235 PersistableBundle c = configManager.getConfigForSubId(subId);
4236 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004237 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004238 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4239 false);
4240 boolean requireVoiceVtProvisioning = c.getBoolean(
4241 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4242
4243 // First check to make sure that the capability requires provisioning.
4244 switch (capability) {
4245 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4246 // intentional fallthrough
4247 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4248 if (requireVoiceVtProvisioning) {
4249 // Voice and Video requires provisioning
4250 return true;
4251 }
4252 break;
4253 }
4254 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4255 if (requireUtProvisioning) {
4256 // UT requires provisioning
4257 return true;
4258 }
4259 break;
4260 }
4261 }
4262 return false;
4263 }
4264
allenwtsu99c623b2020-01-03 18:24:23 +08004265 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4266 int capability) {
4267 CarrierConfigManager configManager = new CarrierConfigManager(context);
4268 PersistableBundle c = configManager.getConfigForSubId(subId);
4269
4270 boolean requireRcsProvisioning = c.getBoolean(
4271 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4272
4273 // First check to make sure that the capability requires provisioning.
4274 switch (capability) {
4275 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4276 // intentional fallthrough
4277 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4278 if (requireRcsProvisioning) {
4279 // OPTION or PRESENCE requires provisioning
4280 return true;
4281 }
4282 break;
4283 }
4284 }
4285 return false;
4286 }
4287
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004288 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004289 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4291 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4292 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004293 enforceReadPrivilegedPermission("getImsProvisioningInt");
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004297 int slotId = getSlotIndex(subId);
4298 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4299 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4300 + subId + "' for key:" + key);
4301 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4302 }
4303 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004304 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004305 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4306 + subId + "' for key:" + key);
4307 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
4313 @Override
4314 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4316 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4317 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004318 enforceReadPrivilegedPermission("getImsProvisioningString");
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004322 int slotId = getSlotIndex(subId);
4323 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4324 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4325 + subId + "' for key:" + key);
4326 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4327 }
4328 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004329 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004330 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4331 + subId + "' for key:" + key);
4332 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
4338 @Override
4339 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4341 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4342 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4344 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 int slotId = getSlotIndex(subId);
4349 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4350 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4351 + subId + "' for key:" + key);
4352 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4353 }
4354 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004356 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4357 + "' for key:" + key);
4358 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
4364 @Override
4365 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4367 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4368 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4370 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004374 int slotId = getSlotIndex(subId);
4375 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4376 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4377 + subId + "' for key:" + key);
4378 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4379 }
4380 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004381 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004382 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4383 + "' for key:" + key);
4384 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
4388 }
4389
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004390 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 int slotId = SubscriptionManager.getSlotIndex(subId);
4392 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4394 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 }
4396 return slotId;
4397 }
4398
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004399 private int getSlotIndex(int subId) {
4400 int slotId = SubscriptionManager.getSlotIndex(subId);
4401 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4402 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4403 }
4404 return slotId;
4405 }
4406
Wink Saville36469e72014-06-11 15:17:00 -07004407 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004408 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004409 */
4410 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004411 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4412 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004413 final int targetSdk = getTargetSdk(callingPackage);
4414 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004415 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004416 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004417 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004418 mApp, subId, callingPackage, callingFeatureId,
4419 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004420 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4421 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 final Phone phone = getPhone(subId);
4426 if (phone != null) {
4427 return phone.getServiceState().getDataNetworkType();
4428 } else {
4429 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4430 }
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004434 }
4435
4436 /**
4437 * Returns the data network type
4438 */
4439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004440 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4441 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4442 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004443 }
4444
4445 /**
4446 * Returns the data network type for a subId
4447 */
4448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004449 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4450 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004452 mApp, subId, callingPackage, callingFeatureId,
4453 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004454 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4455 }
4456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 final Phone phone = getPhone(subId);
4460 if (phone != null) {
4461 return phone.getServiceState().getDataNetworkType();
4462 } else {
4463 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4464 }
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004468 }
4469
4470 /**
Wink Saville36469e72014-06-11 15:17:00 -07004471 * Returns the Voice network type for a subId
4472 */
4473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004474 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4475 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004477 mApp, subId, callingPackage, callingFeatureId,
4478 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004479 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4480 }
4481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 final Phone phone = getPhone(subId);
4485 if (phone != null) {
4486 return phone.getServiceState().getVoiceNetworkType();
4487 } else {
4488 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4489 }
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004493 }
4494
4495 /**
4496 * @return true if a ICC card is present
4497 */
4498 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004499 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004500 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4501 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004502 }
4503
4504 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004505 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004506 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004507 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004508 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
4511 final Phone phone = PhoneFactory.getPhone(slotIndex);
4512 if (phone != null) {
4513 return phone.getIccCard().hasIccCard();
4514 } else {
4515 return false;
4516 }
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004520 }
4521
4522 /**
4523 * Return if the current radio is LTE on CDMA. This
4524 * is a tri-state return value as for a period of time
4525 * the mode may be unknown.
4526 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004527 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004528 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004529 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004530 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004532 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4533 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4534 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004535 }
4536
Sanket Padawe356d7632015-06-22 14:03:32 -07004537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004538 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4539 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004540 try {
4541 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4542 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004543 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4544 }
4545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 final Phone phone = getPhone(subId);
4549 if (phone == null) {
4550 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4551 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004552 return TelephonyProperties.lte_on_cdma_device()
4553 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 }
4555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004557 }
Wink Saville36469e72014-06-11 15:17:00 -07004558 }
4559
Wink Saville36469e72014-06-11 15:17:00 -07004560 /**
4561 * {@hide}
4562 * Returns Default subId, 0 in the case of single standby.
4563 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004564 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004565 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004566 }
4567
Shishir Agrawala9f32182016-04-12 12:00:16 -07004568 private int getSlotForDefaultSubscription() {
4569 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4570 }
4571
Wink Savilleb564aae2014-10-23 10:18:09 -07004572 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004573 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004574 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004575
Pengquan Menge92a50d2018-09-21 15:54:48 -07004576 private boolean isActiveSubscription(int subId) {
4577 return mSubscriptionController.isActiveSubId(subId);
4578 }
4579
Ihab Awadf2177b72013-11-25 13:33:23 -08004580 /**
4581 * @see android.telephony.TelephonyManager.WifiCallingChoices
4582 */
4583 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 final long identity = Binder.clearCallingIdentity();
4585 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004586 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4588 getWhenToMakeWifiCallsDefaultPreference());
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004592 }
4593
4594 /**
4595 * @see android.telephony.TelephonyManager.WifiCallingChoices
4596 */
4597 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004601 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004606 }
4607
Sailesh Nepald1e68152013-12-12 19:08:02 -08004608 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004609 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004610 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004611 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004612
Jordan Liu4c733742019-02-28 12:03:40 -08004613 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4614 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4615 if (phoneId == -1) {
4616 throw new IllegalArgumentException("Given slot index: " + slotIndex
4617 + " does not correspond to an active phone");
4618 }
4619 return PhoneFactory.getPhone(phoneId);
4620 }
4621
Shishir Agrawal566b7612013-10-28 14:41:00 -07004622 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004623 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4624 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4626 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004628 if (DBG) {
4629 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4630 }
4631 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4632 p2);
4633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004634
Jordan Liu4c733742019-02-28 12:03:40 -08004635
4636 @Override
4637 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4638 int slotIndex, String callingPackage, String aid, int p2) {
4639 enforceModifyPermission();
4640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4641 if (DBG) {
4642 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4643 }
4644 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4645 callingPackage, aid, p2);
4646 }
4647
4648 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4649 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 if (TextUtils.equals(ISDR_AID, aid)) {
4653 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004654 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4655 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 if (bestComponent == null
4657 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4658 loge("The calling package is not allowed to access ISD-R.");
4659 throw new SecurityException(
4660 "The calling package is not allowed to access ISD-R.");
4661 }
Derek Tan740e1672017-06-27 14:56:27 -07004662 }
Derek Tan740e1672017-06-27 14:56:27 -07004663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004665 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4666 null /* workSource */);
4667 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 return response;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004672 }
4673
4674 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004675 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4677 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004678 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4679 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4680 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004681
Jordan Liu4c733742019-02-28 12:03:40 -08004682 @Override
4683 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4684 enforceModifyPermission();
4685 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4686 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4687 channel);
4688 }
4689
4690 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 if (channel < 0) {
4694 return false;
4695 }
Jordan Liu4c733742019-02-28 12:03:40 -08004696 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4697 null /* workSource */);
4698 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699 return success;
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004702 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004703 }
4704
4705 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004706 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004707 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4709 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004710 if (DBG) {
4711 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4712 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4713 + p3 + " data=" + data);
4714 }
4715 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4716 command, p1, p2, p3, data);
4717 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004718
Jordan Liu4c733742019-02-28 12:03:40 -08004719 @Override
4720 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4721 int command, int p1, int p2, int p3, String data) {
4722 enforceModifyPermission();
4723 if (DBG) {
4724 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4725 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4726 + p3 + " data=" + data);
4727 }
4728 return iccTransmitApduLogicalChannelWithPermission(
4729 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4730 data);
4731 }
4732
4733 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4734 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004737 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 return "";
4739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004742 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4743 null /* workSource */);
4744 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 // Append the returned status code to the end of the response payload.
4747 String s = Integer.toHexString(
4748 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4749 if (response.payload != null) {
4750 s = IccUtils.bytesToHexString(response.payload) + s;
4751 }
4752 return s;
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004756 }
Jake Hambye994d462014-02-03 13:10:13 -08004757
Evan Charltonc66da362014-05-16 14:06:40 -07004758 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004759 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4760 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4762 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004764 if (DBG) {
4765 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4766 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4767 }
4768 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4769 cla, command, p1, p2, p3, data);
4770 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004771
Jordan Liu4c733742019-02-28 12:03:40 -08004772 @Override
4773 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4774 int command, int p1, int p2, int p3, String data) {
4775 enforceModifyPermission();
4776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4777 if (DBG) {
4778 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4779 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4780 + " data=" + data);
4781 }
4782
4783 return iccTransmitApduBasicChannelWithPermission(
4784 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4785 p2, p3, data);
4786 }
4787
4788 // open APDU basic channel assuming the caller has sufficient permissions
4789 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4790 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4794 && TextUtils.equals(ISDR_AID, data)) {
4795 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004796 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4797 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 if (bestComponent == null
4799 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4800 loge("The calling package is not allowed to select ISD-R.");
4801 throw new SecurityException(
4802 "The calling package is not allowed to select ISD-R.");
4803 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004804 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004807 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4808 null /* workSource */);
4809 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 // Append the returned status code to the end of the response payload.
4812 String s = Integer.toHexString(
4813 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4814 if (response.payload != null) {
4815 s = IccUtils.bytesToHexString(response.payload) + s;
4816 }
4817 return s;
4818 } finally {
4819 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004820 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004821 }
4822
4823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004824 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004825 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4827 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 if (DBG) {
4832 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4833 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4834 }
4835
4836 IccIoResult response =
4837 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4838 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4839 subId);
4840
4841 if (DBG) {
4842 log("Exchange SIM_IO [R]" + response);
4843 }
4844
4845 byte[] result = null;
4846 int length = 2;
4847 if (response.payload != null) {
4848 length = 2 + response.payload.length;
4849 result = new byte[length];
4850 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4851 } else {
4852 result = new byte[length];
4853 }
4854
4855 result[length - 1] = (byte) response.sw2;
4856 result[length - 2] = (byte) response.sw1;
4857 return result;
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004860 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004861 }
4862
Nathan Haroldb3014052017-01-25 15:57:32 -08004863 /**
4864 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4865 * on a particular subscription
4866 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004867 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4868 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004870 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004871 return null;
4872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 if (appType != TelephonyManager.APPTYPE_USIM
4877 && appType != TelephonyManager.APPTYPE_SIM) {
4878 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4879 return null;
4880 }
4881 Object response = sendRequest(
4882 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4883 if (response instanceof String[]) {
4884 return (String[]) response;
4885 }
yincheng zhao2737e882019-09-06 17:06:54 -07004886 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004888 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 } finally {
4890 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004891 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004892 }
4893
yincheng zhao2737e882019-09-06 17:06:54 -07004894 /**
4895 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4896 * subscription.
4897 *
4898 * @param subId the id of the subscription.
4899 * @param appType the uicc app type, must be USIM or SIM.
4900 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4901 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004902 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004903 * @return number of fplmns that is successfully written to the SIM.
4904 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004905 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4906 String callingFeatureId) {
4907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4908 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004909 if (DBG) logv("no permissions for setForbiddenplmns");
4910 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4911 }
4912 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4913 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4914 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4915 }
4916 if (fplmns == null) {
4917 throw new IllegalArgumentException("Fplmn List provided is null");
4918 }
4919 for (String fplmn : fplmns) {
4920 if (!CellIdentity.isValidPlmn(fplmn)) {
4921 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4922 }
4923 }
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 Object response = sendRequest(
4927 CMD_SET_FORBIDDEN_PLMNS,
4928 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4929 subId);
4930 return (int) response;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004936 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004937 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4939 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4944 if (response.payload == null) {
4945 return "";
4946 }
Evan Charltonc66da362014-05-16 14:06:40 -07004947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 // Append the returned status code to the end of the response payload.
4949 String s = Integer.toHexString(
4950 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4951 s = IccUtils.bytesToHexString(response.payload) + s;
4952 return s;
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Evan Charltonc66da362014-05-16 14:06:40 -07004956 }
4957
Jake Hambye994d462014-02-03 13:10:13 -08004958 /**
4959 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4960 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4961 *
4962 * @param itemID the ID of the item to read
4963 * @return the NV item as a String, or null on error.
4964 */
4965 @Override
4966 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4969 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970
4971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004974 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4976 return value;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
Jake Hambye994d462014-02-03 13:10:13 -08004980 }
4981
4982 /**
4983 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4984 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4985 *
4986 * @param itemID the ID of the item to read
4987 * @param itemValue the value to write, as a String
4988 * @return true on success; false on any failure
4989 */
4990 @Override
4991 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4994 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995
4996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4999 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005000 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5002 return success;
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
Jake Hambye994d462014-02-03 13:10:13 -08005006 }
5007
5008 /**
5009 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5010 * Used for device configuration by some CDMA operators.
5011 *
5012 * @param preferredRoamingList byte array containing the new PRL
5013 * @return true on success; false on any failure
5014 */
5015 @Override
5016 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5018 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019
5020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5023 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5024 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5025 return success;
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
Jake Hambye994d462014-02-03 13:10:13 -08005029 }
5030
5031 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005032 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005033 * Used for device configuration by some CDMA operators.
5034 *
chen xu6dac5ab2018-10-26 17:39:23 -07005035 * @param slotIndex - device slot.
5036 *
Jake Hambye994d462014-02-03 13:10:13 -08005037 * @return true on success; false on any failure
5038 */
5039 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005040 public boolean resetModemConfig(int slotIndex) {
5041 Phone phone = PhoneFactory.getPhone(slotIndex);
5042 if (phone != null) {
5043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045
chen xu6dac5ab2018-10-26 17:39:23 -07005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5049 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5050 return success;
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
5053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 }
chen xu6dac5ab2018-10-26 17:39:23 -07005055 return false;
5056 }
5057
5058 /**
5059 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5060 *
5061 * @param slotIndex - device slot.
5062 *
5063 * @return true on success; false on any failure
5064 */
5065 @Override
5066 public boolean rebootModem(int slotIndex) {
5067 Phone phone = PhoneFactory.getPhone(slotIndex);
5068 if (phone != null) {
5069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5070 mApp, phone.getSubId(), "rebootModem");
5071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5075 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5076 return success;
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
5080 }
5081 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005082 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005083
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 public String[] getPcscfAddress(String apnType, String callingPackage,
5085 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005086 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5088 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005089 return new String[0];
5090 }
5091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005094 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
Wink Saville36469e72014-06-11 15:17:00 -07005098 }
5099
Brad Ebinger51f743a2017-01-23 13:50:20 -08005100 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005101 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5102 * {@link #disableIms(int)}.
5103 * @param slotIndex device slot.
5104 */
5105 public void resetIms(int slotIndex) {
5106 enforceModifyPermission();
5107
5108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 if (mImsResolver == null) {
5111 // may happen if the does not support IMS.
5112 return;
5113 }
5114 mImsResolver.disableIms(slotIndex);
5115 mImsResolver.enableIms(slotIndex);
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
5119 }
5120
5121 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005122 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5123 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005124 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005125 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005130 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005131 // may happen if the device does not support IMS.
5132 return;
5133 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005134 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005138 }
5139
5140 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005141 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5142 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005143 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005144 public void disableIms(int slotId) {
5145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005149 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005150 // may happen if the device does not support IMS.
5151 return;
5152 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005153 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005157 }
5158
5159 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005160 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5161 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005162 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005163 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005164 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005165 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005169 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005170 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5171 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005172 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005173 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005177 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005178 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005179 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5180 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005181 @Override
5182 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005183 enforceModifyPermission();
5184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005188 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005195 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005196 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005197 */
5198 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005203 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005204 // may happen if the device does not support IMS.
5205 return null;
5206 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005207 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005211 }
5212
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005213 /**
5214 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005215 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005216 */
5217 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005222 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005223 // may happen if the device does not support IMS.
5224 return null;
5225 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005226 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005230 }
5231
Brad Ebinger884c07b2018-02-15 16:17:40 -08005232 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005233 * Sets the ImsService Package Name that Telephony will bind to.
5234 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005235 * @param slotIndex the slot ID that the ImsService should bind for.
5236 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005237 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005238 * @param featureTypes An integer array of feature types associated with a packageName.
5239 * @param packageName The name of the package that the current configuration will be replaced
5240 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005241 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005242 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005243 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5244 int[] featureTypes, String packageName) {
5245 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5246 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5248 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005249 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 final long identity = Binder.clearCallingIdentity();
5252 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005253 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005254 // may happen if the device does not support IMS.
5255 return false;
5256 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005257 Map<Integer, String> featureConfig = new HashMap<>();
5258 for (int featureType : featureTypes) {
5259 featureConfig.put(featureType, packageName);
5260 }
5261 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5262 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005266 }
5267
5268 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005269 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005270 *
5271 * @param slotId The slot that the ImsService is associated with.
5272 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5273 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005274 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005275 * @return the package name of the ImsService configuration.
5276 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005277 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5278 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005279 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005280 TelephonyPermissions
5281 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5282 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5283 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005287 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005288 // may happen if the device does not support IMS.
5289 return "";
5290 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005291 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005292 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5293 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005297 }
5298
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005299 /**
5300 * Get the MmTelFeature state associated with the requested subscription id.
5301 * @param subId The subscription that the MmTelFeature is associated with.
5302 * @param callback A callback with an integer containing the
5303 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5304 */
5305 @Override
5306 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5307 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5308 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5309 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5310 "IMS not available on device.");
5311 }
5312 final long token = Binder.clearCallingIdentity();
5313 try {
5314 int slotId = getSlotIndex(subId);
5315 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5316 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5317 + subId + "'");
5318 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5319 }
5320 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5321 try {
5322 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5323 } catch (RemoteException e) {
5324 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5325 + "Ignore");
5326 }
5327 });
5328 } finally {
5329 Binder.restoreCallingIdentity(token);
5330 }
5331 }
5332
Wink Saville36469e72014-06-11 15:17:00 -07005333 public void setImsRegistrationState(boolean registered) {
5334 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335
5336 final long identity = Binder.clearCallingIdentity();
5337 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005338 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Wink Saville36469e72014-06-11 15:17:00 -07005342 }
5343
5344 /**
Stuart Scott54788802015-03-30 13:18:01 -07005345 * Set the network selection mode to automatic.
5346 *
5347 */
5348 @Override
5349 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
shilufc958392020-01-20 11:36:01 -08005355 if (!isActiveSubscription(subId)) {
5356 return;
5357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5359 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Stuart Scott54788802015-03-30 13:18:01 -07005363 }
5364
Jack Yud10cdd42020-09-28 20:28:01 -07005365 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005366 * Ask the radio to connect to the input network and change selection mode to manual.
5367 *
5368 * @param subId the id of the subscription.
5369 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5370 * the operator to attach to.
5371 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5372 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5373 * normal network selection next time.
5374 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005375 */
5376 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005377 public boolean setNetworkSelectionModeManual(
5378 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5380 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005381
5382 if (!isActiveSubscription(subId)) {
5383 return false;
5384 }
5385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005388 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005390 if (DBG) {
5391 log("setNetworkSelectionModeManual: subId: " + subId
5392 + " operator: " + operatorInfo);
5393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005398 }
shilu84f6e8b2019-12-19 13:58:01 -08005399 /**
5400 * Get the manual network selection
5401 *
5402 * @param subId the id of the subscription.
5403 *
5404 * @return the previously saved user selected PLMN
5405 */
5406 @Override
5407 public String getManualNetworkSelectionPlmn(int subId) {
5408 TelephonyPermissions
5409 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5410 mApp, subId, "getManualNetworkSelectionPlmn");
5411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005415 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005416 }
5417
5418 final Phone phone = getPhone(subId);
5419 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005420 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005421 }
5422 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5423 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5424 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
5428 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005429
5430 /**
5431 * Scans for available networks.
5432 */
5433 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005434 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5435 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005438 LocationAccessPolicy.LocationPermissionResult locationResult =
5439 LocationAccessPolicy.checkLocationPermission(mApp,
5440 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5441 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005442 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005443 .setCallingPid(Binder.getCallingPid())
5444 .setCallingUid(Binder.getCallingUid())
5445 .setMethod("getCellNetworkScanResults")
5446 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005447 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5448 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005449 .build());
5450 switch (locationResult) {
5451 case DENIED_HARD:
5452 throw new SecurityException("Not allowed to access scan results -- location");
5453 case DENIED_SOFT:
5454 return null;
5455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456
Pengquan Menga1bb6272018-09-06 09:59:22 -07005457 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 try {
5459 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005460 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005465 }
5466
5467 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005468 * Get the call forwarding info, given the call forwarding reason.
5469 */
5470 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005471 public void getCallForwarding(int subId, int callForwardingReason,
5472 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005473 enforceReadPrivilegedPermission("getCallForwarding");
5474 long identity = Binder.clearCallingIdentity();
5475 try {
5476 if (DBG) {
5477 log("getCallForwarding: subId " + subId
5478 + " callForwardingReason" + callForwardingReason);
5479 }
Hall Liu27d24262020-09-18 19:04:59 -07005480
5481 Phone phone = getPhone(subId);
5482 if (phone == null) {
5483 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005484 callback.onError(
5485 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005486 } catch (RemoteException e) {
5487 // ignore
5488 }
5489 return;
5490 }
5491
5492 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5493 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5494 @Override
5495 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5496 try {
5497 callback.onCallForwardingInfoAvailable(info);
5498 } catch (RemoteException e) {
5499 // ignore
5500 }
5501 }
5502
5503 @Override
5504 public void onError(int error) {
5505 try {
5506 callback.onError(error);
5507 } catch (RemoteException e) {
5508 // ignore
5509 }
5510 }
5511 });
5512 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
5516 }
5517
5518 /**
5519 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5520 * reason, the number to forward, and the timeout before the forwarding is attempted.
5521 */
5522 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005523 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5524 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005525 enforceModifyPermission();
5526 long identity = Binder.clearCallingIdentity();
5527 try {
5528 if (DBG) {
5529 log("setCallForwarding: subId " + subId
5530 + " callForwardingInfo" + callForwardingInfo);
5531 }
Hall Liu27d24262020-09-18 19:04:59 -07005532
5533 Phone phone = getPhone(subId);
5534 if (phone == null) {
5535 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005536 callback.accept(
5537 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005538 } catch (RemoteException e) {
5539 // ignore
5540 }
5541 return;
5542 }
5543
5544 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5545 FunctionalUtils.ignoreRemoteException(callback::accept));
5546
5547 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
5553 /**
Hall Liu27d24262020-09-18 19:04:59 -07005554 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005555 */
5556 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005557 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005558 enforceReadPrivilegedPermission("getCallForwarding");
5559 long identity = Binder.clearCallingIdentity();
5560 try {
Hall Liu27d24262020-09-18 19:04:59 -07005561
5562 Phone phone = getPhone(subId);
5563 if (phone == null) {
5564 try {
5565 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5566 } catch (RemoteException e) {
5567 // ignore
5568 }
5569 return;
5570 }
5571
5572 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5573
Shuo Qian4a594052020-01-23 11:59:30 -08005574 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005575 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580
5581 /**
Hall Liu27d24262020-09-18 19:04:59 -07005582 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005583 */
5584 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005585 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005586 enforceModifyPermission();
5587 long identity = Binder.clearCallingIdentity();
5588 try {
Hall Liu27d24262020-09-18 19:04:59 -07005589 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5590
5591 Phone phone = getPhone(subId);
5592 if (phone == null) {
5593 try {
5594 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5595 } catch (RemoteException e) {
5596 // ignore
5597 }
5598 return;
5599 }
5600
5601 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5602 FunctionalUtils.ignoreRemoteException(callback::accept));
5603
5604 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 /**
yinxub1bed742017-04-17 11:45:04 -07005611 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005612 *
yinxub1bed742017-04-17 11:45:04 -07005613 * @param subId id of the subscription
5614 * @param request contains the radio access networks with bands/channels to scan
5615 * @param messenger callback messenger for scan results or errors
5616 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005617 * @return the id of the requested scan which can be used to stop the scan.
5618 */
5619 @Override
5620 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005621 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5623 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005624 LocationAccessPolicy.LocationPermissionResult locationResult =
5625 LocationAccessPolicy.checkLocationPermission(mApp,
5626 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5627 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005628 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005629 .setCallingPid(Binder.getCallingPid())
5630 .setCallingUid(Binder.getCallingUid())
5631 .setMethod("requestNetworkScan")
5632 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005633 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5634 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005635 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005636 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005637 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5638 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005639 if (e != null) {
5640 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5641 throw e;
5642 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005643 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005644 return TelephonyScanManager.INVALID_SCAN_ID;
5645 }
5646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 }
Hall Liu912dfd32019-04-25 14:02:26 -07005648 int callingUid = Binder.getCallingUid();
5649 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 return mNetworkScanRequestTracker.startNetworkScan(
5653 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005654 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
yinxu504e1392017-04-12 16:03:22 -07005658 }
5659
Hall Liub2ac8ef2019-02-28 15:56:23 -08005660 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005661 NetworkScanRequest request, int subId, String callingPackage) {
5662 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005663 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5664 boolean hasNetworkScanPermission =
5665 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5666 == PERMISSION_GRANTED;
5667
5668 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5669 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5670 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005671 }
5672
5673 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5674 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005675 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5676 return new SecurityException("Specific channels must not be"
5677 + " scanned without location access.");
5678 }
5679 }
5680 }
5681
Hall Liub2ac8ef2019-02-28 15:56:23 -08005682 return null;
5683 }
5684
yinxu504e1392017-04-12 16:03:22 -07005685 /**
5686 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005687 *
5688 * @param subId id of the subscription
5689 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005690 */
5691 @Override
5692 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
Hall Liu912dfd32019-04-25 14:02:26 -07005696 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005699 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
yinxu504e1392017-04-12 16:03:22 -07005703 }
5704
5705 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005706 * Get the calculated preferred network type.
5707 * Used for debugging incorrect network type.
5708 *
5709 * @return the preferred network type, defined in RILConstants.java.
5710 */
5711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005712 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005713 final Phone defaultPhone = getDefaultPhone();
5714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005716 return RILConstants.PREFERRED_NETWORK_MODE;
5717 }
5718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Junda Liu84d15a22014-07-02 11:21:04 -07005726 }
5727
5728 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005729 * Get the preferred network type.
5730 * Used for device configuration by some CDMA operators.
5731 *
5732 * @return the preferred network type, defined in RILConstants.java.
5733 */
5734 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005735 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005736 TelephonyPermissions
5737 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5738 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 if (DBG) log("getPreferredNetworkType");
5743 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5744 int networkType = (result != null ? result[0] : -1);
5745 if (DBG) log("getPreferredNetworkType: " + networkType);
5746 return networkType;
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005750 }
5751
5752 /**
5753 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005754 *
5755 * @param networkType the preferred network type, defined in RILConstants.java.
5756 * @return true on success; false on any failure.
5757 */
5758 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005759 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5761 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
calvinpan8ed33732020-03-12 14:17:55 +08005765 Boolean success = (Boolean) sendRequest(
5766 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005767
5768 if (success) {
5769 Settings.Global.putInt(mApp.getContentResolver(),
5770 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5771 }
calvinpan8ed33732020-03-12 14:17:55 +08005772 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5773 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005776 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005777 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005778
5779 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005780 * Get the allowed network types that store in the telephony provider.
5781 *
5782 * @param subId the id of the subscription.
5783 * @return allowedNetworkTypes the allowed network types.
5784 */
5785 @Override
5786 public long getAllowedNetworkTypes(int subId) {
5787 TelephonyPermissions
5788 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5789 mApp, subId, "getAllowedNetworkTypes");
5790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 return SubscriptionManager.getLongSubscriptionProperty(
5794 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
5798 }
5799
5800 /**
5801 * Set the allowed network types.
5802 *
5803 * @param subId the id of the subscription.
5804 * @param allowedNetworkTypes the allowed network types.
5805 * @return true on success; false on any failure.
5806 */
5807 @Override
5808 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5810 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005811
calvinpan8ed33732020-03-12 14:17:55 +08005812 SubscriptionManager.setSubscriptionProperty(subId,
5813 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5814 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005815
calvinpan8ed33732020-03-12 14:17:55 +08005816 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5817 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5818 RILConstants.PREFERRED_NETWORK_MODE);
5819 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005820 }
5821
5822 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005823 * Get the allowed network types for certain reason.
5824 *
5825 * @param subId the id of the subscription.
5826 * @param reason the reason the allowed network type change is taking place
5827 * @return the allowed network types.
5828 */
5829 @Override
5830 public long getAllowedNetworkTypesForReason(int subId,
5831 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5832 TelephonyPermissions
5833 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5834 mApp, subId, "getAllowedNetworkTypesForReason");
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
5840 }
5841 }
5842
5843 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005844 * Enable/Disable E-UTRA-NR Dual Connectivity
5845 * @param subId subscription id of the sim card
5846 * @param nrDualConnectivityState expected NR dual connectivity state
5847 * This can be passed following states
5848 * <ol>
5849 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5850 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5851 * <li>Disable NR dual connectivity and force secondary cell to be released
5852 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5853 * </ol>
5854 * @return operation result.
5855 */
5856 @Override
5857 public int setNrDualConnectivityState(int subId,
5858 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5860 mApp, subId, "enableNRDualConnectivity");
5861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5865 nrDualConnectivityState, subId,
5866 workSource);
5867 if (DBG) log("enableNRDualConnectivity result: " + result);
5868 return result;
5869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
5872 }
5873
5874 /**
5875 * Is E-UTRA-NR Dual Connectivity enabled
5876 * @return true if dual connectivity is enabled else false
5877 */
5878 @Override
5879 public boolean isNrDualConnectivityEnabled(int subId) {
5880 TelephonyPermissions
5881 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5882 mApp, subId, "isNRDualConnectivityEnabled");
5883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5887 null, subId, workSource);
5888 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5889 return isEnabled;
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
5893 }
5894
5895 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07005896 * get carrier bandwidth per primary and secondary carrier
5897 * @param subId subscription id of the sim card
5898 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5899 */
5900 @Override
5901 public CarrierBandwidth getCarrierBandwidth(int subId) {
5902 TelephonyPermissions
5903 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5904 mApp, subId, "isNRDualConnectivityEnabled");
5905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
5908 CarrierBandwidth carrierBandwidth =
5909 getPhoneFromSubId(subId).getCarrierBandwidth();
5910 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5911 return carrierBandwidth;
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
5915 }
5916
5917 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005918 * Get the effective allowed network types on the device.
5919 * This API will return an intersection of allowed network types for all reasons,
5920 * including the configuration done through setAllowedNetworkTypes
5921 *
5922 * @param subId the id of the subscription.
5923 * @return the allowed network types
5924 */
5925 @Override
5926 public long getEffectiveAllowedNetworkTypes(int subId) {
5927 TelephonyPermissions
5928 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5929 mApp, subId, "getEffectiveAllowedNetworkTypes");
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
5936 }
5937
5938 /**
5939 * Set the allowed network types of the device and
5940 * provide the reason triggering the allowed network change.
5941 *
5942 * @param subId the id of the subscription.
5943 * @param reason the reason the allowed network type change is taking place
5944 * @param allowedNetworkTypes the allowed network types.
5945 * @return true on success; false on any failure.
5946 */
5947 @Override
5948 public boolean setAllowedNetworkTypesForReason(int subId,
5949 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5951 mApp, subId, "setAllowedNetworkTypesForReason");
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5955 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5956 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5957 RILConstants.PREFERRED_NETWORK_MODE);
5958 return setPreferredNetworkType(subId, preferredNetworkMode);
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
5962 }
5963
5964 /**
Miaoa84611c2019-03-15 09:21:10 +08005965 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005966 *
Miaoa84611c2019-03-15 09:21:10 +08005967 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005968 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005969 * @hide
5970 */
5971 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005972 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005973 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005975 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 try {
Miaoa84611c2019-03-15 09:21:10 +08005977 if (phone != null) {
5978 return phone.hasMatchedTetherApnSetting();
5979 } else {
5980 return false;
5981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 } finally {
5983 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005984 }
Junda Liu475951f2014-11-07 16:45:03 -08005985 }
5986
5987 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005988 * Enable or disable always reporting signal strength changes from radio.
5989 *
5990 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5991 */
5992 @Override
5993 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5994 enforceModifyPermission();
5995 enforceSystemCaller();
5996
5997 final long identity = Binder.clearCallingIdentity();
5998 final Phone phone = getPhone(subId);
5999 try {
6000 if (phone != null) {
6001 if (DBG) {
6002 log("setAlwaysReportSignalStrength: subId=" + subId
6003 + " isEnable=" + isEnable);
6004 }
6005 phone.setAlwaysReportSignalStrength(isEnable);
6006 } else {
6007 loge("setAlwaysReportSignalStrength: no phone found for subId="
6008 + subId);
6009 }
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
6013 }
6014
6015 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006016 * Get the user enabled state of Mobile Data.
6017 *
6018 * TODO: remove and use isUserDataEnabled.
6019 * This can't be removed now because some vendor codes
6020 * calls through ITelephony directly while they should
6021 * use TelephonyManager.
6022 *
6023 * @return true on enabled
6024 */
6025 @Override
6026 public boolean getDataEnabled(int subId) {
6027 return isUserDataEnabled(subId);
6028 }
6029
6030 /**
6031 * Get whether mobile data is enabled per user setting.
6032 *
6033 * There are other factors deciding whether mobile data is actually enabled, but they are
6034 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006035 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006036 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006037 *
6038 * @return {@code true} if data is enabled else {@code false}
6039 */
6040 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006041 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006042 try {
6043 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6044 null);
6045 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6047 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 int phoneId = mSubscriptionController.getPhoneId(subId);
6053 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6054 Phone phone = PhoneFactory.getPhone(phoneId);
6055 if (phone != null) {
6056 boolean retVal = phone.isUserDataEnabled();
6057 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6058 return retVal;
6059 } else {
6060 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6061 return false;
6062 }
6063 } finally {
6064 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006065 }
6066 }
6067
6068 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006069 * Checks if the device is capable of mobile data by considering whether whether the
6070 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6071 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006072 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006073 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006074 */
6075 @Override
6076 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006077 try {
6078 try {
6079 mApp.enforceCallingOrSelfPermission(
6080 android.Manifest.permission.ACCESS_NETWORK_STATE,
6081 null);
6082 } catch (Exception e) {
6083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6084 "isDataEnabled");
6085 }
6086 } catch (Exception e) {
6087 enforceReadPrivilegedPermission("isDataEnabled");
6088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 int phoneId = mSubscriptionController.getPhoneId(subId);
6093 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6094 Phone phone = PhoneFactory.getPhone(phoneId);
6095 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006096 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6098 return retVal;
6099 } else {
6100 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6101 return false;
6102 }
6103 } finally {
6104 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006105 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006106 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006107
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006108 /**
6109 * Check if data is enabled for a specific reason
6110 * @param subId Subscription index
6111 * @param reason the reason the data enable change is taking place
6112 * @return {@code true} if the overall data is enabled; {@code false} if not.
6113 */
6114 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006115 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006116 @TelephonyManager.DataEnabledReason int reason) {
6117 try {
6118 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6119 null);
6120 } catch (Exception e) {
6121 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006122 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006123 }
6124
6125
6126 final long identity = Binder.clearCallingIdentity();
6127 try {
6128 int phoneId = mSubscriptionController.getPhoneId(subId);
6129 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006130 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006131 + " reason=" + reason);
6132 }
6133 Phone phone = PhoneFactory.getPhone(phoneId);
6134 if (phone != null) {
6135 boolean retVal;
6136 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6137 retVal = phone.isUserDataEnabled();
6138 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006139 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006140 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006141 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006142 return retVal;
6143 } else {
6144 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006145 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006146 + subId + " retVal=false");
6147 }
6148 return false;
6149 }
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
6153 }
6154
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006155 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006156 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006157 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6158 // Skip the check if it's one of these special uids
6159 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6160 }
6161
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006162 //load access rules from carrier configs, and check those as well: b/139133814
6163 SubscriptionController subController = SubscriptionController.getInstance();
6164 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6165 || subController == null) return privilegeFromSim;
6166
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006167 PackageManager pkgMgr = phone.getContext().getPackageManager();
6168 String[] packages = pkgMgr.getPackagesForUid(uid);
6169
6170 final long identity = Binder.clearCallingIdentity();
6171 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006172 int subId = phone.getSubId();
6173 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6174 // A test override is in place for the privileges for this subId, so don't try to
6175 // read the subscription privileges.
6176 return privilegeFromSim;
6177 }
6178 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006179 SubscriptionManager subManager = (SubscriptionManager)
6180 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6181 for (String pkg : packages) {
6182 if (subManager.canManageSubscription(subInfo, pkg)) {
6183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6184 }
6185 }
6186 return privilegeFromSim;
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6193 String pkgName) {
6194 //load access rules from carrier configs, and check those as well: b/139133814
6195 SubscriptionController subController = SubscriptionController.getInstance();
6196 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6197 || subController == null) return privilegeFromSim;
6198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006201 int subId = phone.getSubId();
6202 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6203 // A test override is in place for the privileges for this subId, so don't try to
6204 // read the subscription privileges.
6205 return privilegeFromSim;
6206 }
6207 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006208 SubscriptionManager subManager = (SubscriptionManager)
6209 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6210 return subManager.canManageSubscription(subInfo, pkgName)
6211 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006218 public int getCarrierPrivilegeStatus(int subId) {
6219 final Phone phone = getPhone(subId);
6220 if (phone == null) {
6221 loge("getCarrierPrivilegeStatus: Invalid subId");
6222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6223 }
6224 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006225 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006226 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006227 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6228 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006229
6230 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6231 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006232 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006233 }
Junda Liu29340342014-07-10 15:23:27 -07006234
6235 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006236 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006237 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006238 final Phone phone = getPhone(subId);
6239 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006240 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006241 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6242 }
6243 UiccProfile profile =
6244 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6245 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006246 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006247 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6248 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006249 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006250 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006251 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 }
6253
6254 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006255 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6256 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006257 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006258 }
6259
6260 int phoneId = SubscriptionManager.getPhoneId(subId);
6261 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006262 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006263 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006264 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6265 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006266 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6267 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6268 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006269 }
6270
6271 @Override
6272 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006273 if (TextUtils.isEmpty(pkgName))
6274 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006275 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6276 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6277 UiccCard card = UiccController.getInstance().getUiccCard(i);
6278 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006279 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006280 continue;
6281 }
6282
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006283 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6284 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6285 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006286 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6287 break;
6288 }
6289 }
6290
6291 return result;
Junda Liu29340342014-07-10 15:23:27 -07006292 }
Derek Tan89e89d42014-07-08 17:00:10 -07006293
6294 @Override
Junda Liue64de782015-04-16 17:19:16 -07006295 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6296 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6297 loge("phoneId " + phoneId + " is not valid.");
6298 return null;
6299 }
6300 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006301 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006302 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006303 return null ;
6304 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006306 }
6307
Amith Yamasani6e118872016-02-19 12:53:51 -08006308 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006309 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006311 List<String> privilegedPackages = new ArrayList<>();
6312 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006313 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6314 // has UICC in that slot.
6315 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006316 if (card.hasCarrierPrivilegeRules()) {
6317 if (packages == null) {
6318 // Only check packages in user 0 for now
6319 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006320 PackageManager.MATCH_DISABLED_COMPONENTS
6321 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006322 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006323 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006324 }
6325 for (int p = packages.size() - 1; p >= 0; p--) {
6326 PackageInfo pkgInfo = packages.get(p);
6327 if (pkgInfo != null && pkgInfo.packageName != null
6328 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006329 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006330 privilegedPackages.add(pkgInfo.packageName);
6331 }
6332 }
6333 }
6334 }
6335 return privilegedPackages;
6336 }
6337
chen xuf7e9fe82019-05-09 19:31:02 -07006338 @Override
6339 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006340 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6341
6342 final long identity = Binder.clearCallingIdentity();
6343
chen xuf7e9fe82019-05-09 19:31:02 -07006344 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006345 try {
6346 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6347 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6348 }
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006351 }
6352 return privilegedPackages;
6353 }
6354
Wink Savilleb564aae2014-10-23 10:18:09 -07006355 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006356 final Phone phone = getPhone(subId);
6357 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006358 if (card == null) {
6359 loge("getIccId: No UICC");
6360 return null;
6361 }
6362 String iccId = card.getIccId();
6363 if (TextUtils.isEmpty(iccId)) {
6364 loge("getIccId: ICC ID is null or empty.");
6365 return null;
6366 }
6367 return iccId;
6368 }
6369
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006370 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006371 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6372 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006373 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006374 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 final String iccId = getIccId(subId);
6379 final Phone phone = getPhone(subId);
6380 if (phone == null) {
6381 return false;
6382 }
6383 final String subscriberId = phone.getSubscriberId();
6384
6385 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006386 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 + subscriberId + " to " + number);
6388 }
6389
6390 if (TextUtils.isEmpty(iccId)) {
6391 return false;
6392 }
6393
6394 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6395
6396 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6397 if (alphaTag == null) {
6398 editor.remove(alphaTagPrefKey);
6399 } else {
6400 editor.putString(alphaTagPrefKey, alphaTag);
6401 }
6402
6403 // Record both the line number and IMSI for this ICCID, since we need to
6404 // track all merged IMSIs based on line number
6405 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6406 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6407 if (number == null) {
6408 editor.remove(numberPrefKey);
6409 editor.remove(subscriberPrefKey);
6410 } else {
6411 editor.putString(numberPrefKey, number);
6412 editor.putString(subscriberPrefKey, subscriberId);
6413 }
6414
6415 editor.commit();
6416 return true;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006419 }
Derek Tan7226c842014-07-02 17:42:23 -07006420 }
6421
6422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006423 public String getLine1NumberForDisplay(int subId, String callingPackage,
6424 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006425 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006427 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006428 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006429 return null;
6430 }
Derek Tan97ebb422014-09-05 16:55:38 -07006431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 String iccId = getIccId(subId);
6435 if (iccId != null) {
6436 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6437 if (DBG_MERGE) {
6438 log("getLine1NumberForDisplay returning "
6439 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6440 }
6441 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6444 return null;
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006447 }
Derek Tan7226c842014-07-02 17:42:23 -07006448 }
6449
6450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006451 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6452 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006454 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006455 return null;
6456 }
Derek Tan97ebb422014-09-05 16:55:38 -07006457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 String iccId = getIccId(subId);
6461 if (iccId != null) {
6462 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6463 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6464 }
6465 return null;
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006468 }
Derek Tan7226c842014-07-02 17:42:23 -07006469 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006470
6471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006472 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6473 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006474 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6475 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006477 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006478 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006479 return null;
6480 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006481
Jordan Liub49b04b2019-05-06 14:45:15 -07006482 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6483 // the process, where TelephonyManager was instantiated.
6484 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006485 final long identity = Binder.clearCallingIdentity();
6486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006487 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 final TelephonyManager tele = TelephonyManager.from(context);
6489 final SubscriptionManager sub = SubscriptionManager.from(context);
6490
6491 // Figure out what subscribers are currently active
6492 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493
Jordan Liub49b04b2019-05-06 14:45:15 -07006494 // Only consider subs which match the current subId
6495 // This logic can be simplified. See b/131189269 for progress.
6496 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006497 activeSubscriberIds.add(tele.getSubscriberId(subId));
6498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499
6500 // First pass, find a number override for an active subscriber
6501 String mergeNumber = null;
6502 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6503 for (String key : prefs.keySet()) {
6504 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6505 final String subscriberId = (String) prefs.get(key);
6506 if (activeSubscriberIds.contains(subscriberId)) {
6507 final String iccId = key.substring(
6508 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6509 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6510 mergeNumber = (String) prefs.get(numberKey);
6511 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006512 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 + " for active subscriber " + subscriberId);
6514 }
6515 if (!TextUtils.isEmpty(mergeNumber)) {
6516 break;
6517 }
6518 }
6519 }
6520 }
6521
6522 // Shortcut when no active merged subscribers
6523 if (TextUtils.isEmpty(mergeNumber)) {
6524 return null;
6525 }
6526
6527 // Second pass, find all subscribers under that line override
6528 final ArraySet<String> result = new ArraySet<>();
6529 for (String key : prefs.keySet()) {
6530 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6531 final String number = (String) prefs.get(key);
6532 if (mergeNumber.equals(number)) {
6533 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6534 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6535 final String subscriberId = (String) prefs.get(subscriberKey);
6536 if (!TextUtils.isEmpty(subscriberId)) {
6537 result.add(subscriberId);
6538 }
6539 }
6540 }
6541 }
6542
6543 final String[] resultArray = result.toArray(new String[result.size()]);
6544 Arrays.sort(resultArray);
6545 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006546 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6548 }
6549 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006552 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006553 }
6554
6555 @Override
zoey chen38003472019-12-13 17:16:31 +08006556 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6557 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006558
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 final TelephonyManager telephonyManager = mApp.getSystemService(
6562 TelephonyManager.class);
6563 String subscriberId = telephonyManager.getSubscriberId(subId);
6564 if (subscriberId == null) {
6565 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006566 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006567 + subId);
6568 }
6569 return null;
6570 }
6571
6572 final SubscriptionInfo info = SubscriptionController.getInstance()
6573 .getSubscriptionInfo(subId);
6574 final ParcelUuid groupUuid = info.getGroupUuid();
6575 // If it doesn't belong to any group, return just subscriberId of itself.
6576 if (groupUuid == null) {
6577 return new String[]{subscriberId};
6578 }
6579
6580 // Get all subscriberIds from the group.
6581 final List<String> mergedSubscriberIds = new ArrayList<>();
6582 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006583 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006584 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006585 for (SubscriptionInfo subInfo : groupInfos) {
6586 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6587 if (subscriberId != null) {
6588 mergedSubscriberIds.add(subscriberId);
6589 }
6590 }
6591
6592 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595
6596 }
6597 }
6598
6599 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006600 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006601 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006602 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 final Phone phone = getPhone(subId);
6607 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006611 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006612
6613 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006614 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006615 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6616 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006617 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6618 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 final Phone phone = getPhone(subId);
6623 if (phone == null) {
6624 return false;
6625 }
6626 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6627 cdmaNonRoamingList);
6628 } finally {
6629 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006630 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006631 }
6632
6633 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006634 @Deprecated
6635 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6636 enforceModifyPermission();
6637
6638 int returnValue = 0;
6639 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006640 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006641 if(result.exception == null) {
6642 if (result.result != null) {
6643 byte[] responseData = (byte[])(result.result);
6644 if(responseData.length > oemResp.length) {
6645 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6646 responseData.length + "bytes. Buffer Size is " +
6647 oemResp.length + "bytes.");
6648 }
6649 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6650 returnValue = responseData.length;
6651 }
6652 } else {
6653 CommandException ex = (CommandException) result.exception;
6654 returnValue = ex.getCommandError().ordinal();
6655 if(returnValue > 0) returnValue *= -1;
6656 }
6657 } catch (RuntimeException e) {
6658 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6659 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6660 if(returnValue > 0) returnValue *= -1;
6661 }
6662
6663 return returnValue;
6664 }
6665
6666 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006667 public void setRadioCapability(RadioAccessFamily[] rafs) {
6668 try {
6669 ProxyController.getInstance().setRadioCapability(rafs);
6670 } catch (RuntimeException e) {
6671 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6672 }
6673 }
6674
6675 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006676 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006677 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006678 try {
6679 TelephonyPermissions
6680 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6681 mApp, phone.getSubId(), "getRadioAccessFamily");
6682 } catch (SecurityException e) {
6683 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6684 throw e;
6685 }
chen xub97461a2018-10-26 14:17:57 -07006686 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006687 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006688 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 final long identity = Binder.clearCallingIdentity();
6691 try {
chen xub97461a2018-10-26 14:17:57 -07006692 TelephonyPermissions
6693 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6694 mApp, phone.getSubId(), "getRadioAccessFamily");
6695 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 } finally {
6697 Binder.restoreCallingIdentity(identity);
6698 }
chen xub97461a2018-10-26 14:17:57 -07006699 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006700 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006701
6702 @Override
6703 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006704 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006709 ImsManager.getInstance(defaultPhone.getContext(),
6710 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006714 }
6715
6716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006717 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006718 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6720 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006721 return false;
6722 }
Svet Ganovb320e182015-04-16 12:30:10 -07006723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 // Check the user preference and the system-level IMS setting. Even if the user has
6727 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6728 // In the long run, we may instead need to check if there exists a connection service
6729 // which can support video calling.
6730 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006731 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 return imsManager.isVtEnabledByPlatform()
6733 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6734 && imsManager.isVtEnabledByUser();
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006738 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006739
Andrew Leea1239f22015-03-02 17:44:07 -08006740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006741 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6742 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006744 mApp, subId, callingPackage, callingFeatureId,
6745 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 return false;
6747 }
6748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 CarrierConfigManager configManager =
6752 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006753 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
Andrew Leea1239f22015-03-02 17:44:07 -08006758 }
6759
6760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006761 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006763 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 return false;
6765 }
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 CarrierConfigManager configManager =
6770 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006771 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
Andrew Leea1239f22015-03-02 17:44:07 -08006776 }
6777
Andrew Lee9431b832015-03-09 18:46:45 -07006778 @Override
6779 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006780 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006781 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006782 }
6783
6784 @Override
6785 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 final long identity = Binder.clearCallingIdentity();
6787 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
Andrew Lee9431b832015-03-09 18:46:45 -07006792 }
6793
Hall Liuf6668912018-10-31 17:05:23 -07006794 /**
6795 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6796 * support for the feature and device firmware support.
6797 *
6798 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6799 */
6800 @Override
6801 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006803 final Phone phone = getPhone(subscriptionId);
6804 if (phone == null) {
6805 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6806 return false;
6807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006809 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6811 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 return isCarrierSupported && isDeviceSupported;
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
Hall Liu98187582018-01-22 19:15:32 -08006817 }
6818
Hall Liuf6668912018-10-31 17:05:23 -07006819 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006820 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6821 * RTT setting, will return true if the device and carrier both support RTT.
6822 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006823 */
6824 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006827 boolean isRttSupported = isRttSupported(subscriptionId);
6828 boolean isUserRttSettingOn = Settings.Secure.getInt(
6829 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6830 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6831 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6832 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006836 }
6837
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006838 @Deprecated
6839 @Override
6840 public String getDeviceId(String callingPackage) {
6841 return getDeviceIdWithFeature(callingPackage, null);
6842 }
6843
Sanket Padawe7310cc72015-01-14 09:53:20 -08006844 /**
6845 * Returns the unique device ID of phone, for example, the IMEI for
6846 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6847 *
6848 * <p>Requires Permission:
6849 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6850 */
6851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006852 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006853 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006854 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006855 return null;
6856 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006857 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006858 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006859 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006860 return null;
6861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 return phone.getDeviceId();
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006869 }
6870
Ping Sunc67b7c22016-03-02 19:16:45 +08006871 /**
6872 * {@hide}
6873 * Returns the IMS Registration Status on a particular subid
6874 *
6875 * @param subId
6876 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006877 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006878 Phone phone = getPhone(subId);
6879 if (phone != null) {
6880 return phone.isImsRegistered();
6881 } else {
6882 return false;
6883 }
6884 }
6885
Santos Cordon7a1885b2015-02-03 11:15:19 -08006886 @Override
6887 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006894 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006895
Tyler Gunnf70ed162019-04-03 15:28:53 -07006896 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006897 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006898 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006900 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006901 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6902 }
6903 final long identity = Binder.clearCallingIdentity();
6904 try {
6905 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
6909 }
6910
6911 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006912 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006913 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6914 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006915 final long identity = Binder.clearCallingIdentity();
6916 try {
6917 Phone phone = getPhone(subscriptionId);
6918 if (phone == null) {
6919 return null;
6920 }
6921 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006927 /**
6928 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006929 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006930 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 Phone phone = getPhone(subId);
6934 if (phone != null) {
6935 return phone.isWifiCallingEnabled();
6936 } else {
6937 return false;
6938 }
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006941 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006942 }
6943
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006944 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006945 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006946 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006947 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 Phone phone = getPhone(subId);
6951 if (phone != null) {
6952 return phone.isVideoEnabled();
6953 } else {
6954 return false;
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006958 }
6959 }
6960
6961 /**
6962 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6963 * defined in {@link ImsRegistrationImplBase}.
6964 */
6965 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 final long identity = Binder.clearCallingIdentity();
6967 try {
6968 Phone phone = getPhone(subId);
6969 if (phone != null) {
6970 return phone.getImsRegistrationTech();
6971 } else {
6972 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6973 }
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006976 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006977 }
6978
Stuart Scott8eef64f2015-04-08 15:13:54 -07006979 @Override
6980 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006981 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006982 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6983 return;
6984 }
6985
Svet Ganovcc087f82015-05-12 20:35:54 -07006986 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006987
Svet Ganovcc087f82015-05-12 20:35:54 -07006988 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006989 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6990 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006991 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006992 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006993 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006994 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006995 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6996 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006997 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006998 // There has been issues when Sms raw table somehow stores orphan
6999 // fragments. They lead to garbled message when new fragments come
7000 // in and combined with those stale ones. In case this happens again,
7001 // user can reset all network settings which will clean up this table.
7002 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007003 // Clean up IMS settings as well here.
7004 int slotId = getSlotIndex(subId);
7005 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7006 ImsManager.getInstance(mApp, slotId).factoryReset();
7007 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007008
7009 // Erase modem config if erase modem on network setting is enabled.
7010 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7011 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7012 if (configValue != null && Boolean.parseBoolean(configValue)) {
7013 sendEraseModemConfig(getDefaultPhone());
7014 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007015 } finally {
7016 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007017 }
7018 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007019
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007020 private void cleanUpSmsRawTable(Context context) {
7021 ContentResolver resolver = context.getContentResolver();
7022 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7023 resolver.delete(uri, null, null);
7024 }
7025
Narayan Kamath1c496c22015-04-16 14:40:19 +01007026 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007027 public String getSimLocaleForSubscriber(int subId) {
7028 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7029 final Phone phone = getPhone(subId);
7030 if (phone == null) {
7031 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007032 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final long identity = Binder.clearCallingIdentity();
7035 try {
chen xu5d3637b2019-01-21 23:31:38 -08007036 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007037 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007038 if (info == null) {
7039 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7040 return null;
7041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 // Try and fetch the locale from the carrier properties or from the SIM language
7043 // preferences (EF-PL and EF-LI)...
7044 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007046 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7047 if (localeFromDefaultSim != null) {
7048 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7049 if (DBG) log("Using locale from subId: " + subId + " locale: "
7050 + localeFromDefaultSim);
7051 return localeFromDefaultSim.toLanguageTag();
7052 } else {
7053 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 }
7055 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 // The SIM language preferences only store a language (e.g. fr = French), not an
7058 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7059 // the SIM and carrier preferences does not include a country we add the country
7060 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007061 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007063 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 return mccLocale.toLanguageTag();
7065 }
7066
7067 if (DBG) log("No locale found - returning null");
7068 return null;
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007072 }
7073
7074 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007075 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007076 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007077 }
7078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 /**
7080 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7081 */
7082 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007083 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007084 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007085 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007086
Chenjie Yu1ba97252018-01-11 18:16:20 -08007087 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007088 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007089
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007090 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007091 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7092 * representing the state of the modem.
7093 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007094 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7095 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007096 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007097 */
7098 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007099 public void requestModemActivityInfo(ResultReceiver result) {
7100 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007101 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102
7103 final long identity = Binder.clearCallingIdentity();
7104 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007105 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 } finally {
7107 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007108 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007109 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007110
Siddharth Rayb8114062018-06-17 15:02:38 -07007111 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7112 // less than total activity duration.
7113 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7114 if (info == null) {
7115 return false;
7116 }
7117 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007118 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7119 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7120
Siddharth Rayb8114062018-06-17 15:02:38 -07007121 return (info.isValid()
7122 && (info.getSleepTimeMillis() <= activityDurationMs)
7123 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007124 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007125 && (totalTxTimeMs <= activityDurationMs));
7126 }
7127
Jack Yu85bd38a2015-11-09 11:34:32 -08007128 /**
7129 * {@hide}
7130 * Returns the service state information on specified subscription.
7131 */
7132 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007133 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7134 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007136 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007137 return null;
7138 }
7139
Hall Liuf19c44f2018-11-27 14:38:17 -08007140 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7141 LocationAccessPolicy.checkLocationPermission(mApp,
7142 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7143 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007144 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007145 .setCallingPid(Binder.getCallingPid())
7146 .setCallingUid(Binder.getCallingUid())
7147 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007148 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007149 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007150 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7151 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007152 .build());
7153
7154 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7155 LocationAccessPolicy.checkLocationPermission(mApp,
7156 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7157 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007158 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007159 .setCallingPid(Binder.getCallingPid())
7160 .setCallingUid(Binder.getCallingUid())
7161 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007162 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007163 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007164 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7165 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007166 .build());
7167 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7168 boolean hasFinePermission =
7169 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7170 boolean hasCoarsePermission =
7171 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7172
Jack Yu479f40e2020-10-27 21:29:25 -07007173 final Phone phone = getPhone(subId);
7174 if (phone == null) {
7175 return null;
7176 }
7177
7178 boolean isCallingPackageDataService = phone.getDataServicePackages()
7179 .contains(callingPackage);
7180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007183 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7184 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7185 Rlog.d(LOG_TAG,
7186 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7187 return null;
7188 }
7189
Hall Liuf19c44f2018-11-27 14:38:17 -08007190 ServiceState ss = phone.getServiceState();
7191
7192 // Scrub out the location info in ServiceState depending on what level of access
7193 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007194 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007195 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7196 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007200 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007201
7202 /**
7203 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7204 *
7205 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7206 * voicemail ringtone.
7207 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7208 * PhoneAccount.
7209 */
7210 @Override
7211 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7215 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007216 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007223 }
7224
7225 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007226 * Sets the per-account voicemail ringtone.
7227 *
7228 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7229 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7230 *
7231 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7232 * voicemail ringtone.
7233 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7234 * PhoneAccount.
7235 */
7236 @Override
7237 public void setVoicemailRingtoneUri(String callingPackage,
7238 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007239 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007240 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007241 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7242 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7244 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7245 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7251 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007252 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 }
7254 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007257 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007258 }
7259
7260 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007261 * Returns whether vibration is set for voicemail notification in Phone settings.
7262 *
7263 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7264 * voicemail vibration setting.
7265 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7266 */
7267 @Override
7268 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7272 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007280 }
7281
Youhan Wange64578a2016-05-02 15:32:42 -07007282 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007283 * Sets the per-account voicemail vibration.
7284 *
7285 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7286 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7287 *
7288 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7289 * voicemail vibration setting.
7290 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7291 * specific PhoneAccount.
7292 */
7293 @Override
7294 public void setVoicemailVibrationEnabled(String callingPackage,
7295 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007296 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007298 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7299 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7301 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7302 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007303 }
7304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7308 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007309 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 }
7311 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007314 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007315 }
7316
7317 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007318 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7319 *
7320 * @throws SecurityException if the caller does not have the required permission
7321 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007322 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007324 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007325 }
7326
7327 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007328 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7329 * permission.
7330 *
7331 * @throws SecurityException if the caller does not have the required permission
7332 */
7333 private void enforceSendSmsPermission() {
7334 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7335 }
7336
7337 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007338 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007339 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007340 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007341 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007342 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007346 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 if (componentName == null) {
7348 throw new SecurityException(
7349 "Caller not current active visual voicemail package[null]");
7350 }
7351 String vvmPackage = componentName.getPackageName();
7352 if (!callingPackage.equals(vvmPackage)) {
7353 throw new SecurityException("Caller not current active visual voicemail package["
7354 + vvmPackage + "]");
7355 }
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007358 }
7359 }
7360
7361 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007362 * Return the application ID for the app type.
7363 *
7364 * @param subId the subscription ID that this request applies to.
7365 * @param appType the uicc app type.
7366 * @return Application ID for specificied app type, or null if no uicc.
7367 */
7368 @Override
7369 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007370 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007371 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372
7373 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007374 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 if (phone == null) {
7376 return null;
7377 }
7378 String aid = null;
7379 try {
7380 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7381 .getApplicationByType(appType).getAid();
7382 } catch (Exception e) {
7383 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7384 }
7385 return aid;
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007388 }
Youhan Wange64578a2016-05-02 15:32:42 -07007389 }
7390
Youhan Wang4001d252016-05-11 10:29:41 -07007391 /**
7392 * Return the Electronic Serial Number.
7393 *
7394 * @param subId the subscription ID that this request applies to.
7395 * @return ESN or null if error.
7396 */
7397 @Override
7398 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007399 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007400 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401
7402 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007403 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 if (phone == null) {
7405 return null;
7406 }
7407 String esn = null;
7408 try {
7409 esn = phone.getEsn();
7410 } catch (Exception e) {
7411 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7412 }
7413 return esn;
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007416 }
Youhan Wang4001d252016-05-11 10:29:41 -07007417 }
7418
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007419 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007420 * Return the Preferred Roaming List Version.
7421 *
7422 * @param subId the subscription ID that this request applies to.
7423 * @return PRLVersion or null if error.
7424 */
7425 @Override
7426 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007427 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007428 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429
7430 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007431 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 if (phone == null) {
7433 return null;
7434 }
7435 String cdmaPrlVersion = null;
7436 try {
7437 cdmaPrlVersion = phone.getCdmaPrlVersion();
7438 } catch (Exception e) {
7439 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7440 }
7441 return cdmaPrlVersion;
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007444 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007445 }
7446
7447 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007448 * Get snapshot of Telephony histograms
7449 * @return List of Telephony histograms
7450 * @hide
7451 */
7452 @Override
7453 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7455 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456
7457 final long identity = Binder.clearCallingIdentity();
7458 try {
7459 return RIL.getTelephonyRILTimingHistograms();
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007463 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007464
7465 /**
7466 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007467 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7468 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007469 * Require system privileges. In the future we may add this to carrier APIs.
7470 *
Michele Berionne482f8202018-11-27 18:57:59 -08007471 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007472 */
7473 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007474 @TelephonyManager.SetCarrierRestrictionResult
7475 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007476 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007478
Michele Berionne482f8202018-11-27 18:57:59 -08007479 if (carrierRestrictionRules == null) {
7480 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007481 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 final long identity = Binder.clearCallingIdentity();
7484 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007485 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007486 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007490 }
7491
7492 /**
7493 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007494 * Get the allowed carrier list and the excluded carrier list, including the priority between
7495 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007496 * Require system privileges. In the future we may add this to carrier APIs.
7497 *
Michele Berionne482f8202018-11-27 18:57:59 -08007498 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007499 */
7500 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007501 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007502 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007507 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7508 if (response instanceof CarrierRestrictionRules) {
7509 return (CarrierRestrictionRules) response;
7510 }
7511 // Response is an Exception of some kind,
7512 // which is signalled to the user as a NULL retval
7513 return null;
7514 } catch (Exception e) {
7515 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7516 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007520 }
7521
fionaxu59545b42016-05-25 15:53:37 -07007522 /**
fionaxu59545b42016-05-25 15:53:37 -07007523 * Action set from carrier signalling broadcast receivers to enable/disable radio
7524 * @param subId the subscription ID that this action applies to.
7525 * @param enabled control enable or disable radio.
7526 * {@hide}
7527 */
7528 @Override
7529 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7530 enforceModifyPermission();
7531 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532
7533 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007534 if (phone == null) {
7535 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7536 return;
7537 }
7538 try {
7539 phone.carrierActionSetRadioEnabled(enabled);
7540 } catch (Exception e) {
7541 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007544 }
7545 }
7546
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007547 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007548 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7549 * network status based on which carrier apps could apply actions accordingly,
7550 * enable/disable default url handler for example.
7551 *
7552 * @param subId the subscription ID that this action applies to.
7553 * @param report control start/stop reporting the default network status.
7554 * {@hide}
7555 */
7556 @Override
7557 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7558 enforceModifyPermission();
7559 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560
7561 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007562 if (phone == null) {
7563 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7564 return;
7565 }
7566 try {
7567 phone.carrierActionReportDefaultNetworkStatus(report);
7568 } catch (Exception e) {
7569 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 } finally {
7571 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007572 }
7573 }
7574
7575 /**
fionaxud9622282017-07-17 17:51:30 -07007576 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7577 * @param subId the subscription ID that this action applies to.
7578 * {@hide}
7579 */
7580 @Override
7581 public void carrierActionResetAll(int subId) {
7582 enforceModifyPermission();
7583 final Phone phone = getPhone(subId);
7584 if (phone == null) {
7585 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7586 return;
7587 }
7588 try {
7589 phone.carrierActionResetAll();
7590 } catch (Exception e) {
7591 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7592 }
7593 }
7594
7595 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007596 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7597 * bug report is being generated.
7598 */
7599 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007600 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7602 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007603 writer.println("Permission Denial: can't dump Phone from pid="
7604 + Binder.getCallingPid()
7605 + ", uid=" + Binder.getCallingUid()
7606 + "without permission "
7607 + android.Manifest.permission.DUMP);
7608 return;
7609 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007611 }
Jack Yueb89b242016-06-22 13:27:47 -07007612
Brad Ebingerdac2f002018-04-03 15:17:52 -07007613 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007614 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7615 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7616 @NonNull String[] args) {
7617 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7618 this, in.getFileDescriptor(), out.getFileDescriptor(),
7619 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007620 }
7621
Jack Yueb89b242016-06-22 13:27:47 -07007622 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007623 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007624 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007625 * @param reason the reason the data enable change is taking place
7626 * @param enabled True if enabling the data, otherwise disabling.
7627 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007628 */
7629 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007630 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007631 boolean enabled) {
7632 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7633 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7634 try {
7635 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007636 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007637 } catch (SecurityException se) {
7638 enforceModifyPermission();
7639 }
7640 } else {
7641 enforceModifyPermission();
7642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Phone phone = getPhone(subId);
7647 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007648 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7649 phone.carrierActionSetMeteredApnsEnabled(enabled);
7650 } else {
7651 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 }
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007656 }
7657 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007658
7659 /**
7660 * Get Client request stats
7661 * @return List of Client Request Stats
7662 * @hide
7663 */
7664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7666 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007668 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007669 return null;
7670 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007671 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 if (phone != null) {
7676 return phone.getClientRequestStats();
7677 }
7678
7679 return null;
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007683 }
7684
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007685 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007686 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007687 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007688 }
Jack Yueb4124c2017-02-16 15:32:43 -08007689
7690 /**
Grace Chen70990072017-03-24 17:21:30 -07007691 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007692 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007693 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007694 * @param state State of SIM (power down, power up, pass through)
7695 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7696 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7697 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007698 *
7699 **/
7700 @Override
Grace Chen70990072017-03-24 17:21:30 -07007701 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007702 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007703 Phone phone = PhoneFactory.getPhone(slotIndex);
7704
vagdeviaf9a5b92018-08-15 16:01:53 -07007705 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007710 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 }
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007714 }
7715 }
Shuo Qiandd210312017-04-12 22:11:33 +00007716
Tyler Gunn65d45c22017-06-05 11:22:26 -07007717 private boolean isUssdApiAllowed(int subId) {
7718 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007719 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007720 if (configManager == null) {
7721 return false;
7722 }
7723 PersistableBundle pb = configManager.getConfigForSubId(subId);
7724 if (pb == null) {
7725 return false;
7726 }
7727 return pb.getBoolean(
7728 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7729 }
7730
Shuo Qiandd210312017-04-12 22:11:33 +00007731 /**
7732 * Check if phone is in emergency callback mode
7733 * @return true if phone is in emergency callback mode
7734 * @param subId sub id
7735 */
goneil9c5f4872017-12-05 14:07:56 -08007736 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007737 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007738 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007739 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740
7741 final long identity = Binder.clearCallingIdentity();
7742 try {
7743 if (phone != null) {
7744 return phone.isInEcm();
7745 } else {
7746 return false;
7747 }
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007750 }
7751 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007752
7753 /**
7754 * Get the current signal strength information for the given subscription.
7755 * Because this information is not updated when the device is in a low power state
7756 * it should not be relied-upon to be current.
7757 * @param subId Subscription index
7758 * @return the most recent cached signal strength info from the modem
7759 */
7760 @Override
7761 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 final long identity = Binder.clearCallingIdentity();
7763 try {
7764 Phone p = getPhone(subId);
7765 if (p == null) {
7766 return null;
7767 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 return p.getSignalStrength();
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007773 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007774
Pengquan Meng77b7f132018-08-22 14:49:57 -07007775 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007776 * Get the current modem radio state for the given slot.
7777 * @param slotIndex slot index.
7778 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007779 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007780 * @return the current radio power state from the modem
7781 */
7782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007783 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007784 Phone phone = PhoneFactory.getPhone(slotIndex);
7785 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7787 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007788 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7789 }
7790
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 return phone.getRadioPowerState();
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
7797 }
7798 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7799 }
7800
7801 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007802 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7803 *
7804 * <p>Requires one of the following permissions:
7805 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7806 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7807 * privileges.
7808 *
7809 * @param subId subscription id
7810 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7811 * {@code false}.
7812 */
7813 @Override
7814 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007815 try {
7816 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7817 null);
7818 } catch (Exception e) {
7819 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7820 mApp, subId, "isDataRoamingEnabled");
7821 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007822
Pengquan Menga1bb6272018-09-06 09:59:22 -07007823 boolean isEnabled = false;
7824 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007825 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007826 Phone phone = getPhone(subId);
7827 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007828 } finally {
7829 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007830 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007831 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007832 }
7833
7834
7835 /**
7836 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7837 *
7838 * <p> Requires permission:
7839 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7840 * privileges.
7841 *
7842 * @param subId subscription id
7843 * @param isEnabled {@code true} means enable, {@code false} means disable.
7844 */
7845 @Override
7846 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7848 mApp, subId, "setDataRoamingEnabled");
7849
Pengquan Menga1bb6272018-09-06 09:59:22 -07007850 final long identity = Binder.clearCallingIdentity();
7851 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007852 Phone phone = getPhone(subId);
7853 if (phone != null) {
7854 phone.setDataRoamingEnabled(isEnabled);
7855 }
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007858 }
7859 }
7860
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007861 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007862 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007863 TelephonyPermissions
7864 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007865 mApp, subId, "isManualNetworkSelectionAllowed");
7866
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007867 boolean isAllowed = true;
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007870 Phone phone = getPhone(subId);
7871 if (phone != null) {
7872 isAllowed = phone.isCspPlmnEnabled();
7873 }
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
7877 return isAllowed;
7878 }
7879
7880 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007881 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007882 // Verify that tha callingPackage belongs to the calling UID
7883 mApp.getSystemService(AppOpsManager.class)
7884 .checkPackage(Binder.getCallingUid(), callingPackage);
7885
Jordan Liu1e142fc2019-04-22 15:10:43 -07007886 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007887 try {
7888 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007889 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007890 } catch (SecurityException e) {
7891 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7892 // has carrier privileges on an active UICC
7893 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7894 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007895 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007896 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007897 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007898
7899 final long identity = Binder.clearCallingIdentity();
7900 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007901 UiccController uiccController = UiccController.getInstance();
7902 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007903 if (hasReadPermission) {
7904 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007905 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007906
7907 // Remove private info if the caller doesn't have access
7908 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7909 for (UiccCardInfo cardInfo : cardInfos) {
7910 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7911 // is available
7912 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7913 if (card == null || card.getUiccProfile() == null) {
7914 // assume no access if the card or profile is unavailable
7915 filteredInfos.add(cardInfo.getUnprivileged());
7916 continue;
7917 }
7918 UiccProfile profile = card.getUiccProfile();
7919 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7920 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7921 filteredInfos.add(cardInfo);
7922 } else {
7923 filteredInfos.add(cardInfo.getUnprivileged());
7924 }
7925 }
7926 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
7930 }
7931
7932 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007933 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007934 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7939 if (slots == null) {
7940 Rlog.i(LOG_TAG, "slots is null.");
7941 return null;
7942 }
7943
7944 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7945 for (int i = 0; i < slots.length; i++) {
7946 UiccSlot slot = slots[i];
7947 if (slot == null) {
7948 continue;
7949 }
7950
Jordan Liu7be7e652019-05-06 18:55:02 +00007951 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 UiccCard card = slot.getUiccCard();
7953 if (card != null) {
7954 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007955 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007956 cardId = slot.getEid();
7957 if (TextUtils.isEmpty(cardId)) {
7958 cardId = slot.getIccId();
7959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 }
7961
Jordan Liu857451f2019-05-09 16:35:35 -07007962 if (cardId != null) {
7963 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7964 // if cardId is an EID, it's all digits so this is fine
7965 cardId = IccUtils.stripTrailingFs(cardId);
7966 }
7967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 int cardState = 0;
7969 switch (slot.getCardState()) {
7970 case CARDSTATE_ABSENT:
7971 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7972 break;
7973 case CARDSTATE_PRESENT:
7974 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7975 break;
7976 case CARDSTATE_ERROR:
7977 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7978 break;
7979 case CARDSTATE_RESTRICTED:
7980 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7981 break;
7982 default:
7983 break;
7984
7985 }
7986
7987 infos[i] = new UiccSlotInfo(
7988 slot.isActive(),
7989 slot.isEuicc(),
7990 cardId,
7991 cardState,
7992 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007993 slot.isExtendedApduSupported(),
7994 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 }
7996 return infos;
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008000 }
8001
8002 @Override
8003 public boolean switchSlots(int[] physicalSlots) {
8004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
8011 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008012 }
Jack Yu4c988042018-02-27 15:30:01 -08008013
8014 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008015 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008016 final long identity = Binder.clearCallingIdentity();
8017 try {
8018 return UiccController.getInstance().getCardIdForDefaultEuicc();
8019 } finally {
8020 Binder.restoreCallingIdentity(identity);
8021 }
8022 }
8023
Pengquan Meng85728fb2018-03-12 16:31:21 -07008024 /**
goneil47ffb6e2018-04-06 15:40:58 -07008025 * A test API to reload the UICC profile.
8026 *
8027 * <p>Requires that the calling app has permission
8028 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8029 * @hide
8030 */
8031 @Override
8032 public void refreshUiccProfile(int subId) {
8033 enforceModifyPermission();
8034
8035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 Phone phone = getPhone(subId);
8038 if (phone == null) {
8039 return;
8040 }
8041 UiccCard uiccCard = phone.getUiccCard();
8042 if (uiccCard == null) {
8043 return;
8044 }
8045 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8046 if (uiccProfile == null) {
8047 return;
8048 }
8049 uiccProfile.refresh();
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
8052 }
8053 }
8054
8055 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008056 * Returns false if the mobile data is disabled by default, otherwise return true.
8057 */
8058 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008059 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008060 }
8061
8062 /**
8063 * Returns true if the data roaming is enabled by default, i.e the system property
8064 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8065 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8066 */
8067 private boolean getDefaultDataRoamingEnabled(int subId) {
8068 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008069 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008070 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008071 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8072 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8073 return isDataRoamingEnabled;
8074 }
8075
8076 /**
8077 * Returns the default network type for the given {@code subId}, if the default network type is
8078 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8079 */
8080 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008081 List<Integer> list = TelephonyProperties.default_network();
8082 int phoneId = mSubscriptionController.getPhoneId(subId);
8083 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8084 return list.get(phoneId);
8085 }
8086 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008087 }
fionaxua13278b2018-03-21 00:08:13 -07008088
8089 @Override
8090 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008091 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
8094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 final Phone phone = getPhone(subId);
8097 if (phone == null) {
8098 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8099 return;
8100 }
chen xueaba88a2019-03-15 13:15:10 -07008101 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8102 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008103 if (carrierPrivilegeRules == null) {
8104 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8105 } else {
8106 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 } finally {
8109 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008110 }
fionaxua13278b2018-03-21 00:08:13 -07008111 }
8112
8113 @Override
8114 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 final Phone phone = getPhone(subId);
8120 if (phone == null) {
8121 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8122 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8123 }
8124 return phone.getCarrierIdListVersion();
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008127 }
fionaxua13278b2018-03-21 00:08:13 -07008128 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008129
8130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008131 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8132 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008134 mApp, subId, callingPackage, callingFeatureId,
8135 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008136 return -1;
8137 }
8138
8139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
8144 }
8145 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008146
8147 @Override
8148 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008149 TelephonyPermissions
8150 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008151 mApp, subId, "getCdmaRoamingMode");
8152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
8159 }
8160
8161 @Override
8162 public boolean setCdmaRoamingMode(int subId, int mode) {
8163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8164 mApp, subId, "setCdmaRoamingMode");
8165
8166 final long identity = Binder.clearCallingIdentity();
8167 try {
8168 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
8174 @Override
8175 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8177 mApp, subId, "setCdmaSubscriptionMode");
8178
8179 final long identity = Binder.clearCallingIdentity();
8180 try {
8181 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
8185 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008186
sqianc5eccab2018-10-19 18:46:41 -07008187 @Override
sqian8c685422019-02-22 15:55:18 -08008188 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008189 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008191 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8192 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008193 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8194 }
8195 final long identity = Binder.clearCallingIdentity();
8196 try {
sqian854d44b2018-12-12 16:48:18 -08008197 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8198 for (Phone phone: PhoneFactory.getPhones()) {
8199 if (phone.getEmergencyNumberTracker() != null
8200 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8201 emergencyNumberListInternal.put(
8202 phone.getSubId(),
8203 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8204 }
sqian11b7a0e2018-12-05 18:48:28 -08008205 }
sqian854d44b2018-12-12 16:48:18 -08008206 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
sqianc5eccab2018-10-19 18:46:41 -07008210 }
8211
8212 @Override
sqian8c685422019-02-22 15:55:18 -08008213 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008214 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008215 if (!exactMatch) {
8216 TelephonyPermissions
8217 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008218 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008219 }
8220 final long identity = Binder.clearCallingIdentity();
8221 try {
sqian854d44b2018-12-12 16:48:18 -08008222 for (Phone phone: PhoneFactory.getPhones()) {
8223 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008224 && phone.getEmergencyNumberTracker()
8225 .isEmergencyNumber(number, exactMatch)) {
8226 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008227 }
sqian11b7a0e2018-12-05 18:48:28 -08008228 }
8229 return false;
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
8232 }
8233 }
8234
sqianf4ca7ed2019-01-15 18:32:07 -08008235 /**
8236 * Update emergency number list for test mode.
8237 */
8238 @Override
8239 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8240 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8241 "updateEmergencyNumberListTestMode");
8242
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 for (Phone phone: PhoneFactory.getPhones()) {
8246 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8247 if (tracker != null) {
8248 tracker.executeEmergencyNumberTestModeCommand(action, num);
8249 }
8250 }
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 }
8255
8256 /**
8257 * Get the full emergency number list for test mode.
8258 */
8259 @Override
8260 public List<String> getEmergencyNumberListTestMode() {
8261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8262 "getEmergencyNumberListTestMode");
8263
8264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 Set<String> emergencyNumbers = new HashSet<>();
8267 for (Phone phone: PhoneFactory.getPhones()) {
8268 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8269 if (tracker != null) {
8270 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8271 emergencyNumbers.add(num.getNumber());
8272 }
8273 }
8274 }
8275 return new ArrayList<>(emergencyNumbers);
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
8279 }
8280
chen xud6b45bd2018-10-30 22:27:10 -07008281 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008282 public int getEmergencyNumberDbVersion(int subId) {
8283 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8284
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 final Phone phone = getPhone(subId);
8288 if (phone == null) {
8289 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8290 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8291 }
8292 return phone.getEmergencyNumberDbVersion();
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
8297
8298 @Override
8299 public void notifyOtaEmergencyNumberDbInstalled() {
8300 enforceModifyPermission();
8301
8302 final long identity = Binder.clearCallingIdentity();
8303 try {
8304 for (Phone phone: PhoneFactory.getPhones()) {
8305 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8306 if (tracker != null) {
8307 tracker.updateOtaEmergencyNumberDatabase();
8308 }
8309 }
8310 } finally {
8311 Binder.restoreCallingIdentity(identity);
8312 }
8313 }
8314
8315 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008316 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008317 enforceActiveEmergencySessionPermission();
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 for (Phone phone: PhoneFactory.getPhones()) {
8322 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8323 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008324 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8325 }
8326 }
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 @Override
8333 public void resetOtaEmergencyNumberDbFilePath() {
8334 enforceActiveEmergencySessionPermission();
8335
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 for (Phone phone: PhoneFactory.getPhones()) {
8339 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8340 if (tracker != null) {
8341 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008342 }
8343 }
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
8347 }
8348
8349 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008350 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8351 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8352 Phone phone = getPhone(subId);
8353 if (phone == null) {
8354 return null;
8355 }
8356 final long identity = Binder.clearCallingIdentity();
8357 try {
8358 UiccProfile profile = UiccController.getInstance()
8359 .getUiccProfileForPhone(phone.getPhoneId());
8360 if (profile != null) {
8361 return profile.getCertsFromCarrierPrivilegeAccessRules();
8362 }
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
8366 return null;
8367 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008368
8369 /**
8370 * Enable or disable a modem stack.
8371 */
8372 @Override
8373 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8374 enforceModifyPermission();
8375
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 Phone phone = PhoneFactory.getPhone(slotIndex);
8379 if (phone == null) {
8380 return false;
8381 } else {
8382 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8383 }
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
Michelecea4cf22018-12-21 15:00:11 -08008388
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008389 /**
8390 * Whether a modem stack is enabled or not.
8391 */
8392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008393 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8394 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008395 Phone phone = PhoneFactory.getPhone(slotIndex);
8396 if (phone == null) return false;
8397
8398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008399 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8400 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008401 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8402 }
8403
8404 final long identity = Binder.clearCallingIdentity();
8405 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008406 try {
8407 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8408 } catch (NoSuchElementException ex) {
8409 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8410 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
Michelecea4cf22018-12-21 15:00:11 -08008416 @Override
Michele0ea7d782019-03-19 14:58:42 -07008417 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008418 enforceModifyPermission();
8419
8420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008423 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008424 .commit();
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
8428 }
8429
8430 @Override
Michele0ea7d782019-03-19 14:58:42 -07008431 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008432 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008434 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8435 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008436 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008437 }
Michelecea4cf22018-12-21 15:00:11 -08008438
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
Michele0ea7d782019-03-19 14:58:42 -07008441 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008442 } finally {
8443 Binder.restoreCallingIdentity(identity);
8444 }
8445 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008446
Michele0ea7d782019-03-19 14:58:42 -07008447 @TelephonyManager.IsMultiSimSupportedResult
8448 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008449 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8450 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8451 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008452 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8453 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008454 }
8455 // Check if the hardware supports multisim functionality. If usage of multisim is not
8456 // supported by the modem, indicate that it is restricted.
8457 PhoneCapability staticCapability =
8458 mPhoneConfigurationManager.getStaticPhoneCapability();
8459 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008460 loge("isMultiSimSupportedInternal: no static configuration available");
8461 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008462 }
Sarah Chin7caee492020-02-18 20:49:02 +00008463 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008464 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8465 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008466 }
8467 // Check if support of multiple SIMs is restricted by carrier
8468 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008469 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008470 }
8471
Michele0ea7d782019-03-19 14:58:42 -07008472 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008473 }
8474
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008475 /**
8476 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008477 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8478 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8479 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008480 * @param numOfSims number of active sims we want to switch to
8481 */
8482 @Override
8483 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008484 if (numOfSims == 1) {
8485 enforceModifyPermission();
8486 } else {
8487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8488 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8489 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008490 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008491
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008492 try {
Michele30b57b22019-03-01 12:01:14 -08008493 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008494 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008495 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8496 return;
8497 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008498 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
8502 }
8503
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008504 @Override
8505 public boolean isApplicationOnUicc(int subId, int appType) {
8506 enforceReadPrivilegedPermission("isApplicationOnUicc");
8507 Phone phone = getPhone(subId);
8508 if (phone == null) {
8509 return false;
8510 }
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 UiccCard uiccCard = phone.getUiccCard();
8514 if (uiccCard == null) {
8515 return false;
8516 }
8517 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8518 if (uiccProfile == null) {
8519 return false;
8520 }
8521 if (TelephonyManager.APPTYPE_SIM <= appType
8522 && appType <= TelephonyManager.APPTYPE_ISIM) {
8523 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8524 }
8525 return false;
8526 } finally {
8527 Binder.restoreCallingIdentity(identity);
8528 }
8529 }
8530
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008531 /**
chen xub4baa772019-04-03 10:23:41 -07008532 * Get whether making changes to modem configurations will trigger reboot.
8533 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008534 */
8535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008536 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8537 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008539 mApp, subId, callingPackage, callingFeatureId,
8540 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008541 return false;
8542 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
Nathan Harold29f5f052019-02-15 13:41:57 -08008551 private void updateModemStateMetrics() {
8552 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8553 // TODO: check the state for each modem if the api is ready.
8554 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8555 }
8556
Pengquan Meng3889a572019-01-23 11:16:29 -08008557 @Override
8558 public int[] getSlotsMapping() {
8559 enforceReadPrivilegedPermission("getSlotsMapping");
8560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8564 // All logical slots should have a mapping to a physical slot.
8565 int[] logicalSlotsMapping = new int[phoneCount];
8566 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8567 for (int i = 0; i < slotInfos.length; i++) {
8568 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8569 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8570 }
8571 }
8572 return logicalSlotsMapping;
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008577
8578 /**
8579 * Get the IRadio HAL Version
8580 */
8581 @Override
8582 public int getRadioHalVersion() {
8583 Phone phone = getDefaultPhone();
8584 if (phone == null) return -1;
8585 HalVersion hv = phone.getHalVersion();
8586 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8587 return hv.major * 100 + hv.minor;
8588 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008589
8590 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008591 * Get the current calling package name.
8592 * @return the current calling package name
8593 */
8594 @Override
8595 public String getCurrentPackageName() {
8596 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8597 }
8598
8599 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008600 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8601 * corresponding network requests on a subId.
8602 *
8603 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008604 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008605 * 2) APN is un-metered for this subscription, or
8606 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008607 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008608 *
8609 * @return whether data is allowed for a apn type.
8610 *
8611 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008612 */
8613 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008614 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008615 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8616 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008617
8618 // Now that all security checks passes, perform the operation as ourselves.
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 Phone phone = getPhone(subId);
8622 if (phone == null) return false;
8623
Jack Yu41407ee2019-05-13 16:54:09 -07008624 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008625 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630
8631 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008632 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008633 enforceReadPrivilegedPermission("isApnMetered");
8634
8635 // Now that all security checks passes, perform the operation as ourselves.
8636 final long identity = Binder.clearCallingIdentity();
8637 try {
8638 Phone phone = getPhone(subId);
8639 if (phone == null) return true; // By default return true.
8640
Jack Yu41407ee2019-05-13 16:54:09 -07008641 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008642 } finally {
8643 Binder.restoreCallingIdentity(identity);
8644 }
8645 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008646
8647 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008648 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8649 int subscriptionId, IBooleanConsumer resultCallback) {
8650 enforceModifyPermission();
8651 long token = Binder.clearCallingIdentity();
8652 try {
8653 Phone phone = getPhone(subscriptionId);
8654 if (phone == null) {
8655 try {
8656 if (resultCallback != null) {
8657 resultCallback.accept(false);
8658 }
8659 } catch (RemoteException e) {
8660 // ignore
8661 }
8662 return;
8663 }
8664 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8665 Pair.create(specifiers, (x) -> {
8666 try {
8667 if (resultCallback != null) {
8668 resultCallback.accept(x);
8669 }
8670 } catch (RemoteException e) {
8671 // ignore
8672 }
8673 });
8674 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8675 } finally {
8676 Binder.restoreCallingIdentity(token);
8677 }
8678 }
8679
8680 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008681 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008682 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008683 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8684 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8685 if (iccRecords == null) {
8686 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8687 return false;
8688 }
8689 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8690 }
8691
8692 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008693 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8694 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008695 if (callingPackage == null) {
8696 callingPackage = getCurrentPackageName();
8697 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008698 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8699 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008700 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8701 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008702 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8703 }
8704 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8705 Intent intent = new Intent();
8706 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8707 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8708 // Bring up choose default SMS subscription dialog right now
8709 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8710 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8711 mApp.startActivity(intent);
8712 }
chen xud5ca2d52019-05-28 15:20:57 -07008713
8714 @Override
8715 public String getMmsUAProfUrl(int subId) {
8716 //TODO investigate if this API should require proper permission check in R b/133791609
8717 final long identity = Binder.clearCallingIdentity();
8718 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008719 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8720 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8721 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8722 return carrierUAProfUrl;
8723 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008724 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8725 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
8730
8731 @Override
8732 public String getMmsUserAgent(int subId) {
8733 //TODO investigate if this API should require proper permission check in R b/133791609
8734 final long identity = Binder.clearCallingIdentity();
8735 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008736 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8737 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8738 if (!TextUtils.isEmpty(carrierUserAgent)) {
8739 return carrierUserAgent;
8740 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008741 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8742 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008743 } finally {
8744 Binder.restoreCallingIdentity(identity);
8745 }
8746 }
Jack Yub07d4972019-05-28 16:12:25 -07008747
8748 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008749 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8750 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008751
Jack Yub07d4972019-05-28 16:12:25 -07008752 final long identity = Binder.clearCallingIdentity();
8753 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008754 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008755 if (phone == null) return false;
8756
Hall Liua62f5da2020-09-25 10:42:19 -07008757 switch (policy) {
8758 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8759 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8760 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8761 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8762 default:
8763 throw new IllegalArgumentException(policy + " is not a valid policy");
8764 }
Jack Yub07d4972019-05-28 16:12:25 -07008765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008771 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8772 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008773 enforceModifyPermission();
8774
changbettyd5c246e2019-12-24 15:40:37 +08008775 final long identity = Binder.clearCallingIdentity();
8776 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008777 Phone phone = getPhone(subscriptionId);
8778 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008779
Hall Liua62f5da2020-09-25 10:42:19 -07008780 switch (policy) {
8781 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8782 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8783 break;
8784 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8785 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8786 break;
8787 default:
8788 throw new IllegalArgumentException(policy + " is not a valid policy");
8789 }
changbettyd5c246e2019-12-24 15:40:37 +08008790 } finally {
8791 Binder.restoreCallingIdentity(identity);
8792 }
8793 }
8794
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008795 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008796 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008797 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8798 * otherwise.
8799 */
8800 @Override
8801 public void setCepEnabled(boolean isCepEnabled) {
8802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8803
8804 final long identity = Binder.clearCallingIdentity();
8805 try {
8806 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8807 for (Phone phone : PhoneFactory.getPhones()) {
8808 Phone defaultPhone = phone.getImsPhone();
8809 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8810 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8811 ImsPhoneCallTracker imsPhoneCallTracker =
8812 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8813 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8814 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8815 + imsPhone.getMsisdn());
8816 }
8817 }
8818 } finally {
8819 Binder.restoreCallingIdentity(identity);
8820 }
8821 }
allenwtsu46dcc572020-01-08 18:24:03 +08008822
8823 /**
8824 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8825 *
8826 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8827 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8828 * before being read.
8829 */
8830 @Override
8831 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8832 isCompressed) {
8833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8834 mApp, subId, "notifyRcsAutoConfigurationReceived");
8835 try {
8836 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8837 if (configBinder == null) {
8838 Rlog.e(LOG_TAG, "null result for getImsConfig");
8839 } else {
8840 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8841 }
8842 } catch (RemoteException e) {
8843 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8844 }
8845 }
zoey chene02881a2019-12-30 16:11:23 +08008846
8847 @Override
8848 public boolean isIccLockEnabled(int subId) {
8849 enforceReadPrivilegedPermission("isIccLockEnabled");
8850
8851 // Now that all security checks passes, perform the operation as ourselves.
8852 final long identity = Binder.clearCallingIdentity();
8853 try {
8854 Phone phone = getPhone(subId);
8855 if (phone != null && phone.getIccCard() != null) {
8856 return phone.getIccCard().getIccLockEnabled();
8857 } else {
8858 return false;
8859 }
8860 } finally {
8861 Binder.restoreCallingIdentity(identity);
8862 }
8863 }
8864
8865 /**
8866 * Set the ICC pin lock enabled or disabled.
8867 *
8868 * @return an integer representing the status of IccLock enabled or disabled in the following
8869 * three cases:
8870 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8871 * successfully.
8872 * - Positive number and zero for remaining password attempts.
8873 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8874 *
8875 */
8876 @Override
8877 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8878 enforceModifyPermission();
8879
8880 Phone phone = getPhone(subId);
8881 if (phone == null) {
8882 return 0;
8883 }
8884 // Now that all security checks passes, perform the operation as ourselves.
8885 final long identity = Binder.clearCallingIdentity();
8886 try {
8887 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8888 new Pair<Boolean, String>(enabled, password), phone, null);
8889 return attemptsRemaining;
8890
8891 } catch (Exception e) {
8892 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8893 } finally {
8894 Binder.restoreCallingIdentity(identity);
8895 }
8896 return 0;
8897 }
8898
8899 /**
8900 * Change the ICC password used in ICC pin lock.
8901 *
8902 * @return an integer representing the status of IccLock changed in the following three cases:
8903 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8904 * - Positive number and zero for remaining password attempts.
8905 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8906 *
8907 */
8908 @Override
8909 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8910 enforceModifyPermission();
8911
8912 Phone phone = getPhone(subId);
8913 if (phone == null) {
8914 return 0;
8915 }
8916 // Now that all security checks passes, perform the operation as ourselves.
8917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8920 new Pair<String, String>(oldPassword, newPassword), phone, null);
8921 return attemptsRemaining;
8922
8923 } catch (Exception e) {
8924 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
8927 }
8928 return 0;
8929 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008930
8931 /**
8932 * Request for receiving user activity notification
8933 */
8934 @Override
8935 public void requestUserActivityNotification() {
8936 if (!mNotifyUserActivity.get()
8937 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8938 mNotifyUserActivity.set(true);
8939 }
8940 }
8941
8942 /**
8943 * Called when userActivity is signalled in the power manager.
8944 * This is safe to call from any thread, with any window manager locks held or not.
8945 */
8946 @Override
8947 public void userActivity() {
8948 // ***************************************
8949 // * Inherited from PhoneWindowManager *
8950 // ***************************************
8951 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8952 // WITH ITS LOCKS HELD.
8953 //
8954 // This code must be VERY careful about the locks
8955 // it acquires.
8956 // In fact, the current code acquires way too many,
8957 // and probably has lurking deadlocks.
8958
8959 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8960 throw new SecurityException("Only the OS may call notifyUserActivity()");
8961 }
8962
8963 if (mNotifyUserActivity.getAndSet(false)) {
8964 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8965 USER_ACTIVITY_NOTIFICATION_DELAY);
8966 }
8967 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008968
8969 @Override
8970 public boolean canConnectTo5GInDsdsMode() {
8971 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8972 }
Jack Yud10cdd42020-09-28 20:28:01 -07008973
8974 @Override
8975 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8976 String callingFeatureId) {
8977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8978 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8979 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8980 }
8981
8982 Phone phone = getPhone(subId);
8983 if (phone == null) {
8984 throw new RuntimeException("phone is not available");
8985 }
8986 // Now that all security checks passes, perform the operation as ourselves.
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 return phone.getEquivalentHomePlmns();
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008994}