blob: 48b8fa5872ea95a926e873ee3771ef3032c74435 [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;
Sarah Chinbaab1432020-10-28 13:46:24 -0700297 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
298 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800300 // Parameters of select command.
301 private static final int SELECT_COMMAND = 0xA4;
302 private static final int SELECT_P1 = 0x04;
303 private static final int SELECT_P2 = 0;
304 private static final int SELECT_P3 = 0x10;
305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 /** The singleton instance. */
307 private static PhoneInterfaceManager sInstance;
308
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800311 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700312 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800313 private AppOpsManager mAppOps;
314 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800315 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800316 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700317 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318
Peter Wangdafb9ac2020-01-15 14:13:38 -0800319 /** User Activity */
320 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800321 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
322
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700323 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
324
Derek Tan97ebb422014-09-05 16:55:38 -0700325 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
326 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800327 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800328 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700329
Michelecea4cf22018-12-21 15:00:11 -0800330 // String to store multi SIM allowed
331 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
332
Derek Tan740e1672017-06-27 14:56:27 -0700333 // The AID of ISD-R.
334 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
335
yinxub1bed742017-04-17 11:45:04 -0700336 private NetworkScanRequestTracker mNetworkScanRequestTracker;
337
David Kelly5e06a7f2018-03-12 14:10:59 +0000338 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
339 private static final int MANUFACTURER_CODE_LENGTH = 8;
340
Derek Tan89e89d42014-07-08 17:00:10 -0700341 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700342 * Experiment flag to enable erase modem config on reset network, default value is false
343 */
344 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
345 "reset_network_erase_modem_config_enabled";
346
347 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700348 * A request object to use for transmitting data to an ICC.
349 */
350 private static final class IccAPDUArgument {
351 public int channel, cla, command, p1, p2, p3;
352 public String data;
353
354 public IccAPDUArgument(int channel, int cla, int command,
355 int p1, int p2, int p3, String data) {
356 this.channel = channel;
357 this.cla = cla;
358 this.command = command;
359 this.p1 = p1;
360 this.p2 = p2;
361 this.p3 = p3;
362 this.data = data;
363 }
364 }
365
366 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700367 * A request object to use for transmitting data to an ICC.
368 */
369 private static final class ManualNetworkSelectionArgument {
370 public OperatorInfo operatorInfo;
371 public boolean persistSelection;
372
373 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
374 this.operatorInfo = operatorInfo;
375 this.persistSelection = persistSelection;
376 }
377 }
378
379 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
381 * request after sending. The main thread will notify the request when it is complete.
382 */
383 private static final class MainThreadRequest {
384 /** The argument to use for the request */
385 public Object argument;
386 /** The result of the request that is run on the main thread */
387 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800388 // The subscriber id that this request applies to. Defaults to
389 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
390 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 // In cases where subId is unavailable, the caller needs to specify the phone.
393 public Phone phone;
394
vagdeviaf9a5b92018-08-15 16:01:53 -0700395 public WorkSource workSource;
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 public MainThreadRequest(Object argument) {
398 this.argument = argument;
399 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400
Nathan Harold92bed182018-10-12 18:16:49 -0700401 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
402 this.argument = argument;
403 if (phone != null) {
404 this.phone = phone;
405 }
406 this.workSource = workSource;
407 }
408
vagdeviaf9a5b92018-08-15 16:01:53 -0700409 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800410 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800411 if (subId != null) {
412 this.subId = subId;
413 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700414 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 }
417
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800418 private static final class IncomingThirdPartyCallArgs {
419 public final ComponentName component;
420 public final String callId;
421 public final String callerDisplayName;
422
423 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
424 String callerDisplayName) {
425 this.component = component;
426 this.callId = callId;
427 this.callerDisplayName = callerDisplayName;
428 }
429 }
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 /**
432 * A handler that processes messages on the main thread in the phone process. Since many
433 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
434 * inbound binder threads to the main thread in the phone process. The Binder thread
435 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
436 * on, which will be notified when the operation completes and will contain the result of the
437 * request.
438 *
439 * <p>If a MainThreadRequest object is provided in the msg.obj field,
440 * note that request.result must be set to something non-null for the calling thread to
441 * unblock.
442 */
443 private final class MainThreadHandler extends Handler {
444 @Override
445 public void handleMessage(Message msg) {
446 MainThreadRequest request;
447 Message onCompleted;
448 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800451 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
453 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 case CMD_HANDLE_USSD_REQUEST: {
455 request = (MainThreadRequest) msg.obj;
456 final Phone phone = getPhoneFromRequest(request);
457 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
458 String ussdRequest = ussdObject.first;
459 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700460
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 if (!isUssdApiAllowed(request.subId)) {
462 // Carrier does not support use of this API, return failure.
463 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
464 UssdResponse response = new UssdResponse(ussdRequest, null);
465 Bundle returnData = new Bundle();
466 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
467 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700468
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 request.result = true;
470 notifyRequester(request);
471 return;
472 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700473
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 try {
475 request.result = phone != null
476 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
477 } catch (CallStateException cse) {
478 request.result = false;
479 }
480 // Wake up the requesting thread
481 notifyRequester(request);
482 break;
pkanwar32d516d2016-10-14 19:37:38 -0700483 }
484
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 final Phone phone = getPhoneFromRequest(request);
488 request.result = phone != null ?
489 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
490 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduLogicalChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
506 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700507 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 iccArgument.channel, iccArgument.cla, iccArgument.command,
509 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 break;
513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800523 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800525 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 } else {
527 loge("iccTransmitApduLogicalChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 break;
532
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccTransmitApduBasicChannel: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
543 request);
544 uiccCard.iccTransmitApduBasicChannel(
545 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
546 iccArgument.p3, iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("iccTransmitApduBasicChannel: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("iccTransmitApduBasicChannel: CommandException: " +
561 ar.exception);
562 } else {
563 loge("iccTransmitApduBasicChannel: Unknown exception");
564 }
565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 break;
568
569 case CMD_EXCHANGE_SIM_IO:
570 request = (MainThreadRequest) msg.obj;
571 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 if (uiccCard == null) {
574 loge("iccExchangeSimIO: No UICC");
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 } else {
578 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
579 request);
580 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
581 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
582 iccArgument.data, onCompleted);
583 }
584 break;
585
586 case EVENT_EXCHANGE_SIM_IO_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
589 if (ar.exception == null && ar.result != null) {
590 request.result = ar.result;
591 } else {
592 request.result = new IccIoResult(0x6f, 0, (byte[])null);
593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 break;
596
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 case CMD_SEND_ENVELOPE:
598 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800599 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 if (uiccCard == null) {
601 loge("sendEnvelopeWithStatus: No UICC");
602 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
606 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
607 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 break;
609
610 case EVENT_SEND_ENVELOPE_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700613 if (ar.exception == null && ar.result != null) {
614 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
617 if (ar.result == null) {
618 loge("sendEnvelopeWithStatus: Empty response");
619 } else if (ar.exception instanceof CommandException) {
620 loge("sendEnvelopeWithStatus: CommandException: " +
621 ar.exception);
622 } else {
623 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
624 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 break;
628
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 case CMD_OPEN_CHANNEL:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800632 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 if (uiccCard == null) {
634 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800635 request.result = new IccOpenLogicalChannelResponse(-1,
636 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800640 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
641 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case EVENT_OPEN_CHANNEL_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 int[] result = (int[]) ar.result;
651 int channelId = result[0];
652 byte[] selectResponse = null;
653 if (result.length > 1) {
654 selectResponse = new byte[result.length - 1];
655 for (int i = 1; i < result.length; ++i) {
656 selectResponse[i - 1] = (byte) result[i];
657 }
658 }
659 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 if (ar.result == null) {
663 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 if (ar.exception != null) {
666 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
667 }
668
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700670 if (ar.exception instanceof CommandException) {
671 CommandException.Error error =
672 ((CommandException) (ar.exception)).getCommandError();
673 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700674 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700675 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700676 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 }
678 }
679 openChannelResp = new IccOpenLogicalChannelResponse(
680 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700682 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
686 case CMD_CLOSE_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 if (uiccCard == null) {
690 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900691 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 } else {
694 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
695 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
699 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800700 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
701 break;
702
703 case CMD_NV_READ_ITEM:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
707 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 request.result = "";
717 if (ar.result == null) {
718 loge("nvReadItem: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("nvReadItem: CommandException: " +
721 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800723 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
725 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
Jake Hambye994d462014-02-03 13:10:13 -0800729 case CMD_NV_WRITE_ITEM:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
732 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700734 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_ITEM_DONE:
738 handleNullReturnEvent(msg, "nvWriteItem");
739 break;
740
741 case CMD_NV_WRITE_CDMA_PRL:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
747 case EVENT_NV_WRITE_CDMA_PRL_DONE:
748 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
749 break;
750
chen xu6dac5ab2018-10-26 17:39:23 -0700751 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800752 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700753 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800754 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800755 break;
756
chen xu6dac5ab2018-10-26 17:39:23 -0700757 case EVENT_RESET_MODEM_CONFIG_DONE:
758 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800759 break;
760
Sooraj Sasindran37444802020-08-11 10:40:43 -0700761 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
764 request);
765 Phone phone = getPhoneFromRequest(request);
766 if (phone != null) {
767 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
768 } else {
769 loge("isNRDualConnectivityEnabled: No phone object");
770 request.result = false;
771 notifyRequester(request);
772 }
773 break;
774 }
775
776 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
781 } else {
782 // request.result must be set to something non-null
783 // for the calling thread to unblock
784 if (request.result != null) {
785 request.result = ar.result;
786 } else {
787 request.result = false;
788 }
789 if (ar.result == null) {
790 loge("isNRDualConnectivityEnabled: Empty response");
791 } else if (ar.exception instanceof CommandException) {
792 loge("isNRDualConnectivityEnabled: CommandException: "
793 + ar.exception);
794 } else {
795 loge("isNRDualConnectivityEnabled: Unknown exception");
796 }
797 }
798 notifyRequester(request);
799 break;
800
801 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
804 Phone phone = getPhoneFromRequest(request);
805 if (phone != null) {
806 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
807 request.workSource);
808 } else {
809 loge("enableNrDualConnectivity: No phone object");
810 request.result =
811 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
812 notifyRequester(request);
813 }
814 break;
815 }
816
817 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null) {
821 request.result =
822 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
823 } else {
824 request.result =
825 TelephonyManager
826 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
827 if (ar.exception instanceof CommandException) {
828 CommandException.Error error =
829 ((CommandException) (ar.exception)).getCommandError();
830 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
831 request.result =
832 TelephonyManager
833 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
834 }
835 loge("enableNrDualConnectivity" + ": CommandException: "
836 + ar.exception);
837 } else {
838 loge("enableNrDualConnectivity" + ": Unknown exception");
839 }
840 }
841 notifyRequester(request);
842 break;
843 }
844
Jake Hamby7c27be32014-03-03 13:25:59 -0800845 case CMD_GET_PREFERRED_NETWORK_TYPE:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700848 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800849 break;
850
851 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result; // Integer
856 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530857 // request.result must be set to something non-null
858 // for the calling thread to unblock
859 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800860 if (ar.result == null) {
861 loge("getPreferredNetworkType: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("getPreferredNetworkType: CommandException: " +
864 ar.exception);
865 } else {
866 loge("getPreferredNetworkType: Unknown exception");
867 }
868 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800870 break;
871
872 case CMD_SET_PREFERRED_NETWORK_TYPE:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
875 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700876 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 break;
878
879 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
880 handleNullReturnEvent(msg, "setPreferredNetworkType");
881 break;
882
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000883 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
884 request = (MainThreadRequest)msg.obj;
885 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000887 break;
888
889 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
890 ar = (AsyncResult)msg.obj;
891 request = (MainThreadRequest)ar.userObj;
892 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700893 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000894 break;
895
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800896 case CMD_SET_VOICEMAIL_NUMBER:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
899 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800900 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
901 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800902 break;
903
904 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
905 handleNullReturnEvent(msg, "setVoicemailNumber");
906 break;
907
Stuart Scott54788802015-03-30 13:18:01 -0700908 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
911 request);
912 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
913 break;
914
915 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
916 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
917 break;
918
Shishir Agrawal302c8692015-06-19 13:49:39 -0700919 case CMD_PERFORM_NETWORK_SCAN:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
922 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
923 break;
924
Hall Liu27d24262020-09-18 19:04:59 -0700925 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700928 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
929 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
930 request.argument;
931 int callForwardingReason = args.first;
932 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800933 break;
Hall Liu27d24262020-09-18 19:04:59 -0700934 }
935 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700938 TelephonyManager.CallForwardingInfoCallback callback =
939 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
940 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800941 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700942 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800943 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
944 for (CallForwardInfo callForwardInfo : callForwardInfos) {
945 // Service Class is a bit mask per 3gpp 27.007. Search for
946 // any service for voice call.
947 if ((callForwardInfo.serviceClass
948 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700949 callForwardingInfo = new CallForwardingInfo(true,
950 callForwardInfo.reason,
951 callForwardInfo.number,
952 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800953 break;
954 }
955 }
956 // Didn't find a call forward info for voice call.
957 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700958 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
959 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800960 }
Hall Liu27d24262020-09-18 19:04:59 -0700961 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800962 } else {
963 if (ar.result == null) {
964 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
965 }
966 if (ar.exception != null) {
967 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
968 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700969 int errorCode = TelephonyManager
970 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700975 errorCode = TelephonyManager
976 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800977 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700978 errorCode = TelephonyManager
979 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800980 }
981 }
Hall Liu27d24262020-09-18 19:04:59 -0700982 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800983 }
Shuo Qian4a594052020-01-23 11:59:30 -0800984 break;
Hall Liu27d24262020-09-18 19:04:59 -0700985 }
Shuo Qian4a594052020-01-23 11:59:30 -0800986
Hall Liu27d24262020-09-18 19:04:59 -0700987 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700990 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800991 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700992 ((Pair<CallForwardingInfo, Consumer<Integer>>)
993 request.argument).first;
994 request.phone.setCallForwardingOption(
995 callForwardingInfoToSet.isEnabled()
996 ? CommandsInterface.CF_ACTION_ENABLE
997 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800998 callForwardingInfoToSet.getReason(),
999 callForwardingInfoToSet.getNumber(),
1000 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1001 break;
Hall Liu27d24262020-09-18 19:04:59 -07001002 }
Shuo Qian4a594052020-01-23 11:59:30 -08001003
Hall Liu27d24262020-09-18 19:04:59 -07001004 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001007 Consumer<Integer> callback =
1008 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1009 request.argument).second;
1010 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001011 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001012 int errorCode = TelephonyManager.CallForwardingInfoCallback
1013 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001014 if (ar.exception instanceof CommandException) {
1015 CommandException.Error error =
1016 ((CommandException) (ar.exception)).getCommandError();
1017 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager.CallForwardingInfoCallback
1019 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001020 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001021 errorCode = TelephonyManager.CallForwardingInfoCallback
1022 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001023 }
1024 }
1025 callback.accept(errorCode);
1026 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001027 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001028 }
Shuo Qian4a594052020-01-23 11:59:30 -08001029 break;
Hall Liu27d24262020-09-18 19:04:59 -07001030 }
Shuo Qian4a594052020-01-23 11:59:30 -08001031
Hall Liu27d24262020-09-18 19:04:59 -07001032 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001033 request = (MainThreadRequest) msg.obj;
1034 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1035 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1036 break;
Hall Liu27d24262020-09-18 19:04:59 -07001037 }
Shuo Qian4a594052020-01-23 11:59:30 -08001038
Hall Liu27d24262020-09-18 19:04:59 -07001039 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001042 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001043 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1044 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001045 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001046 // Service Class is a bit mask per 3gpp 27.007.
1047 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001048 if (callForwardResults.length > 1
1049 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001050 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001051 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001052 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1053 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001054 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001055 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001056 }
1057 } else {
1058 if (ar.result == null) {
1059 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1060 }
1061 if (ar.exception != null) {
1062 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1063 }
1064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1068 callForwardingStatus =
1069 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1070 }
1071 }
1072 }
Hall Liu27d24262020-09-18 19:04:59 -07001073 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001074 break;
Hall Liu27d24262020-09-18 19:04:59 -07001075 }
Shuo Qian4a594052020-01-23 11:59:30 -08001076
Hall Liu27d24262020-09-18 19:04:59 -07001077 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001080 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1081 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001082 break;
Hall Liu27d24262020-09-18 19:04:59 -07001083 }
Shuo Qian4a594052020-01-23 11:59:30 -08001084
Hall Liu27d24262020-09-18 19:04:59 -07001085 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1089 Consumer<Integer> callback =
1090 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1091 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001092 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001093 if (ar.exception instanceof CommandException) {
1094 CommandException.Error error =
1095 ((CommandException) (ar.exception)).getCommandError();
1096 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1097 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1098 } else {
1099 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1100 }
1101 } else {
1102 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1103 }
1104 } else {
1105 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1106 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001107 }
Shuo Qian4a594052020-01-23 11:59:30 -08001108 break;
Hall Liu27d24262020-09-18 19:04:59 -07001109 }
Shuo Qian4a594052020-01-23 11:59:30 -08001110
Shishir Agrawal302c8692015-06-19 13:49:39 -07001111 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 CellNetworkScanResult cellScanResult;
1115 if (ar.exception == null && ar.result != null) {
1116 cellScanResult = new CellNetworkScanResult(
1117 CellNetworkScanResult.STATUS_SUCCESS,
1118 (List<OperatorInfo>) ar.result);
1119 } else {
1120 if (ar.result == null) {
1121 loge("getCellNetworkScanResults: Empty response");
1122 }
1123 if (ar.exception != null) {
1124 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1125 }
1126 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1131 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1132 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1133 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1134 }
1135 }
1136 cellScanResult = new CellNetworkScanResult(errorCode, null);
1137 }
1138 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001140 break;
1141
1142 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1143 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001144 ManualNetworkSelectionArgument selArg =
1145 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001146 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1147 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001148 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1149 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001150 break;
1151
1152 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 if (ar.exception == null) {
1156 request.result = true;
1157 } else {
1158 request.result = false;
1159 loge("setNetworkSelectionModeManual " + ar.exception);
1160 }
1161 notifyRequester(request);
1162 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001163 break;
1164
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001165 case CMD_GET_MODEM_ACTIVITY_INFO:
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001168 if (defaultPhone != null) {
1169 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001170 } else {
1171 ResultReceiver result = (ResultReceiver) request.argument;
1172 Bundle bundle = new Bundle();
1173 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001174 new ModemActivityInfo(0, 0, 0,
1175 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001176 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001177 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001178 break;
1179
Hall Liud0f208c2020-10-14 16:54:44 -07001180 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001183 ResultReceiver result = (ResultReceiver) request.argument;
1184
Hall Liud0f208c2020-10-14 16:54:44 -07001185 ModemActivityInfo ret = null;
1186 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001187 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001188 // Update the last modem activity info and the result of the request.
1189 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1190 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001191 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001192 int[] txTimeMs = info.getTransmitTimeMillis();
1193 int[] lastModemTxTimeMs = mLastModemActivityInfo
1194 .getTransmitTimeMillis();
1195 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1196 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1197 }
Hall Liu49656c02020-10-09 19:00:11 -07001198 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001199 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1200 + mLastModemActivityInfo.getSleepTimeMillis());
1201 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1202 + mLastModemActivityInfo.getIdleTimeMillis());
1203 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1204 mLastModemActivityInfo.setReceiveTimeMillis(
1205 info.getReceiveTimeMillis()
1206 + mLastModemActivityInfo.getReceiveTimeMillis());
1207 }
Hall Liu49656c02020-10-09 19:00:11 -07001208 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001209 mLastModemActivityInfo.getSleepTimeMillis(),
1210 mLastModemActivityInfo.getIdleTimeMillis(),
1211 mLastModemActivityInfo.getTransmitTimeMillis(),
1212 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 } else {
1214 if (ar.result == null) {
1215 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001216 error = TelephonyManager.ModemActivityInfoException
1217 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 } else if (ar.exception instanceof CommandException) {
1219 loge("queryModemActivityInfo: CommandException: " +
1220 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001221 error = TelephonyManager.ModemActivityInfoException
1222 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001223 } else {
1224 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001225 error = TelephonyManager.ModemActivityInfoException
1226 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 }
1228 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001230 if (ret != null) {
1231 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1232 } else {
1233 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1234 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001236 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001238 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239
Meng Wang1a7c35a2016-05-05 20:56:15 -07001240 case CMD_SET_ALLOWED_CARRIERS:
1241 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001242 CarrierRestrictionRules argument =
1243 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001244 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001245 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001246 break;
1247
1248 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 if (ar.exception == null && ar.result != null) {
1252 request.result = ar.result;
1253 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001254 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1255 if (ar.exception instanceof CommandException) {
1256 loge("setAllowedCarriers: CommandException: " + ar.exception);
1257 CommandException.Error error =
1258 ((CommandException) (ar.exception)).getCommandError();
1259 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1260 request.result =
1261 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 } else {
1264 loge("setAllowedCarriers: Unknown exception");
1265 }
1266 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001267 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001268 break;
1269
1270 case CMD_GET_ALLOWED_CARRIERS:
1271 request = (MainThreadRequest) msg.obj;
1272 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001273 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001274 break;
1275
1276 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null && ar.result != null) {
1280 request.result = ar.result;
1281 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001282 request.result = new IllegalStateException(
1283 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 if (ar.result == null) {
1285 loge("getAllowedCarriers: Empty response");
1286 } else if (ar.exception instanceof CommandException) {
1287 loge("getAllowedCarriers: CommandException: " +
1288 ar.exception);
1289 } else {
1290 loge("getAllowedCarriers: Unknown exception");
1291 }
1292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001293 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001294 break;
1295
Nathan Haroldb3014052017-01-25 15:57:32 -08001296 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
1299 if (ar.exception == null && ar.result != null) {
1300 request.result = ar.result;
1301 } else {
1302 request.result = new IllegalArgumentException(
1303 "Failed to retrieve Forbidden Plmns");
1304 if (ar.result == null) {
1305 loge("getForbiddenPlmns: Empty response");
1306 } else {
1307 loge("getForbiddenPlmns: Unknown exception");
1308 }
1309 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001311 break;
1312
1313 case CMD_GET_FORBIDDEN_PLMNS:
1314 request = (MainThreadRequest) msg.obj;
1315 uiccCard = getUiccCardFromRequest(request);
1316 if (uiccCard == null) {
1317 loge("getForbiddenPlmns() UiccCard is null");
1318 request.result = new IllegalArgumentException(
1319 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001320 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001321 break;
1322 }
1323 Integer appType = (Integer) request.argument;
1324 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1325 if (uiccApp == null) {
1326 loge("getForbiddenPlmns() no app with specified type -- "
1327 + appType);
1328 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001330 break;
1331 } else {
1332 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1333 + " specified type -- " + appType);
1334 }
1335 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1336 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1337 onCompleted);
1338 break;
1339
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001340 case CMD_SWITCH_SLOTS:
1341 request = (MainThreadRequest) msg.obj;
1342 int[] physicalSlots = (int[]) request.argument;
1343 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1344 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1345 break;
1346
1347 case EVENT_SWITCH_SLOTS_DONE:
1348 ar = (AsyncResult) msg.obj;
1349 request = (MainThreadRequest) ar.userObj;
1350 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001351 notifyRequester(request);
1352 break;
1353 case CMD_GET_NETWORK_SELECTION_MODE:
1354 request = (MainThreadRequest) msg.obj;
1355 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1356 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1357 break;
1358
1359 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1360 ar = (AsyncResult) msg.obj;
1361 request = (MainThreadRequest) ar.userObj;
1362 if (ar.exception != null) {
1363 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1364 } else {
1365 int mode = ((int[]) ar.result)[0];
1366 if (mode == 0) {
1367 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1368 } else {
1369 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1370 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
1373 break;
1374 case CMD_GET_CDMA_ROAMING_MODE:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1377 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1378 break;
1379 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 if (ar.exception != null) {
1383 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1384 } else {
1385 request.result = ((int[]) ar.result)[0];
1386 }
1387 notifyRequester(request);
1388 break;
1389 case CMD_SET_CDMA_ROAMING_MODE:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1392 int mode = (int) request.argument;
1393 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1394 break;
1395 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 request.result = ar.exception == null;
1399 notifyRequester(request);
1400 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001401 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1402 request = (MainThreadRequest) msg.obj;
1403 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1404 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1405 break;
1406 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 if (ar.exception != null) {
1410 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1411 } else {
1412 request.result = ((int[]) ar.result)[0];
1413 }
1414 notifyRequester(request);
1415 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1417 request = (MainThreadRequest) msg.obj;
1418 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1419 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001420 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1421 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001422 break;
1423 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 request.result = ar.exception == null;
1427 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001428 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001429 case CMD_GET_ALL_CELL_INFO:
1430 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001431 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001432 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001433 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001434 case EVENT_GET_ALL_CELL_INFO_DONE:
1435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001437 // If a timeout occurs, the response will be null
1438 request.result = (ar.exception == null && ar.result != null)
1439 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001440 synchronized (request) {
1441 request.notifyAll();
1442 }
1443 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001444 case CMD_REQUEST_CELL_INFO_UPDATE:
1445 request = (MainThreadRequest) msg.obj;
1446 request.phone.requestCellInfoUpdate(request.workSource,
1447 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1448 break;
1449 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1453 try {
1454 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001455 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001456 cb.onError(
1457 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1458 ar.exception.getClass().getName(),
1459 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001460 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001462 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001463 } else {
1464 // use the result as returned
1465 cb.onCellInfo((List<CellInfo>) ar.result);
1466 }
1467 } catch (RemoteException re) {
1468 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1469 }
1470 break;
1471 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 request = (MainThreadRequest) msg.obj;
1473 WorkSource ws = (WorkSource) request.argument;
1474 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001475 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = ar.result;
1482 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001485 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 }
1487
1488 synchronized (request) {
1489 request.notifyAll();
1490 }
1491 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001492 case CMD_MODEM_REBOOT:
1493 request = (MainThreadRequest) msg.obj;
1494 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001495 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001496 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001497 case EVENT_CMD_MODEM_REBOOT_DONE:
1498 handleNullReturnEvent(msg, "rebootModem");
1499 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001500 case CMD_REQUEST_ENABLE_MODEM:
1501 request = (MainThreadRequest) msg.obj;
1502 boolean enable = (boolean) request.argument;
1503 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001504 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001505 PhoneConfigurationManager.getInstance()
1506 .enablePhone(request.phone, enable, onCompleted);
1507 break;
1508 case EVENT_ENABLE_MODEM_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001512 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001513 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001514 if ((boolean) request.result) {
1515 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1516 updateModemStateMetrics();
1517 } else {
1518 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1519 + ar.exception);
1520 }
1521 notifyRequester(request);
1522 break;
1523 case CMD_GET_MODEM_STATUS:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1526 PhoneConfigurationManager.getInstance()
1527 .getPhoneStatusFromModem(request.phone, onCompleted);
1528 break;
1529 case EVENT_GET_MODEM_STATUS_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 int id = request.phone.getPhoneId();
1533 if (ar.exception == null && ar.result != null) {
1534 request.result = ar.result;
1535 //update the cache as modem status has changed
1536 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1537 (boolean) request.result);
1538 } else {
1539 // Return true if modem status cannot be retrieved. For most cases,
1540 // modem status is on. And for older version modems, GET_MODEM_STATUS
1541 // and disable modem are not supported. Modem is always on.
1542 // TODO: this should be fixed in R to support a third
1543 // status UNKNOWN b/131631629
1544 request.result = true;
1545 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1546 + ar.exception);
1547 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001548 notifyRequester(request);
1549 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001550 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1553 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1554 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1555 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1556 break;
1557 }
1558 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1562 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1563 args.second.accept(ar.exception == null);
1564 notifyRequester(request);
1565 break;
1566 }
yincheng zhao2737e882019-09-06 17:06:54 -07001567 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 if (ar.exception == null && ar.result != null) {
1571 request.result = ar.result;
1572 } else {
1573 request.result = -1;
1574 loge("Failed to set Forbidden Plmns");
1575 if (ar.result == null) {
1576 loge("setForbidenPlmns: Empty response");
1577 } else if (ar.exception != null) {
1578 loge("setForbiddenPlmns: Exception: " + ar.exception);
1579 request.result = -1;
1580 } else {
1581 loge("setForbiddenPlmns: Unknown exception");
1582 }
1583 }
1584 notifyRequester(request);
1585 break;
1586 case CMD_SET_FORBIDDEN_PLMNS:
1587 request = (MainThreadRequest) msg.obj;
1588 uiccCard = getUiccCardFromRequest(request);
1589 if (uiccCard == null) {
1590 loge("setForbiddenPlmns: UiccCard is null");
1591 request.result = -1;
1592 notifyRequester(request);
1593 break;
1594 }
1595 Pair<Integer, List<String>> setFplmnsArgs =
1596 (Pair<Integer, List<String>>) request.argument;
1597 appType = setFplmnsArgs.first;
1598 List<String> fplmns = setFplmnsArgs.second;
1599 uiccApp = uiccCard.getApplicationByType(appType);
1600 if (uiccApp == null) {
1601 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1602 request.result = -1;
1603 loge("Failed to get UICC App");
1604 notifyRequester(request);
1605 } else {
1606 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1607 ((SIMRecords) uiccApp.getIccRecords())
1608 .setForbiddenPlmns(onCompleted, fplmns);
1609 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001610 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001611 case CMD_ERASE_MODEM_CONFIG:
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1614 defaultPhone.eraseModemConfig(onCompleted);
1615 break;
1616 case EVENT_ERASE_MODEM_CONFIG_DONE:
1617 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001618 break;
zoey chene02881a2019-12-30 16:11:23 +08001619
1620 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1623 Pair<String, String> changed = (Pair<String, String>) request.argument;
1624 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1625 changed.first, changed.second, onCompleted);
1626 break;
1627 case EVENT_CHANGE_ICC_LOCK_PASSWORD_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
1638 case CMD_SET_ICC_LOCK_ENABLED:
1639 request = (MainThreadRequest) msg.obj;
1640 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1641 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1642 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1643 enabled.first, enabled.second, onCompleted);
1644 break;
1645 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 if (ar.exception == null) {
1649 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1650 } else {
1651 request.result = msg.arg1;
1652 }
1653 notifyRequester(request);
1654 break;
1655
Peter Wangdafb9ac2020-01-15 14:13:38 -08001656 case MSG_NOTIFY_USER_ACTIVITY:
1657 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001658 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001659 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1660 getDefaultPhone().getContext().sendBroadcastAsUser(
1661 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1662 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 default:
1664 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1665 break;
1666 }
1667 }
Jake Hambye994d462014-02-03 13:10:13 -08001668
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 private void notifyRequester(MainThreadRequest request) {
1670 synchronized (request) {
1671 request.notifyAll();
1672 }
1673 }
1674
Jake Hambye994d462014-02-03 13:10:13 -08001675 private void handleNullReturnEvent(Message msg, String command) {
1676 AsyncResult ar = (AsyncResult) msg.obj;
1677 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1678 if (ar.exception == null) {
1679 request.result = true;
1680 } else {
1681 request.result = false;
1682 if (ar.exception instanceof CommandException) {
1683 loge(command + ": CommandException: " + ar.exception);
1684 } else {
1685 loge(command + ": Unknown exception");
1686 }
1687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001688 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
1692 /**
1693 * Posts the specified command to be executed on the main thread,
1694 * waits for the request to complete, and returns the result.
1695 * @see #sendRequestAsync
1696 */
1697 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001698 return sendRequest(
1699 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001700 }
1701
1702 /**
1703 * Posts the specified command to be executed on the main thread,
1704 * waits for the request to complete, and returns the result.
1705 * @see #sendRequestAsync
1706 */
1707 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1708 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001709 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
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 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001717 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001718 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001719 }
1720
1721 /**
1722 * Posts the specified command to be executed on the main thread,
1723 * waits for the request to complete, and returns the result.
1724 * @see #sendRequestAsync
1725 */
Nathan Harold92bed182018-10-12 18:16:49 -07001726 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1727 return sendRequest(command, argument, subId, null, workSource);
1728 }
1729
1730 /**
1731 * Posts the specified command to be executed on the main thread,
1732 * waits for the request to complete, and returns the result.
1733 * @see #sendRequestAsync
1734 */
1735 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1736 return sendRequest(
1737 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1738 }
1739
1740 /**
1741 * Posts the specified command to be executed on the main thread,
1742 * waits for the request to complete, and returns the result.
1743 * @see #sendRequestAsync
1744 */
1745 private Object sendRequest(
1746 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1748 throw new RuntimeException("This method will deadlock if called from the main thread.");
1749 }
1750
Nathan Harold92bed182018-10-12 18:16:49 -07001751 MainThreadRequest request = null;
1752 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1753 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1754 } else if (phone != null) {
1755 request = new MainThreadRequest(argument, phone, workSource);
1756 } else {
1757 request = new MainThreadRequest(argument, subId, workSource);
1758 }
1759
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 Message msg = mMainThreadHandler.obtainMessage(command, request);
1761 msg.sendToTarget();
1762
1763 // Wait for the request to complete
1764 synchronized (request) {
1765 while (request.result == null) {
1766 try {
1767 request.wait();
1768 } catch (InterruptedException e) {
1769 // Do nothing, go back and wait until the request is complete
1770 }
1771 }
1772 }
1773 return request.result;
1774 }
1775
1776 /**
1777 * Asynchronous ("fire and forget") version of sendRequest():
1778 * Posts the specified command to be executed on the main thread, and
1779 * returns immediately.
1780 * @see #sendRequest
1781 */
1782 private void sendRequestAsync(int command) {
1783 mMainThreadHandler.sendEmptyMessage(command);
1784 }
1785
1786 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001787 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001789 */
1790 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001791 sendRequestAsync(command, argument, null, null);
1792 }
1793
1794 /**
1795 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1796 * @see {@link #sendRequest(int,Object)}
1797 */
1798 private void sendRequestAsync(
1799 int command, Object argument, Phone phone, WorkSource workSource) {
1800 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001801 Message msg = mMainThreadHandler.obtainMessage(command, request);
1802 msg.sendToTarget();
1803 }
1804
1805 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 * Initialize the singleton PhoneInterfaceManager instance.
1807 * This is only done once, at startup, from PhoneApp.onCreate().
1808 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001809 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 synchronized (PhoneInterfaceManager.class) {
1811 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001812 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 } else {
1814 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1815 }
1816 return sInstance;
1817 }
1818 }
1819
1820 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001821 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001824 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001825 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1827 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001828 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001829 mTelephonySharedPreferences =
1830 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001831 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001832 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001833 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001834
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 publish();
1836 }
1837
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001838 private Phone getDefaultPhone() {
1839 Phone thePhone = getPhone(getDefaultSubscription());
1840 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1841 }
1842
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 private void publish() {
1844 if (DBG) log("publish: " + this);
1845
Peter Wangc035ce42020-01-08 21:00:22 -08001846 TelephonyFrameworkInitializer
1847 .getTelephonyServiceManager()
1848 .getTelephonyServiceRegisterer()
1849 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Stuart Scott584921c2015-01-15 17:10:34 -08001852 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001853 if (request.phone != null) {
1854 return request.phone;
1855 } else {
1856 return getPhoneFromSubId(request.subId);
1857 }
1858 }
1859
1860 private Phone getPhoneFromSubId(int subId) {
1861 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1862 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001863 }
1864
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001865 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1866 Phone phone = getPhoneFromRequest(request);
1867 return phone == null ? null :
1868 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1869 }
1870
Wink Saville36469e72014-06-11 15:17:00 -07001871 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001872 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001873 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875
Naina Nallurid63128d2019-09-17 14:10:30 -07001876 private void sendEraseModemConfig(Phone phone) {
1877 if (phone != null) {
1878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1879 mApp, phone.getSubId(), "eraseModemConfig");
1880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1883 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
1886 }
1887 }
1888 }
1889
Peter Wang44b186e2020-01-13 23:33:09 -08001890 private boolean isImsAvailableOnDevice() {
1891 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1892 if (pm == null) {
1893 // For some reason package manger is not available.. This will fail internally anyway,
1894 // so do not throw error and allow.
1895 return true;
1896 }
1897 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1898 }
1899
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001901 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001902 }
1903
Wink Savilleb564aae2014-10-23 10:18:09 -07001904 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 if (DBG) log("dial: " + number);
1906 // No permission check needed here: This is just a wrapper around the
1907 // ACTION_DIAL intent, which is available to any app since it puts up
1908 // the UI before it does anything.
1909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910 final long identity = Binder.clearCallingIdentity();
1911 try {
1912 String url = createTelUrl(number);
1913 if (url == null) {
1914 return;
1915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 // PENDING: should we just silently fail if phone is offhook or ringing?
1918 PhoneConstants.State state = mCM.getState(subId);
1919 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1920 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1921 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1922 mApp.startActivity(intent);
1923 }
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927 }
1928
1929 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001930 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001931 }
1932
Wink Savilleb564aae2014-10-23 10:18:09 -07001933 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 if (DBG) log("call: " + number);
1935
1936 // This is just a wrapper around the ACTION_CALL intent, but we still
1937 // need to do a permission check since we're calling startActivity()
1938 // from the context of the phone app.
1939 enforceCallPermission();
1940
Jordan Liu1617b712019-07-10 15:06:26 -07001941 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 != AppOpsManager.MODE_ALLOWED) {
1943 return;
1944 }
1945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 String url = createTelUrl(number);
1949 if (url == null) {
1950 return;
1951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 boolean isValid = false;
1954 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1955 if (slist != null) {
1956 for (SubscriptionInfo subInfoRecord : slist) {
1957 if (subInfoRecord.getSubscriptionId() == subId) {
1958 isValid = true;
1959 break;
1960 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001961 }
Wink Saville08874612014-08-31 19:19:58 -07001962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001963 if (!isValid) {
1964 return;
1965 }
Wink Saville08874612014-08-31 19:19:58 -07001966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1968 intent.putExtra(SUBSCRIPTION_KEY, subId);
1969 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1970 mApp.startActivity(intent);
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
1973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Wink Savilleb564aae2014-10-23 10:18:09 -07001976 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001977 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001978 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1979 }
1980
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001982 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001983 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1984 }
1985
Wink Savilleb564aae2014-10-23 10:18:09 -07001986 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988
1989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1992 checkSimPin.start();
1993 return checkSimPin.unlockSim(null, pin);
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
Wink Savilleb564aae2014-10-23 10:18:09 -07001999 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2005 checkSimPuk.start();
2006 return checkSimPuk.unlockSim(puk, pin);
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
2009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002013 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 * a synchronous one.
2015 */
2016 private static class UnlockSim extends Thread {
2017
2018 private final IccCard mSimCard;
2019
2020 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002021 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2022 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023
2024 // For replies from SimCard interface
2025 private Handler mHandler;
2026
2027 // For async handler to identify request type
2028 private static final int SUPPLY_PIN_COMPLETE = 100;
2029
2030 public UnlockSim(IccCard simCard) {
2031 mSimCard = simCard;
2032 }
2033
2034 @Override
2035 public void run() {
2036 Looper.prepare();
2037 synchronized (UnlockSim.this) {
2038 mHandler = new Handler() {
2039 @Override
2040 public void handleMessage(Message msg) {
2041 AsyncResult ar = (AsyncResult) msg.obj;
2042 switch (msg.what) {
2043 case SUPPLY_PIN_COMPLETE:
2044 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2045 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002046 mRetryCount = msg.arg1;
2047 if (ar.exception != null) {
2048 if (ar.exception instanceof CommandException &&
2049 ((CommandException)(ar.exception)).getCommandError()
2050 == CommandException.Error.PASSWORD_INCORRECT) {
2051 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002052 } //When UiccCardApp dispose,handle message and return exception
2053 else if (ar.exception instanceof CommandException &&
2054 ((CommandException) (ar.exception)).getCommandError()
2055 == CommandException.Error.ABORTED) {
2056 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002057 } else {
2058 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2059 }
2060 } else {
2061 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 mDone = true;
2064 UnlockSim.this.notifyAll();
2065 }
2066 break;
2067 }
2068 }
2069 };
2070 UnlockSim.this.notifyAll();
2071 }
2072 Looper.loop();
2073 }
2074
2075 /*
2076 * Use PIN or PUK to unlock SIM card
2077 *
2078 * If PUK is null, unlock SIM card with PIN
2079 *
2080 * If PUK is not null, unlock SIM card with PUK and set PIN code
2081 */
Wink Saville9de0f752013-10-22 19:04:03 -07002082 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083
2084 while (mHandler == null) {
2085 try {
2086 wait();
2087 } catch (InterruptedException e) {
2088 Thread.currentThread().interrupt();
2089 }
2090 }
2091 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2092
2093 if (puk == null) {
2094 mSimCard.supplyPin(pin, callback);
2095 } else {
2096 mSimCard.supplyPuk(puk, pin, callback);
2097 }
2098
2099 while (!mDone) {
2100 try {
2101 Log.d(LOG_TAG, "wait for done");
2102 wait();
2103 } catch (InterruptedException e) {
2104 // Restore the interrupted status
2105 Thread.currentThread().interrupt();
2106 }
2107 }
2108 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002109 int[] resultArray = new int[2];
2110 resultArray[0] = mResult;
2111 resultArray[1] = mRetryCount;
2112 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114 }
2115
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002116 /**
2117 * This method has been removed due to privacy and stability concerns.
2118 */
2119 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002121 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2122 return;
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Nathan Harold1f889d82020-06-04 17:05:26 -07002125 @Override
2126 public void updateServiceLocationWithPackageName(String callingPackage) {
2127 mApp.getSystemService(AppOpsManager.class)
2128 .checkPackage(Binder.getCallingUid(), callingPackage);
2129
2130 final int targetSdk = getTargetSdk(callingPackage);
2131 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2132 // Callers targeting S have no business invoking this method.
2133 return;
2134 }
2135
2136 LocationAccessPolicy.LocationPermissionResult locationResult =
2137 LocationAccessPolicy.checkLocationPermission(mApp,
2138 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2139 .setCallingPackage(callingPackage)
2140 .setCallingFeatureId(null)
2141 .setCallingPid(Binder.getCallingPid())
2142 .setCallingUid(Binder.getCallingUid())
2143 .setMethod("updateServiceLocation")
2144 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2145 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2146 .build());
2147 // Apps that lack location permission have no business calling this method;
2148 // however, because no permission was declared in the public API, denials must
2149 // all be "soft".
2150 switch (locationResult) {
2151 case DENIED_HARD: /* fall through */
2152 case DENIED_SOFT:
2153 return;
2154 }
2155
2156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002157 final long identity = Binder.clearCallingIdentity();
2158 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002159 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002161 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002168 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 @Override
2170 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002171 return isRadioOnWithFeature(callingPackage, null);
2172 }
2173
2174
2175 @Override
2176 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2177 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2178 callingFeatureId);
2179 }
2180
2181 @Deprecated
2182 @Override
2183 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2184 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002188 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2189 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002191 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 return false;
2193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 return isRadioOnForSubscriber(subId);
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002201 }
2202
2203 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 final Phone phone = getPhone(subId);
2207 if (phone != null) {
2208 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2209 } else {
2210 return false;
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
2217 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002218 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
Wink Saville36469e72014-06-11 15:17:00 -07002220
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2229 }
2230 } finally {
2231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 }
Wink Saville36469e72014-06-11 15:17:00 -07002233 }
2234
2235 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002236 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
Wink Savilleb564aae2014-10-23 10:18:09 -07002239 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = getPhone(subId);
2245 if (phone == null) {
2246 return false;
2247 }
2248 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2249 toggleRadioOnOffForSubscriber(subId);
2250 }
2251 return true;
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
Wink Saville36469e72014-06-11 15:17:00 -07002256
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002257 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002258 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002259 /*
2260 * If any of the Radios are available, it will need to be
2261 * shutdown. So return true if any Radio is available.
2262 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2266 Phone phone = PhoneFactory.getPhone(i);
2267 if (phone != null && phone.isRadioAvailable()) return true;
2268 }
2269 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2270 return false;
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002273 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002274 }
2275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002277 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 enforceModifyPermission();
2279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2283 logv("Shutting down Phone " + i);
2284 shutdownRadioUsingPhoneId(i);
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002288 }
2289 }
2290
2291 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002292 Phone phone = PhoneFactory.getPhone(phoneId);
2293 if (phone != null && phone.isRadioAvailable()) {
2294 phone.shutdownRadio();
2295 }
2296 }
2297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2304 if (defaultPhone != null) {
2305 defaultPhone.setRadioPower(turnOn);
2306 return true;
2307 } else {
2308 loge("There's no default phone.");
2309 return false;
2310 }
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002313 }
Wink Saville36469e72014-06-11 15:17:00 -07002314 }
2315
Wink Savilleb564aae2014-10-23 10:18:09 -07002316 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318
2319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 final Phone phone = getPhone(subId);
2322 if (phone != null) {
2323 phone.setRadioPower(turnOn);
2324 return true;
2325 } else {
2326 return false;
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
Wink Saville36469e72014-06-11 15:17:00 -07002333 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 public boolean enableDataConnectivity() {
2336 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 int subId = mSubscriptionController.getDefaultDataSubId();
2341 final Phone phone = getPhone(subId);
2342 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002343 phone.getDataEnabledSettings().setDataEnabled(
2344 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 return true;
2346 } else {
2347 return false;
2348 }
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
Wink Saville36469e72014-06-11 15:17:00 -07002354 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002355 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 public boolean disableDataConnectivity() {
2357 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 int subId = mSubscriptionController.getDefaultDataSubId();
2362 final Phone phone = getPhone(subId);
2363 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002364 phone.getDataEnabledSettings().setDataEnabled(
2365 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 return true;
2367 } else {
2368 return false;
2369 }
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
Sanket Padawe356d7632015-06-22 14:03:32 -07002375 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002376 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002381 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 } else {
2383 return false;
2384 }
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
2389
2390 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002391 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
pkanwarae03a6b2016-11-06 20:37:09 -08002394 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 enforceCallPermission();
2396
2397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2400 return;
2401 }
2402 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2403 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
pkanwar32d516d2016-10-14 19:37:38 -07002407 };
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002411
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2415 return false;
2416 }
2417 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002424 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002425 }
2426
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002427 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 Phone phone = PhoneFactory.getPhone(slotIndex);
2431 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2432 PhoneConstantConversions.convertCallState(phone.getState());
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
2435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002439 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002440 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2441 }
2442
2443 @Override
2444 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 if (phone != null) {
2449 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2450 } else {
2451 return PhoneConstantConversions.convertDataState(
2452 PhoneConstants.DataState.DISCONNECTED);
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002460 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002461 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2462 }
2463
2464 @Override
2465 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 final long identity = Binder.clearCallingIdentity();
2467 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 if (phone != null) {
2470 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2471 } else {
2472 return TelephonyManager.DATA_ACTIVITY_NONE;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
2479 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002480 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002482 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002483
2484 LocationAccessPolicy.LocationPermissionResult locationResult =
2485 LocationAccessPolicy.checkLocationPermission(mApp,
2486 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2487 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002488 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002489 .setCallingPid(Binder.getCallingPid())
2490 .setCallingUid(Binder.getCallingUid())
2491 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002492 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002493 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2494 .build());
2495 switch (locationResult) {
2496 case DENIED_HARD:
2497 throw new SecurityException("Not allowed to access cell location");
2498 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002499 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2500 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002507 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002508 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Svetoslav64fad262015-04-14 14:35:21 -07002512 }
2513
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002515 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002516 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2517 // registered cell info, so return a NULL country instead.
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002520 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2521 // Get default phone in this case.
2522 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2523 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002524 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002526 if (phone == null) return "";
2527 ServiceStateTracker sst = phone.getServiceStateTracker();
2528 if (sst == null) return "";
2529 LocaleTracker lt = sst.getLocaleTracker();
2530 if (lt == null) return "";
2531 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2532 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2533 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002537 }
2538
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002539 /**
2540 * This method was removed due to potential issues caused by performing partial
2541 * updates of service state, and lack of a credible use case.
2542 *
2543 * This has the ability to break the telephony implementation by disabling notification of
2544 * changes in device connectivity. DO NOT USE THIS!
2545 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002546 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 public void enableLocationUpdates() {
2548 mApp.enforceCallingOrSelfPermission(
2549 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002552 /**
2553 * This method was removed due to potential issues caused by performing partial
2554 * updates of service state, and lack of a credible use case.
2555 *
2556 * This has the ability to break the telephony implementation by disabling notification of
2557 * changes in device connectivity. DO NOT USE THIS!
2558 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 @Override
2560 public void disableLocationUpdates() {
2561 mApp.enforceCallingOrSelfPermission(
2562 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
2564
Nathan Harold31d7ff32018-10-15 20:20:30 -07002565 /**
2566 * Returns the target SDK version number for a given package name.
2567 *
Nathan Haroldec184742019-07-10 17:04:16 -07002568 * This call MUST be invoked before clearing the calling UID.
2569 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002570 * @return target SDK if the package is found or INT_MAX.
2571 */
2572 private int getTargetSdk(String packageName) {
2573 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002574 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002575 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002576 if (ai != null) return ai.targetSdkVersion;
2577 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002578 loge("Failed to get package info for pkg="
2579 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002580 }
2581 return Integer.MAX_VALUE;
2582 }
2583
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 @Override
2585 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002586 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2587 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002588 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002589 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2590 throw new SecurityException(
2591 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2592 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002593
Jordan Liu1617b712019-07-10 15:06:26 -07002594 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2596 return null;
2597 }
Svetoslav64fad262015-04-14 14:35:21 -07002598
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002599 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002601 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002602 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603
Nathan Haroldf180aac2018-06-01 18:43:55 -07002604 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2605 for (CellInfo ci : info) {
2606 if (ci instanceof CellInfoGsm) {
2607 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2608 } else if (ci instanceof CellInfoWcdma) {
2609 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002612 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002615 private List<CellInfo> getCachedCellInfo() {
2616 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2617 for (Phone phone : PhoneFactory.getPhones()) {
2618 List<CellInfo> info = phone.getAllCellInfo();
2619 if (info != null) cellInfos.addAll(info);
2620 }
2621 return cellInfos;
2622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623
2624 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002625 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002627 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002628
2629 LocationAccessPolicy.LocationPermissionResult locationResult =
2630 LocationAccessPolicy.checkLocationPermission(mApp,
2631 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2632 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002633 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002634 .setCallingPid(Binder.getCallingPid())
2635 .setCallingUid(Binder.getCallingUid())
2636 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002637 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002638 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2639 .build());
2640 switch (locationResult) {
2641 case DENIED_HARD:
2642 throw new SecurityException("Not allowed to access cell info");
2643 case DENIED_SOFT:
2644 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 }
2646
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002647 final int targetSdk = getTargetSdk(callingPackage);
2648 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2649 return getCachedCellInfo();
2650 }
2651
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002652 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2657 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002658 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002659 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 if (info != null) cellInfos.addAll(info);
2661 }
2662 return cellInfos;
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666 }
2667
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002668 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002669 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2670 String callingFeatureId) {
2671 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2672 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002673 }
2674
2675 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002676 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2677 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002678 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002679 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002680 }
2681
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002682 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2683 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002684 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002685 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002686
2687 LocationAccessPolicy.LocationPermissionResult locationResult =
2688 LocationAccessPolicy.checkLocationPermission(mApp,
2689 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2690 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002691 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002692 .setCallingPid(Binder.getCallingPid())
2693 .setCallingUid(Binder.getCallingUid())
2694 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002695 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2696 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002697 .build());
2698 switch (locationResult) {
2699 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002700 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2701 // Safetynet logging for b/154934934
2702 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2703 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002704 throw new SecurityException("Not allowed to access cell info");
2705 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002706 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2707 // Safetynet logging for b/154934934
2708 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2709 }
Nathan Harold5320c422019-05-09 10:26:08 -07002710 try {
2711 cb.onCellInfo(new ArrayList<CellInfo>());
2712 } catch (RemoteException re) {
2713 // Drop without consequences
2714 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002715 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002716 }
2717
Nathan Harolda939a962019-05-09 10:13:47 -07002718
2719 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002720 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2721
2722 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2723 }
2724
2725 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002727 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002732 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 } finally {
2734 Binder.restoreCallingIdentity(identity);
2735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
2737
Shishir Agrawala9f32182016-04-12 12:00:16 -07002738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002739 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002740 Phone phone = PhoneFactory.getPhone(slotIndex);
2741 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002742 return null;
2743 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002744 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002745 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002746 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002747 return null;
2748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 return phone.getImei();
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002756 }
2757
2758 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002759 public String getTypeAllocationCodeForSlot(int slotIndex) {
2760 Phone phone = PhoneFactory.getPhone(slotIndex);
2761 String tac = null;
2762 if (phone != null) {
2763 String imei = phone.getImei();
2764 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2765 }
2766 return tac;
2767 }
2768
2769 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002771 Phone phone = PhoneFactory.getPhone(slotIndex);
2772 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002773 return null;
2774 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002775
Jeff Davidson913390f2018-02-23 17:11:49 -08002776 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002777 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002778 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002779 return null;
2780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return phone.getMeid();
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Jack Yu2af8d712017-03-15 17:14:14 -07002788 }
2789
2790 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002791 public String getManufacturerCodeForSlot(int slotIndex) {
2792 Phone phone = PhoneFactory.getPhone(slotIndex);
2793 String manufacturerCode = null;
2794 if (phone != null) {
2795 String meid = phone.getMeid();
2796 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2797 }
2798 return manufacturerCode;
2799 }
2800
2801 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002802 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2803 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002804 Phone phone = PhoneFactory.getPhone(slotIndex);
2805 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002806 return null;
2807 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002808 int subId = phone.getSubId();
2809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002810 mApp, subId, callingPackage, callingFeatureId,
2811 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002812 return null;
2813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 return phone.getDeviceSvn();
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002821 }
2822
fionaxu43304da2017-11-27 22:51:16 -08002823 @Override
2824 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone phone = getPhone(subId);
2828 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
fionaxu43304da2017-11-27 22:51:16 -08002832 }
2833
2834 @Override
2835 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 return phone == null ? null : phone.getCarrierName();
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
2842 }
fionaxu43304da2017-11-27 22:51:16 -08002843 }
2844
calvinpanffe225e2018-11-01 19:43:06 +08002845 @Override
chen xu0026ca62019-03-06 15:28:50 -08002846 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = getPhone(subId);
2850 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002851 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
2855 }
2856
2857 @Override
chen xu0026ca62019-03-06 15:28:50 -08002858 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002862 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
2866 }
2867
chen xu651eec72018-11-11 19:03:44 -08002868 @Override
chen xu864e11c2018-12-06 22:10:03 -08002869 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2870 if (!isSubscriptionMccMnc) {
2871 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2872 }
chen xu651eec72018-11-11 19:03:44 -08002873 final Phone phone = PhoneFactory.getPhone(slotIndex);
2874 if (phone == null) {
2875 return TelephonyManager.UNKNOWN_CARRIER_ID;
2876 }
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 //
2886 // Internal helper methods.
2887 //
2888
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002889 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2891 *
2892 * @throws SecurityException if the caller does not have the required permission
2893 */
2894 private void enforceModifyPermission() {
2895 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2896 }
2897
Shuo Qiancd19c462020-01-16 20:51:11 -08002898 /**
2899 * Make sure the caller is system.
2900 *
2901 * @throws SecurityException if the caller is not system.
2902 */
2903 private void enforceSystemCaller() {
2904 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2905 throw new SecurityException("Caller must be system");
2906 }
2907 }
2908
Shuo Qian3b6ee772019-11-13 17:43:31 -08002909 private void enforceActiveEmergencySessionPermission() {
2910 mApp.enforceCallingOrSelfPermission(
2911 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2912 }
2913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 /**
2915 * Make sure the caller has the CALL_PHONE permission.
2916 *
2917 * @throws SecurityException if the caller does not have the required permission
2918 */
2919 private void enforceCallPermission() {
2920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2921 }
2922
paulhu5a773602019-08-23 19:17:33 +08002923 private void enforceSettingsPermission() {
2924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002925 }
2926
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 private String createTelUrl(String number) {
2928 if (TextUtils.isEmpty(number)) {
2929 return null;
2930 }
2931
Jake Hambye994d462014-02-03 13:10:13 -08002932 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Ihab Awadf9e92732013-12-05 18:02:52 -08002935 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2937 }
2938
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002939 private static void logv(String msg) {
2940 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2941 }
2942
Ihab Awadf9e92732013-12-05 18:02:52 -08002943 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2945 }
2946
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002947 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002949 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002950 }
2951
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002953 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = PhoneFactory.getPhone(slotIndex);
2957 if (phone == null) {
2958 return PhoneConstants.PHONE_TYPE_NONE;
2959 } else {
2960 return phone.getPhoneType();
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 }
2966
2967 /**
2968 * Returns the CDMA ERI icon index to display
2969 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2972 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2973 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002974 }
2975
Sanket Padawe356d7632015-06-22 14:03:32 -07002976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002977 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2978 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002980 mApp, subId, callingPackage, callingFeatureId,
2981 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002982 return -1;
2983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 final Phone phone = getPhone(subId);
2988 if (phone != null) {
2989 return phone.getCdmaEriIconIndex();
2990 } else {
2991 return -1;
2992 }
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 }
2997
2998 /**
2999 * Returns the CDMA ERI icon mode,
3000 * 0 - ON
3001 * 1 - FLASHING
3002 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003004 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3005 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3006 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003007 }
3008
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003010 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3011 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003013 mApp, subId, callingPackage, callingFeatureId,
3014 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003015 return -1;
3016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 final Phone phone = getPhone(subId);
3021 if (phone != null) {
3022 return phone.getCdmaEriIconMode();
3023 } else {
3024 return -1;
3025 }
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030
3031 /**
3032 * Returns the CDMA ERI text,
3033 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003035 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3036 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3037 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003038 }
3039
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003041 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3042 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003044 mApp, subId, callingPackage, callingFeatureId,
3045 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003046 return null;
3047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 final Phone phone = getPhone(subId);
3052 if (phone != null) {
3053 return phone.getCdmaEriText();
3054 } else {
3055 return null;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
3062 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003063 * Returns the CDMA MDN.
3064 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003065 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003066 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3068 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 return phone.getLine1Number();
3075 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 return null;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003081 }
3082 }
3083
3084 /**
3085 * Returns the CDMA MIN.
3086 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003087 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003088 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3090 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 final Phone phone = getPhone(subId);
3095 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3096 return phone.getCdmaMin();
3097 } else {
3098 return null;
3099 }
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003102 }
3103 }
3104
Hall Liud892bec2018-11-30 14:51:45 -08003105 @Override
3106 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3107 INumberVerificationCallback callback, String callingPackage) {
3108 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3109 != PERMISSION_GRANTED) {
3110 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3111 }
3112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3113
3114 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3115 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3116 throw new SecurityException("Calling package must be configured in the device config");
3117 }
3118
3119 if (range == null) {
3120 throw new NullPointerException("Range must be non-null");
3121 }
3122
3123 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003124 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003125
3126 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3127 }
3128
Junda Liuca05d5d2014-08-14 22:36:34 -07003129 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 * Returns true if CDMA provisioning needs to run.
3131 */
3132 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 }
3140
3141 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003142 * Sets the voice mail number of a given subId.
3143 */
3144 @Override
3145 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003146 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3147 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3152 new Pair<String, String>(alphaTag, number), new Integer(subId));
3153 return success;
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003157 }
3158
Ta-wei Yen87c49842016-05-13 21:19:52 -07003159 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003160 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3161 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003162 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3163 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003164 if (!TextUtils.equals(callingPackage, systemDialer)) {
3165 throw new SecurityException("caller must be system dialer");
3166 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3171 if (phoneAccountHandle == null) {
3172 return null;
3173 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003177 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003178 }
3179
3180 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003181 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3182 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003185 mApp, subId, callingPackage, callingFeatureId,
3186 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003187 return null;
3188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003196 }
3197
3198 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003199 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3200 VisualVoicemailSmsFilterSettings settings) {
3201 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003210 }
3211
3212 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003213 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3214 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003223 }
3224
3225 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003226 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3227 String callingPackage, int subId) {
3228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003237 }
3238
3239 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003240 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003246 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003250 }
3251
3252 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003253 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3254 String callingAttributionTag, int subId, String number, int port, String text,
3255 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003257 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003258 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003259 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003260 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3261 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003262 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003263
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003264 /**
fionaxu0152e512016-11-14 13:36:14 -08003265 * Sets the voice activation state of a given subId.
3266 */
3267 @Override
3268 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3270 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 final Phone phone = getPhone(subId);
3275 if (phone != null) {
3276 phone.setVoiceActivationState(activationState);
3277 } else {
3278 loge("setVoiceActivationState fails with invalid subId: " + subId);
3279 }
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003282 }
3283 }
3284
3285 /**
3286 * Sets the data activation state of a given subId.
3287 */
3288 @Override
3289 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 final Phone phone = getPhone(subId);
3296 if (phone != null) {
3297 phone.setDataActivationState(activationState);
3298 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003299 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300 }
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003303 }
3304 }
3305
3306 /**
3307 * Returns the voice activation state of a given subId.
3308 */
3309 @Override
3310 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
fionaxu0152e512016-11-14 13:36:14 -08003313 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 if (phone != null) {
3317 return phone.getVoiceActivationState();
3318 } else {
3319 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3320 }
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003323 }
3324 }
3325
3326 /**
3327 * Returns the data activation state of a given subId.
3328 */
3329 @Override
3330 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
fionaxu0152e512016-11-14 13:36:14 -08003333 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (phone != null) {
3337 return phone.getDataActivationState();
3338 } else {
3339 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003343 }
3344 }
3345
3346 /**
Wink Saville36469e72014-06-11 15:17:00 -07003347 * Returns the unread count of voicemails for a subId
3348 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003350 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3351 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003353 mApp, subId, callingPackage, callingFeatureId,
3354 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003355 return 0;
3356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone phone = getPhone(subId);
3360 if (phone != null) {
3361 return phone.getVoiceMessageCount();
3362 } else {
3363 return 0;
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003371 * returns true, if the device is in a state where both voice and data
3372 * are supported simultaneously. This can change based on location or network condition.
3373 */
3374 @Override
3375 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003383 }
3384
3385 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003386 * Send the dialer code if called from the current default dialer or the caller has
3387 * carrier privilege.
3388 * @param inputCode The dialer code to send
3389 */
3390 @Override
3391 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003394 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3395 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003396 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003397 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003398 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
fionaxu235cc5e2017-03-06 22:25:57 -08003407 }
3408
Pengquan Menga1bb6272018-09-06 09:59:22 -07003409 @Override
3410 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003411 TelephonyPermissions
3412 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3413 mApp, subId, "getNetworkSelectionMode");
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 if (!isActiveSubscription(subId)) {
3417 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3418 }
3419 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003422 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003423 }
3424
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003426 public boolean isInEmergencySmsMode() {
3427 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 for (Phone phone : PhoneFactory.getPhones()) {
3431 if (phone.isInEmergencySmsMode()) {
3432 return true;
3433 }
3434 }
3435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 return false;
3439 }
3440
shilu366312e2019-12-17 09:28:10 -08003441 /**
3442 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3443 * @param subId The subscription to use to check the configuration.
3444 * @param c The callback that will be used to send the result.
3445 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003446 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003447 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3448 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003449 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3450 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003451
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003452 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3454 "IMS not available on device.");
3455 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 final long token = Binder.clearCallingIdentity();
3457 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
3462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
shilu366312e2019-12-17 09:28:10 -08003468 /**
3469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3470 * @param subId The subscription to use to check the configuration.
3471 * @param c The callback that will be used to send the result.
3472 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003473 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003474 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003475 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3476 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003477 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3478 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3479 }
Meng Wangafbc5852019-09-19 17:37:13 -07003480 final long token = Binder.clearCallingIdentity();
3481 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003482 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003483 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3484 .removeRegistrationCallbackForSubscription(c, subId);
3485 } catch (ImsException e) {
3486 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3487 + "is inactive, ignoring unregister.");
3488 // If the subscription is no longer active, just return, since the callback
3489 // will already have been removed internally.
3490 } finally {
3491 Binder.restoreCallingIdentity(token);
3492 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 }
3494
Brad Ebingera34a6c22019-10-22 17:36:18 -07003495 /**
3496 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3497 */
3498 @Override
3499 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3500 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3501 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3502 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3503 "IMS not available on device.");
3504 }
3505 final long token = Binder.clearCallingIdentity();
3506 try {
3507 Phone phone = getPhone(subId);
3508 if (phone == null) {
3509 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3510 + subId + "'");
3511 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3512 }
3513 phone.getImsRegistrationState(regState -> {
3514 try {
3515 consumer.accept((regState == null)
3516 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3517 } catch (RemoteException e) {
3518 // Ignore if the remote process is no longer available to call back.
3519 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3520 }
3521 });
3522 } finally {
3523 Binder.restoreCallingIdentity(token);
3524 }
3525 }
3526
3527 /**
3528 * Get the transport type for the IMS service registration state.
3529 */
3530 @Override
3531 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003532 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3533 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003534 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3536 "IMS not available on device.");
3537 }
3538 final long token = Binder.clearCallingIdentity();
3539 try {
3540 Phone phone = getPhone(subId);
3541 if (phone == null) {
3542 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3543 + subId + "'");
3544 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3545 }
3546 phone.getImsRegistrationTech(regTech -> {
3547 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3548 int regTechConverted = (regTech == null)
3549 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3550 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3551 regTechConverted);
3552 try {
3553 consumer.accept(regTechConverted);
3554 } catch (RemoteException e) {
3555 // Ignore if the remote process is no longer available to call back.
3556 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3557 }
3558 });
3559 } finally {
3560 Binder.restoreCallingIdentity(token);
3561 }
3562 }
3563
shilu366312e2019-12-17 09:28:10 -08003564 /**
3565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3566 * @param subId The subscription to use to check the configuration.
3567 * @param c The callback that will be used to send the result.
3568 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003570 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3571 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003572 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3573 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003574 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3576 "IMS not available on device.");
3577 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3579 final long token = Binder.clearCallingIdentity();
3580 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003583 } catch (ImsException e) {
3584 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 } finally {
3586 Binder.restoreCallingIdentity(token);
3587 }
3588 }
3589
shilu366312e2019-12-17 09:28:10 -08003590 /**
3591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3592 * @param subId The subscription to use to check the configuration.
3593 * @param c The callback that will be used to send the result.
3594 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003596 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003597 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3598 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3600 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3601 }
Meng Wangafbc5852019-09-19 17:37:13 -07003602
3603 final long token = Binder.clearCallingIdentity();
3604 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003605 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003606 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003607 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003608 } catch (ImsException e) {
3609 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3610 + "is inactive, ignoring unregister.");
3611 // If the subscription is no longer active, just return, since the callback
3612 // will already have been removed internally.
3613 } finally {
3614 Binder.restoreCallingIdentity(token);
3615 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 }
3617
3618 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003619 public boolean isCapable(int subId, int capability, int regTech) {
3620 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3622 final long token = Binder.clearCallingIdentity();
3623 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003624 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003626 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3628 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003629 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003630 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3631 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 } finally {
3633 Binder.restoreCallingIdentity(token);
3634 }
3635 }
3636
3637 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003638 public boolean isAvailable(int subId, int capability, int regTech) {
3639 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 final long token = Binder.clearCallingIdentity();
3641 try {
3642 Phone phone = getPhone(subId);
3643 if (phone == null) return false;
3644 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003645 } catch (com.android.ims.ImsException e) {
3646 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3647 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 } finally {
3649 Binder.restoreCallingIdentity(token);
3650 }
3651 }
3652
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003653 /**
3654 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3655 * subscription.
3656 * @param subId The subscription to use to check the configuration.
3657 * @param callback The callback that will be used to send the result.
3658 * @param capability The MmTelFeature capability that will be used to send the result.
3659 * @param transportType The transport type of the MmTelFeature capability.
3660 */
3661 @Override
3662 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3663 int transportType) {
3664 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3665 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3667 "IMS not available on device.");
3668 }
3669 final long token = Binder.clearCallingIdentity();
3670 try {
3671 int slotId = getSlotIndex(subId);
3672 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3673 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3674 + subId + "'");
3675 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3676 }
3677 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3678 transportType, aBoolean -> {
3679 try {
3680 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3681 } catch (RemoteException e) {
3682 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3683 + "running. Ignore");
3684 }
3685 });
3686 } finally {
3687 Binder.restoreCallingIdentity(token);
3688 }
3689 }
3690
shilu366312e2019-12-17 09:28:10 -08003691 /**
3692 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3693 * @param subId The subscription to use to check the configuration.
3694 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 @Override
3696 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003697 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3698 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003699
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3701 final long token = Binder.clearCallingIdentity();
3702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (ImsException e) {
3706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(token);
3709 }
3710 }
3711
3712 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003713 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003715 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 } catch (ImsException e) {
3722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
shilu366312e2019-12-17 09:28:10 -08003728 /**
3729 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3730 * @param subId The subscription to use to check the configuration.
3731 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003733 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003734 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3735 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003739 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003748 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003750 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 } catch (ImsException e) {
3756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
shilu366312e2019-12-17 09:28:10 -08003762 /**
3763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3764 * @param subId The subscription to use to check the configuration.
3765 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 @Override
3767 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003768 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3769 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003775 } catch (ImsException e) {
3776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
3782 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003783 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003785 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003790 } catch (ImsException e) {
3791 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 } finally {
3793 Binder.restoreCallingIdentity(identity);
3794 }
3795 }
3796
shilu366312e2019-12-17 09:28:10 -08003797 /**
3798 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3799 * @param subId The subscription to use to check the configuration.
3800 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 @Override
3802 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003803 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3804 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003808 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003810 } catch (ImsException e) {
3811 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
3815 }
3816
3817 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003818 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003820 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003824 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003826 } catch (ImsException e) {
3827 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
3831 }
3832
3833 @Override
3834 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3836 "setVoWiFiNonPersistent");
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003840 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003841 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003842 } catch (ImsException e) {
3843 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
3847 }
3848
shilu366312e2019-12-17 09:28:10 -08003849 /**
3850 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3851 * @param subId The subscription to use to check the configuration.
3852 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 @Override
3854 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003855 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3856 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003860 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003862 } catch (ImsException e) {
3863 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
3869 @Override
3870 public void setVoWiFiModeSetting(int subId, int mode) {
3871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3872 "setVoWiFiModeSetting");
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003876 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003878 } catch (ImsException e) {
3879 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 } finally {
3881 Binder.restoreCallingIdentity(identity);
3882 }
3883 }
3884
3885 @Override
3886 public int getVoWiFiRoamingModeSetting(int subId) {
3887 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003891 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003893 } catch (ImsException e) {
3894 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
3898 }
3899
3900 @Override
3901 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3903 "setVoWiFiRoamingModeSetting");
3904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003907 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003909 } catch (ImsException e) {
3910 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 } finally {
3912 Binder.restoreCallingIdentity(identity);
3913 }
3914 }
3915
3916 @Override
3917 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3919 "setRttCapabilityEnabled");
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003923 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3924 } catch (ImsException e) {
3925 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 } finally {
3927 Binder.restoreCallingIdentity(identity);
3928 }
3929 }
3930
shilu366312e2019-12-17 09:28:10 -08003931 /**
3932 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3933 * @param subId The subscription to use to check the configuration.
3934 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 @Override
3936 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003937 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3938 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003943 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003944 } catch (ImsException e) {
3945 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
3949 }
3950
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003951 @Override
3952 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3953 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003956 if (!isImsAvailableOnDevice()) {
3957 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3958 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003959 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003960 // 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 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003963 } catch (ImsException e) {
3964 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
3968 }
3969
3970 @Override
3971 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3972 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3973 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3975 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3976 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003977 try {
3978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003980 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003981 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003982 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3983 + "is inactive, ignoring unregister.");
3984 // If the subscription is no longer active, just return, since the callback will already
3985 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
3989 }
3990
allenwtsu99c623b2020-01-03 18:24:23 +08003991
3992 private void checkModifyPhoneStatePermission(int subId, String message) {
3993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3994 message);
3995 }
3996
3997 private boolean isImsProvisioningRequired(int subId, int capability,
3998 boolean isMmtelCapability) {
3999 Phone phone = getPhone(subId);
4000 if (phone == null) {
4001 loge("phone instance null for subid " + subId);
4002 return false;
4003 }
4004 if (isMmtelCapability) {
4005 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4006 return false;
4007 }
4008 } else {
4009 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4010 return false;
4011 }
4012 }
4013 return true;
4014 }
4015
4016 @Override
4017 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4018 boolean isProvisioned) {
4019 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4024 if (!isImsProvisioningRequired(subId, capability, false)) {
4025 return;
4026 }
4027
4028 // this capability requires provisioning, route to the correct API.
4029 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4030 switch (capability) {
4031 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4032 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4033 ims.setEabProvisioned(isProvisioned);
4034 break;
4035 default: {
4036 throw new IllegalArgumentException("Tried to set provisioning for "
4037 + "rcs capability '" + capability + "', which does not require "
4038 + "provisioning.");
4039 }
4040 }
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044
4045 }
4046
4047
4048 @Override
4049 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4050 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4054 if (!isImsProvisioningRequired(subId, capability, false)) {
4055 return true;
4056 }
4057
4058 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4059 switch (capability) {
4060 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4061 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4062 return ims.isEabProvisionedOnDevice();
4063
4064 default: {
4065 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4066 + "capability '" + capability + "', which does not require "
4067 + "provisioning.");
4068 }
4069 }
4070
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004076 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004077 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4078 boolean isProvisioned) {
4079 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4080 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4081 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4082 }
allenwtsu99c623b2020-01-03 18:24:23 +08004083 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004087 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004088 return;
4089 }
4090
4091 // this capability requires provisioning, route to the correct API.
4092 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4093 switch (capability) {
4094 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4095 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4096 ims.setVolteProvisioned(isProvisioned);
4097 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4098 ims.setWfcProvisioned(isProvisioned);
4099 }
4100 break;
4101 }
4102 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4103 // There is currently no difference in VT provisioning type.
4104 ims.setVtProvisioned(isProvisioned);
4105 break;
4106 }
4107 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4108 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4109 // change the capability of the feature instead if needed.
4110 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4111 == isProvisioned) {
4112 // No change in provisioning.
4113 return;
4114 }
4115 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4116 try {
4117 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004118 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4120 + ", Exception" + e.getMessage());
4121 }
4122 break;
4123 }
4124 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004125 throw new IllegalArgumentException("Tried to set provisioning for "
4126 + "MmTel capability '" + capability + "', which does not require "
4127 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 }
4129 }
4130
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
4134 }
4135
4136 @Override
4137 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4138 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4139 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4140 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4141 }
4142 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004146 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 return true;
4148 }
4149
4150 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4151 switch (capability) {
4152 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4153 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4154 return ims.isVolteProvisionedOnDevice();
4155 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4156 return ims.isWfcProvisionedOnDevice();
4157 }
4158 // This should never happen, since we are checking tech above to make sure it
4159 // is either LTE or IWLAN.
4160 throw new IllegalArgumentException("Invalid radio technology for voice "
4161 + "capability.");
4162 }
4163 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4164 // There is currently no difference in VT provisioning type.
4165 return ims.isVtProvisionedOnDevice();
4166 }
4167 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4168 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4169 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4170 }
4171 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004172 throw new IllegalArgumentException(
4173 "Tried to get provisioning for MmTel capability '" + capability
4174 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 }
4176 }
4177
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
4181 }
4182
4183 @Override
4184 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4185 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4186 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4187 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4188 }
4189 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4190 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4191 return (provisionedBits & capability) > 0;
4192 }
4193
4194 @Override
4195 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4196 boolean isProvisioned) {
4197 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4198 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4199 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4200 }
4201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4202 "setProvisioningStatusForCapability");
4203 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4204 // If the current provisioning status for capability already matches isProvisioned,
4205 // do nothing.
4206 if (((provisionedBits & capability) > 0) == isProvisioned) {
4207 return;
4208 }
4209 if (isProvisioned) {
4210 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4211 } else {
4212 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4213 }
4214 }
4215
4216 /**
4217 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4218 * technology. The bitfield should mirror the bitfield defined by
4219 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4220 */
4221 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4222 String key = getMmTelProvisioningKey(subId, tech);
4223 // Default is no capabilities are provisioned.
4224 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4225 }
4226
4227 /**
4228 * Sets the MmTel capability provisioning bitfield (defined by
4229 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4230 * technology specified.
4231 *
4232 * Note: This is a synchronous command and should not be called on UI thread.
4233 */
4234 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4235 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4236 String key = getMmTelProvisioningKey(subId, tech);
4237 editor.putInt(key, newField);
4238 editor.commit();
4239 }
4240
4241 private static String getMmTelProvisioningKey(int subId, int tech) {
4242 // resulting key is provision_ims_mmtel_{subId}_{tech}
4243 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4244 }
4245
4246 /**
4247 * Query CarrierConfig to see if the specified capability requires provisioning for the
4248 * carrier associated with the subscription id.
4249 */
4250 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4251 int capability) {
4252 CarrierConfigManager configManager = new CarrierConfigManager(context);
4253 PersistableBundle c = configManager.getConfigForSubId(subId);
4254 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004255 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004256 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4257 false);
4258 boolean requireVoiceVtProvisioning = c.getBoolean(
4259 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4260
4261 // First check to make sure that the capability requires provisioning.
4262 switch (capability) {
4263 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4264 // intentional fallthrough
4265 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4266 if (requireVoiceVtProvisioning) {
4267 // Voice and Video requires provisioning
4268 return true;
4269 }
4270 break;
4271 }
4272 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4273 if (requireUtProvisioning) {
4274 // UT requires provisioning
4275 return true;
4276 }
4277 break;
4278 }
4279 }
4280 return false;
4281 }
4282
allenwtsu99c623b2020-01-03 18:24:23 +08004283 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4284 int capability) {
4285 CarrierConfigManager configManager = new CarrierConfigManager(context);
4286 PersistableBundle c = configManager.getConfigForSubId(subId);
4287
4288 boolean requireRcsProvisioning = c.getBoolean(
4289 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4290
4291 // First check to make sure that the capability requires provisioning.
4292 switch (capability) {
4293 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4294 // intentional fallthrough
4295 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4296 if (requireRcsProvisioning) {
4297 // OPTION or PRESENCE requires provisioning
4298 return true;
4299 }
4300 break;
4301 }
4302 }
4303 return false;
4304 }
4305
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004306 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004307 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4309 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4310 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004311 enforceReadPrivilegedPermission("getImsProvisioningInt");
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004315 int slotId = getSlotIndex(subId);
4316 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4317 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4318 + subId + "' for key:" + key);
4319 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4320 }
4321 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004323 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4324 + subId + "' for key:" + key);
4325 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 @Override
4332 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004333 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4334 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4335 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004336 enforceReadPrivilegedPermission("getImsProvisioningString");
4337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004340 int slotId = getSlotIndex(subId);
4341 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4342 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4343 + subId + "' for key:" + key);
4344 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4345 }
4346 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004347 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4349 + subId + "' for key:" + key);
4350 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
4354 }
4355
4356 @Override
4357 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004358 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4359 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4360 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4362 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 int slotId = getSlotIndex(subId);
4367 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4368 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4369 + subId + "' for key:" + key);
4370 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4371 }
4372 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004374 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4375 + "' for key:" + key);
4376 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
4382 @Override
4383 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4385 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4386 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4388 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004389 final long identity = Binder.clearCallingIdentity();
4390 try {
4391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004392 int slotId = getSlotIndex(subId);
4393 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4394 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4395 + subId + "' for key:" + key);
4396 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4397 }
4398 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004399 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004400 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4401 + "' for key:" + key);
4402 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004408 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004409 int slotId = SubscriptionManager.getSlotIndex(subId);
4410 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004411 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4412 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 }
4414 return slotId;
4415 }
4416
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 private int getSlotIndex(int subId) {
4418 int slotId = SubscriptionManager.getSlotIndex(subId);
4419 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4420 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4421 }
4422 return slotId;
4423 }
4424
Wink Saville36469e72014-06-11 15:17:00 -07004425 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004426 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004427 */
4428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004429 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4430 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004431 final int targetSdk = getTargetSdk(callingPackage);
4432 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004433 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004434 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004435 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004436 mApp, subId, callingPackage, callingFeatureId,
4437 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004438 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4439 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 final long identity = Binder.clearCallingIdentity();
4442 try {
4443 final Phone phone = getPhone(subId);
4444 if (phone != null) {
4445 return phone.getServiceState().getDataNetworkType();
4446 } else {
4447 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4448 }
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004452 }
4453
4454 /**
4455 * Returns the data network type
4456 */
4457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004458 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4459 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4460 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004461 }
4462
4463 /**
4464 * Returns the data network type for a subId
4465 */
4466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004467 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4468 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004470 mApp, subId, callingPackage, callingFeatureId,
4471 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004472 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4473 }
4474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 final Phone phone = getPhone(subId);
4478 if (phone != null) {
4479 return phone.getServiceState().getDataNetworkType();
4480 } else {
4481 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4482 }
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004486 }
4487
4488 /**
Wink Saville36469e72014-06-11 15:17:00 -07004489 * Returns the Voice network type for a subId
4490 */
4491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004492 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4493 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004495 mApp, subId, callingPackage, callingFeatureId,
4496 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004497 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4498 }
4499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 final Phone phone = getPhone(subId);
4503 if (phone != null) {
4504 return phone.getServiceState().getVoiceNetworkType();
4505 } else {
4506 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4507 }
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004511 }
4512
4513 /**
4514 * @return true if a ICC card is present
4515 */
4516 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004517 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004518 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4519 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004520 }
4521
4522 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004523 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004524 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004525 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004526 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 final Phone phone = PhoneFactory.getPhone(slotIndex);
4530 if (phone != null) {
4531 return phone.getIccCard().hasIccCard();
4532 } else {
4533 return false;
4534 }
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004538 }
4539
4540 /**
4541 * Return if the current radio is LTE on CDMA. This
4542 * is a tri-state return value as for a period of time
4543 * the mode may be unknown.
4544 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004545 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004546 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004547 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004548 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004550 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4551 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4552 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004553 }
4554
Sanket Padawe356d7632015-06-22 14:03:32 -07004555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004556 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4557 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004558 try {
4559 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4560 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004561 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4562 }
4563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 final Phone phone = getPhone(subId);
4567 if (phone == null) {
4568 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4569 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004570 return TelephonyProperties.lte_on_cdma_device()
4571 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 }
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004575 }
Wink Saville36469e72014-06-11 15:17:00 -07004576 }
4577
Wink Saville36469e72014-06-11 15:17:00 -07004578 /**
4579 * {@hide}
4580 * Returns Default subId, 0 in the case of single standby.
4581 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004582 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004583 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004584 }
4585
Shishir Agrawala9f32182016-04-12 12:00:16 -07004586 private int getSlotForDefaultSubscription() {
4587 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4588 }
4589
Wink Savilleb564aae2014-10-23 10:18:09 -07004590 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004591 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004592 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004593
Pengquan Menge92a50d2018-09-21 15:54:48 -07004594 private boolean isActiveSubscription(int subId) {
4595 return mSubscriptionController.isActiveSubId(subId);
4596 }
4597
Ihab Awadf2177b72013-11-25 13:33:23 -08004598 /**
4599 * @see android.telephony.TelephonyManager.WifiCallingChoices
4600 */
4601 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 final long identity = Binder.clearCallingIdentity();
4603 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4606 getWhenToMakeWifiCallsDefaultPreference());
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
4609 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004610 }
4611
4612 /**
4613 * @see android.telephony.TelephonyManager.WifiCallingChoices
4614 */
4615 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004619 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004624 }
4625
Sailesh Nepald1e68152013-12-12 19:08:02 -08004626 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004627 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004628 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004629 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004630
Jordan Liu4c733742019-02-28 12:03:40 -08004631 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4632 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4633 if (phoneId == -1) {
4634 throw new IllegalArgumentException("Given slot index: " + slotIndex
4635 + " does not correspond to an active phone");
4636 }
4637 return PhoneFactory.getPhone(phoneId);
4638 }
4639
Shishir Agrawal566b7612013-10-28 14:41:00 -07004640 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004641 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4642 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4644 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004646 if (DBG) {
4647 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4648 }
4649 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4650 p2);
4651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004652
Jordan Liu4c733742019-02-28 12:03:40 -08004653
4654 @Override
4655 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4656 int slotIndex, String callingPackage, String aid, int p2) {
4657 enforceModifyPermission();
4658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4659 if (DBG) {
4660 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4661 }
4662 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4663 callingPackage, aid, p2);
4664 }
4665
4666 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4667 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 if (TextUtils.equals(ISDR_AID, aid)) {
4671 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004672 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4673 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 if (bestComponent == null
4675 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4676 loge("The calling package is not allowed to access ISD-R.");
4677 throw new SecurityException(
4678 "The calling package is not allowed to access ISD-R.");
4679 }
Derek Tan740e1672017-06-27 14:56:27 -07004680 }
Derek Tan740e1672017-06-27 14:56:27 -07004681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004683 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4684 null /* workSource */);
4685 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686 return response;
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
4689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004690 }
4691
4692 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004693 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4695 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004696 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4697 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4698 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004699
Jordan Liu4c733742019-02-28 12:03:40 -08004700 @Override
4701 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4702 enforceModifyPermission();
4703 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4704 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4705 channel);
4706 }
4707
4708 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 final long identity = Binder.clearCallingIdentity();
4710 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 if (channel < 0) {
4712 return false;
4713 }
Jordan Liu4c733742019-02-28 12:03:40 -08004714 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4715 null /* workSource */);
4716 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 return success;
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004720 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004721 }
4722
4723 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004724 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004725 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4727 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004728 if (DBG) {
4729 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4730 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4731 + p3 + " data=" + data);
4732 }
4733 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4734 command, p1, p2, p3, data);
4735 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004736
Jordan Liu4c733742019-02-28 12:03:40 -08004737 @Override
4738 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4739 int command, int p1, int p2, int p3, String data) {
4740 enforceModifyPermission();
4741 if (DBG) {
4742 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4743 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4744 + p3 + " data=" + data);
4745 }
4746 return iccTransmitApduLogicalChannelWithPermission(
4747 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4748 data);
4749 }
4750
4751 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4752 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 final long identity = Binder.clearCallingIdentity();
4754 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004755 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 return "";
4757 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004760 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4761 null /* workSource */);
4762 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 // Append the returned status code to the end of the response payload.
4765 String s = Integer.toHexString(
4766 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4767 if (response.payload != null) {
4768 s = IccUtils.bytesToHexString(response.payload) + s;
4769 }
4770 return s;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004774 }
Jake Hambye994d462014-02-03 13:10:13 -08004775
Evan Charltonc66da362014-05-16 14:06:40 -07004776 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004777 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4778 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4780 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004782 if (DBG) {
4783 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4784 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4785 }
4786 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4787 cla, command, p1, p2, p3, data);
4788 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004789
Jordan Liu4c733742019-02-28 12:03:40 -08004790 @Override
4791 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4792 int command, int p1, int p2, int p3, String data) {
4793 enforceModifyPermission();
4794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4795 if (DBG) {
4796 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4797 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4798 + " data=" + data);
4799 }
4800
4801 return iccTransmitApduBasicChannelWithPermission(
4802 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4803 p2, p3, data);
4804 }
4805
4806 // open APDU basic channel assuming the caller has sufficient permissions
4807 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4808 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4812 && TextUtils.equals(ISDR_AID, data)) {
4813 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004814 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4815 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 if (bestComponent == null
4817 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4818 loge("The calling package is not allowed to select ISD-R.");
4819 throw new SecurityException(
4820 "The calling package is not allowed to select ISD-R.");
4821 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004822 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004825 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4826 null /* workSource */);
4827 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 // Append the returned status code to the end of the response payload.
4830 String s = Integer.toHexString(
4831 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4832 if (response.payload != null) {
4833 s = IccUtils.bytesToHexString(response.payload) + s;
4834 }
4835 return s;
4836 } finally {
4837 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004838 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004839 }
4840
4841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004842 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004843 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4845 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 if (DBG) {
4850 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4851 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4852 }
4853
4854 IccIoResult response =
4855 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4856 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4857 subId);
4858
4859 if (DBG) {
4860 log("Exchange SIM_IO [R]" + response);
4861 }
4862
4863 byte[] result = null;
4864 int length = 2;
4865 if (response.payload != null) {
4866 length = 2 + response.payload.length;
4867 result = new byte[length];
4868 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4869 } else {
4870 result = new byte[length];
4871 }
4872
4873 result[length - 1] = (byte) response.sw2;
4874 result[length - 2] = (byte) response.sw1;
4875 return result;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004878 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004879 }
4880
Nathan Haroldb3014052017-01-25 15:57:32 -08004881 /**
4882 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4883 * on a particular subscription
4884 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004885 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4886 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004888 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004889 return null;
4890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 if (appType != TelephonyManager.APPTYPE_USIM
4895 && appType != TelephonyManager.APPTYPE_SIM) {
4896 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4897 return null;
4898 }
4899 Object response = sendRequest(
4900 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4901 if (response instanceof String[]) {
4902 return (String[]) response;
4903 }
yincheng zhao2737e882019-09-06 17:06:54 -07004904 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004906 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004909 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004910 }
4911
yincheng zhao2737e882019-09-06 17:06:54 -07004912 /**
4913 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4914 * subscription.
4915 *
4916 * @param subId the id of the subscription.
4917 * @param appType the uicc app type, must be USIM or SIM.
4918 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4919 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004920 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004921 * @return number of fplmns that is successfully written to the SIM.
4922 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4924 String callingFeatureId) {
4925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4926 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004927 if (DBG) logv("no permissions for setForbiddenplmns");
4928 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4929 }
4930 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4931 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4932 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4933 }
4934 if (fplmns == null) {
4935 throw new IllegalArgumentException("Fplmn List provided is null");
4936 }
4937 for (String fplmn : fplmns) {
4938 if (!CellIdentity.isValidPlmn(fplmn)) {
4939 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4940 }
4941 }
4942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 Object response = sendRequest(
4945 CMD_SET_FORBIDDEN_PLMNS,
4946 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4947 subId);
4948 return (int) response;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
4952 }
4953
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004955 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4957 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4962 if (response.payload == null) {
4963 return "";
4964 }
Evan Charltonc66da362014-05-16 14:06:40 -07004965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 // Append the returned status code to the end of the response payload.
4967 String s = Integer.toHexString(
4968 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4969 s = IccUtils.bytesToHexString(response.payload) + s;
4970 return s;
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Evan Charltonc66da362014-05-16 14:06:40 -07004974 }
4975
Jake Hambye994d462014-02-03 13:10:13 -08004976 /**
4977 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4978 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4979 *
4980 * @param itemID the ID of the item to read
4981 * @return the NV item as a String, or null on error.
4982 */
4983 @Override
4984 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4987 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988
4989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004992 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4994 return value;
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Jake Hambye994d462014-02-03 13:10:13 -08004998 }
4999
5000 /**
5001 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5002 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5003 *
5004 * @param itemID the ID of the item to read
5005 * @param itemValue the value to write, as a String
5006 * @return true on success; false on any failure
5007 */
5008 @Override
5009 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005010 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5012 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013
5014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5017 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005018 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5020 return success;
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Jake Hambye994d462014-02-03 13:10:13 -08005024 }
5025
5026 /**
5027 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5028 * Used for device configuration by some CDMA operators.
5029 *
5030 * @param preferredRoamingList byte array containing the new PRL
5031 * @return true on success; false on any failure
5032 */
5033 @Override
5034 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5036 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037
5038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5041 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5042 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5043 return success;
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
Jake Hambye994d462014-02-03 13:10:13 -08005047 }
5048
5049 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005050 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005051 * Used for device configuration by some CDMA operators.
5052 *
chen xu6dac5ab2018-10-26 17:39:23 -07005053 * @param slotIndex - device slot.
5054 *
Jake Hambye994d462014-02-03 13:10:13 -08005055 * @return true on success; false on any failure
5056 */
5057 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005058 public boolean resetModemConfig(int slotIndex) {
5059 Phone phone = PhoneFactory.getPhone(slotIndex);
5060 if (phone != null) {
5061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5062 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063
chen xu6dac5ab2018-10-26 17:39:23 -07005064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5067 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5068 return success;
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 }
chen xu6dac5ab2018-10-26 17:39:23 -07005073 return false;
5074 }
5075
5076 /**
5077 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5078 *
5079 * @param slotIndex - device slot.
5080 *
5081 * @return true on success; false on any failure
5082 */
5083 @Override
5084 public boolean rebootModem(int slotIndex) {
5085 Phone phone = PhoneFactory.getPhone(slotIndex);
5086 if (phone != null) {
5087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5088 mApp, phone.getSubId(), "rebootModem");
5089
5090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5093 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5094 return success;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
5098 }
5099 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005100 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005101
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005102 public String[] getPcscfAddress(String apnType, String callingPackage,
5103 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005104 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5106 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005107 return new String[0];
5108 }
5109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
Wink Saville36469e72014-06-11 15:17:00 -07005116 }
5117
Brad Ebinger51f743a2017-01-23 13:50:20 -08005118 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005119 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5120 * {@link #disableIms(int)}.
5121 * @param slotIndex device slot.
5122 */
5123 public void resetIms(int slotIndex) {
5124 enforceModifyPermission();
5125
5126 final long identity = Binder.clearCallingIdentity();
5127 try {
5128 if (mImsResolver == null) {
5129 // may happen if the does not support IMS.
5130 return;
5131 }
5132 mImsResolver.disableIms(slotIndex);
5133 mImsResolver.enableIms(slotIndex);
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
5139 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005140 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5141 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005142 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005143 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005148 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005149 // may happen if the device does not support IMS.
5150 return;
5151 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005152 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005156 }
5157
5158 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005159 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5160 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005161 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005162 public void disableIms(int slotId) {
5163 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005167 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005168 // may happen if the device does not support IMS.
5169 return;
5170 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005171 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005175 }
5176
5177 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005178 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5179 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005180 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005181 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005182 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005187 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005188 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5189 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005190 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005191 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005195 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005196 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005197 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5198 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005199 @Override
5200 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005201 enforceModifyPermission();
5202
5203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005206 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
5210 }
5211
5212 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005213 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005214 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005215 */
5216 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005221 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005222 // may happen if the device does not support IMS.
5223 return null;
5224 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005225 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005229 }
5230
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005231 /**
5232 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005233 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005234 */
5235 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005240 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005241 // may happen if the device does not support IMS.
5242 return null;
5243 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005244 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005248 }
5249
Brad Ebinger884c07b2018-02-15 16:17:40 -08005250 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005251 * Sets the ImsService Package Name that Telephony will bind to.
5252 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005253 * @param slotIndex the slot ID that the ImsService should bind for.
5254 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005255 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005256 * @param featureTypes An integer array of feature types associated with a packageName.
5257 * @param packageName The name of the package that the current configuration will be replaced
5258 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005259 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005260 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005261 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5262 int[] featureTypes, String packageName) {
5263 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5266 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005267 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005271 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005272 // may happen if the device does not support IMS.
5273 return false;
5274 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005275 Map<Integer, String> featureConfig = new HashMap<>();
5276 for (int featureType : featureTypes) {
5277 featureConfig.put(featureType, packageName);
5278 }
5279 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5280 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005284 }
5285
5286 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005287 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005288 *
5289 * @param slotId The slot that the ImsService is associated with.
5290 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5291 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005292 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005293 * @return the package name of the ImsService configuration.
5294 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005295 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5296 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005297 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005298 TelephonyPermissions
5299 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5300 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5301 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 final long identity = Binder.clearCallingIdentity();
5304 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005305 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005306 // may happen if the device does not support IMS.
5307 return "";
5308 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005309 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005310 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5311 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005315 }
5316
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005317 /**
5318 * Get the MmTelFeature state associated with the requested subscription id.
5319 * @param subId The subscription that the MmTelFeature is associated with.
5320 * @param callback A callback with an integer containing the
5321 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5322 */
5323 @Override
5324 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5325 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5326 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5327 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5328 "IMS not available on device.");
5329 }
5330 final long token = Binder.clearCallingIdentity();
5331 try {
5332 int slotId = getSlotIndex(subId);
5333 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5334 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5335 + subId + "'");
5336 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5337 }
5338 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5339 try {
5340 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5341 } catch (RemoteException e) {
5342 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5343 + "Ignore");
5344 }
5345 });
5346 } finally {
5347 Binder.restoreCallingIdentity(token);
5348 }
5349 }
5350
Wink Saville36469e72014-06-11 15:17:00 -07005351 public void setImsRegistrationState(boolean registered) {
5352 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353
5354 final long identity = Binder.clearCallingIdentity();
5355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005356 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Wink Saville36469e72014-06-11 15:17:00 -07005360 }
5361
5362 /**
Stuart Scott54788802015-03-30 13:18:01 -07005363 * Set the network selection mode to automatic.
5364 *
5365 */
5366 @Override
5367 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5369 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370
5371 final long identity = Binder.clearCallingIdentity();
5372 try {
shilufc958392020-01-20 11:36:01 -08005373 if (!isActiveSubscription(subId)) {
5374 return;
5375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5377 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Stuart Scott54788802015-03-30 13:18:01 -07005381 }
5382
Jack Yud10cdd42020-09-28 20:28:01 -07005383 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005384 * Ask the radio to connect to the input network and change selection mode to manual.
5385 *
5386 * @param subId the id of the subscription.
5387 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5388 * the operator to attach to.
5389 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5390 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5391 * normal network selection next time.
5392 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005393 */
5394 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005395 public boolean setNetworkSelectionModeManual(
5396 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5398 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005399
5400 if (!isActiveSubscription(subId)) {
5401 return false;
5402 }
5403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005406 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005408 if (DBG) {
5409 log("setNetworkSelectionModeManual: subId: " + subId
5410 + " operator: " + operatorInfo);
5411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005416 }
shilu84f6e8b2019-12-19 13:58:01 -08005417 /**
5418 * Get the manual network selection
5419 *
5420 * @param subId the id of the subscription.
5421 *
5422 * @return the previously saved user selected PLMN
5423 */
5424 @Override
5425 public String getManualNetworkSelectionPlmn(int subId) {
5426 TelephonyPermissions
5427 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5428 mApp, subId, "getManualNetworkSelectionPlmn");
5429
5430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005433 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005434 }
5435
5436 final Phone phone = getPhone(subId);
5437 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005438 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005439 }
5440 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5441 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5442 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
5446 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005447
5448 /**
5449 * Scans for available networks.
5450 */
5451 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005452 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5453 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5455 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005456 LocationAccessPolicy.LocationPermissionResult locationResult =
5457 LocationAccessPolicy.checkLocationPermission(mApp,
5458 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5459 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005460 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005461 .setCallingPid(Binder.getCallingPid())
5462 .setCallingUid(Binder.getCallingUid())
5463 .setMethod("getCellNetworkScanResults")
5464 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005465 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5466 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005467 .build());
5468 switch (locationResult) {
5469 case DENIED_HARD:
5470 throw new SecurityException("Not allowed to access scan results -- location");
5471 case DENIED_SOFT:
5472 return null;
5473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474
Pengquan Menga1bb6272018-09-06 09:59:22 -07005475 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 try {
5477 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005478 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005483 }
5484
5485 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005486 * Get the call forwarding info, given the call forwarding reason.
5487 */
5488 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005489 public void getCallForwarding(int subId, int callForwardingReason,
5490 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005491 enforceReadPrivilegedPermission("getCallForwarding");
5492 long identity = Binder.clearCallingIdentity();
5493 try {
5494 if (DBG) {
5495 log("getCallForwarding: subId " + subId
5496 + " callForwardingReason" + callForwardingReason);
5497 }
Hall Liu27d24262020-09-18 19:04:59 -07005498
5499 Phone phone = getPhone(subId);
5500 if (phone == null) {
5501 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005502 callback.onError(
5503 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005504 } catch (RemoteException e) {
5505 // ignore
5506 }
5507 return;
5508 }
5509
5510 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5511 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5512 @Override
5513 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5514 try {
5515 callback.onCallForwardingInfoAvailable(info);
5516 } catch (RemoteException e) {
5517 // ignore
5518 }
5519 }
5520
5521 @Override
5522 public void onError(int error) {
5523 try {
5524 callback.onError(error);
5525 } catch (RemoteException e) {
5526 // ignore
5527 }
5528 }
5529 });
5530 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
5534 }
5535
5536 /**
5537 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5538 * reason, the number to forward, and the timeout before the forwarding is attempted.
5539 */
5540 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005541 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5542 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005543 enforceModifyPermission();
5544 long identity = Binder.clearCallingIdentity();
5545 try {
5546 if (DBG) {
5547 log("setCallForwarding: subId " + subId
5548 + " callForwardingInfo" + callForwardingInfo);
5549 }
Hall Liu27d24262020-09-18 19:04:59 -07005550
5551 Phone phone = getPhone(subId);
5552 if (phone == null) {
5553 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005554 callback.accept(
5555 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005556 } catch (RemoteException e) {
5557 // ignore
5558 }
5559 return;
5560 }
5561
5562 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5563 FunctionalUtils.ignoreRemoteException(callback::accept));
5564
5565 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570
5571 /**
Hall Liu27d24262020-09-18 19:04:59 -07005572 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005573 */
5574 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005575 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005576 enforceReadPrivilegedPermission("getCallForwarding");
5577 long identity = Binder.clearCallingIdentity();
5578 try {
Hall Liu27d24262020-09-18 19:04:59 -07005579
5580 Phone phone = getPhone(subId);
5581 if (phone == null) {
5582 try {
5583 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5584 } catch (RemoteException e) {
5585 // ignore
5586 }
5587 return;
5588 }
5589
5590 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5591
Shuo Qian4a594052020-01-23 11:59:30 -08005592 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005593 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
5597 }
5598
5599 /**
Hall Liu27d24262020-09-18 19:04:59 -07005600 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005601 */
5602 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005603 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005604 enforceModifyPermission();
5605 long identity = Binder.clearCallingIdentity();
5606 try {
Hall Liu27d24262020-09-18 19:04:59 -07005607 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5608
5609 Phone phone = getPhone(subId);
5610 if (phone == null) {
5611 try {
5612 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5613 } catch (RemoteException e) {
5614 // ignore
5615 }
5616 return;
5617 }
5618
5619 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5620 FunctionalUtils.ignoreRemoteException(callback::accept));
5621
5622 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
5627
5628 /**
yinxub1bed742017-04-17 11:45:04 -07005629 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005630 *
yinxub1bed742017-04-17 11:45:04 -07005631 * @param subId id of the subscription
5632 * @param request contains the radio access networks with bands/channels to scan
5633 * @param messenger callback messenger for scan results or errors
5634 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005635 * @return the id of the requested scan which can be used to stop the scan.
5636 */
5637 @Override
5638 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005639 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5641 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005642 LocationAccessPolicy.LocationPermissionResult locationResult =
5643 LocationAccessPolicy.checkLocationPermission(mApp,
5644 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5645 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005646 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005647 .setCallingPid(Binder.getCallingPid())
5648 .setCallingUid(Binder.getCallingUid())
5649 .setMethod("requestNetworkScan")
5650 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005651 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5652 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005653 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005654 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005655 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5656 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005657 if (e != null) {
5658 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5659 throw e;
5660 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005661 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005662 return TelephonyScanManager.INVALID_SCAN_ID;
5663 }
5664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 }
Hall Liu912dfd32019-04-25 14:02:26 -07005666 int callingUid = Binder.getCallingUid();
5667 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 return mNetworkScanRequestTracker.startNetworkScan(
5671 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005672 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
yinxu504e1392017-04-12 16:03:22 -07005676 }
5677
Hall Liub2ac8ef2019-02-28 15:56:23 -08005678 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005679 NetworkScanRequest request, int subId, String callingPackage) {
5680 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005681 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5682 boolean hasNetworkScanPermission =
5683 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5684 == PERMISSION_GRANTED;
5685
5686 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5687 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5688 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005689 }
5690
5691 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5692 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005693 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5694 return new SecurityException("Specific channels must not be"
5695 + " scanned without location access.");
5696 }
5697 }
5698 }
5699
Hall Liub2ac8ef2019-02-28 15:56:23 -08005700 return null;
5701 }
5702
yinxu504e1392017-04-12 16:03:22 -07005703 /**
5704 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005705 *
5706 * @param subId id of the subscription
5707 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005708 */
5709 @Override
5710 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5712 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
Hall Liu912dfd32019-04-25 14:02:26 -07005714 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 final long identity = Binder.clearCallingIdentity();
5716 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005717 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
yinxu504e1392017-04-12 16:03:22 -07005721 }
5722
5723 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005724 * Get the calculated preferred network type.
5725 * Used for debugging incorrect network type.
5726 *
5727 * @return the preferred network type, defined in RILConstants.java.
5728 */
5729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005730 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 final Phone defaultPhone = getDefaultPhone();
5732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005733 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005734 return RILConstants.PREFERRED_NETWORK_MODE;
5735 }
5736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Junda Liu84d15a22014-07-02 11:21:04 -07005744 }
5745
5746 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005747 * Get the preferred network type.
5748 * Used for device configuration by some CDMA operators.
5749 *
5750 * @return the preferred network type, defined in RILConstants.java.
5751 */
5752 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005753 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005754 TelephonyPermissions
5755 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5756 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 if (DBG) log("getPreferredNetworkType");
5761 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5762 int networkType = (result != null ? result[0] : -1);
5763 if (DBG) log("getPreferredNetworkType: " + networkType);
5764 return networkType;
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005768 }
5769
5770 /**
5771 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005772 *
5773 * @param networkType the preferred network type, defined in RILConstants.java.
5774 * @return true on success; false on any failure.
5775 */
5776 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005777 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
calvinpan8ed33732020-03-12 14:17:55 +08005783 Boolean success = (Boolean) sendRequest(
5784 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005785
5786 if (success) {
5787 Settings.Global.putInt(mApp.getContentResolver(),
5788 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5789 }
calvinpan8ed33732020-03-12 14:17:55 +08005790 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5791 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005794 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005795 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005796
5797 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005798 * Get the allowed network types that store in the telephony provider.
5799 *
5800 * @param subId the id of the subscription.
5801 * @return allowedNetworkTypes the allowed network types.
5802 */
5803 @Override
5804 public long getAllowedNetworkTypes(int subId) {
5805 TelephonyPermissions
5806 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5807 mApp, subId, "getAllowedNetworkTypes");
5808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 return SubscriptionManager.getLongSubscriptionProperty(
5812 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
5816 }
5817
5818 /**
5819 * Set the allowed network types.
5820 *
5821 * @param subId the id of the subscription.
5822 * @param allowedNetworkTypes the allowed network types.
5823 * @return true on success; false on any failure.
5824 */
5825 @Override
5826 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005829
calvinpan8ed33732020-03-12 14:17:55 +08005830 SubscriptionManager.setSubscriptionProperty(subId,
5831 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5832 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005833
calvinpan8ed33732020-03-12 14:17:55 +08005834 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5835 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5836 RILConstants.PREFERRED_NETWORK_MODE);
5837 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005838 }
5839
5840 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005841 * Get the allowed network types for certain reason.
5842 *
5843 * @param subId the id of the subscription.
5844 * @param reason the reason the allowed network type change is taking place
5845 * @return the allowed network types.
5846 */
5847 @Override
5848 public long getAllowedNetworkTypesForReason(int subId,
5849 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5850 TelephonyPermissions
5851 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5852 mApp, subId, "getAllowedNetworkTypesForReason");
5853 final long identity = Binder.clearCallingIdentity();
5854 try {
5855 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005862 * Enable/Disable E-UTRA-NR Dual Connectivity
5863 * @param subId subscription id of the sim card
5864 * @param nrDualConnectivityState expected NR dual connectivity state
5865 * This can be passed following states
5866 * <ol>
5867 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5868 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5869 * <li>Disable NR dual connectivity and force secondary cell to be released
5870 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5871 * </ol>
5872 * @return operation result.
5873 */
5874 @Override
5875 public int setNrDualConnectivityState(int subId,
5876 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, subId, "enableNRDualConnectivity");
5879 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5883 nrDualConnectivityState, subId,
5884 workSource);
5885 if (DBG) log("enableNRDualConnectivity result: " + result);
5886 return result;
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
5891
5892 /**
5893 * Is E-UTRA-NR Dual Connectivity enabled
5894 * @return true if dual connectivity is enabled else false
5895 */
5896 @Override
5897 public boolean isNrDualConnectivityEnabled(int subId) {
5898 TelephonyPermissions
5899 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5900 mApp, subId, "isNRDualConnectivityEnabled");
5901 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5905 null, subId, workSource);
5906 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5907 return isEnabled;
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
5911 }
5912
5913 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07005914 * get carrier bandwidth per primary and secondary carrier
5915 * @param subId subscription id of the sim card
5916 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5917 */
5918 @Override
5919 public CarrierBandwidth getCarrierBandwidth(int subId) {
5920 TelephonyPermissions
5921 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5922 mApp, subId, "isNRDualConnectivityEnabled");
5923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 CarrierBandwidth carrierBandwidth =
5927 getPhoneFromSubId(subId).getCarrierBandwidth();
5928 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5929 return carrierBandwidth;
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
5932 }
5933 }
5934
5935 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005936 * Get the effective allowed network types on the device.
5937 * This API will return an intersection of allowed network types for all reasons,
5938 * including the configuration done through setAllowedNetworkTypes
5939 *
5940 * @param subId the id of the subscription.
5941 * @return the allowed network types
5942 */
5943 @Override
5944 public long getEffectiveAllowedNetworkTypes(int subId) {
5945 TelephonyPermissions
5946 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5947 mApp, subId, "getEffectiveAllowedNetworkTypes");
5948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5951 } finally {
5952 Binder.restoreCallingIdentity(identity);
5953 }
5954 }
5955
5956 /**
5957 * Set the allowed network types of the device and
5958 * provide the reason triggering the allowed network change.
5959 *
5960 * @param subId the id of the subscription.
5961 * @param reason the reason the allowed network type change is taking place
5962 * @param allowedNetworkTypes the allowed network types.
5963 * @return true on success; false on any failure.
5964 */
5965 @Override
5966 public boolean setAllowedNetworkTypesForReason(int subId,
5967 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5969 mApp, subId, "setAllowedNetworkTypesForReason");
5970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5973 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5974 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5975 RILConstants.PREFERRED_NETWORK_MODE);
5976 return setPreferredNetworkType(subId, preferredNetworkMode);
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
5980 }
5981
5982 /**
Miaoa84611c2019-03-15 09:21:10 +08005983 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005984 *
Miaoa84611c2019-03-15 09:21:10 +08005985 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005986 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005987 * @hide
5988 */
5989 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005990 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005993 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 try {
Miaoa84611c2019-03-15 09:21:10 +08005995 if (phone != null) {
5996 return phone.hasMatchedTetherApnSetting();
5997 } else {
5998 return false;
5999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006002 }
Junda Liu475951f2014-11-07 16:45:03 -08006003 }
6004
6005 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006006 * Enable or disable always reporting signal strength changes from radio.
6007 *
6008 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6009 */
6010 @Override
6011 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6012 enforceModifyPermission();
6013 enforceSystemCaller();
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 final Phone phone = getPhone(subId);
6017 try {
6018 if (phone != null) {
6019 if (DBG) {
6020 log("setAlwaysReportSignalStrength: subId=" + subId
6021 + " isEnable=" + isEnable);
6022 }
6023 phone.setAlwaysReportSignalStrength(isEnable);
6024 } else {
6025 loge("setAlwaysReportSignalStrength: no phone found for subId="
6026 + subId);
6027 }
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
6033 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006034 * Get the user enabled state of Mobile Data.
6035 *
6036 * TODO: remove and use isUserDataEnabled.
6037 * This can't be removed now because some vendor codes
6038 * calls through ITelephony directly while they should
6039 * use TelephonyManager.
6040 *
6041 * @return true on enabled
6042 */
6043 @Override
6044 public boolean getDataEnabled(int subId) {
6045 return isUserDataEnabled(subId);
6046 }
6047
6048 /**
6049 * Get whether mobile data is enabled per user setting.
6050 *
6051 * There are other factors deciding whether mobile data is actually enabled, but they are
6052 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006053 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006054 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006055 *
6056 * @return {@code true} if data is enabled else {@code false}
6057 */
6058 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006059 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006060 try {
6061 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6062 null);
6063 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6065 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 int phoneId = mSubscriptionController.getPhoneId(subId);
6071 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6072 Phone phone = PhoneFactory.getPhone(phoneId);
6073 if (phone != null) {
6074 boolean retVal = phone.isUserDataEnabled();
6075 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6076 return retVal;
6077 } else {
6078 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6079 return false;
6080 }
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006083 }
6084 }
6085
6086 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006087 * Checks if the device is capable of mobile data by considering whether whether the
6088 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6089 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006090 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006091 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006092 */
6093 @Override
6094 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006095 try {
6096 try {
6097 mApp.enforceCallingOrSelfPermission(
6098 android.Manifest.permission.ACCESS_NETWORK_STATE,
6099 null);
6100 } catch (Exception e) {
6101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6102 "isDataEnabled");
6103 }
6104 } catch (Exception e) {
6105 enforceReadPrivilegedPermission("isDataEnabled");
6106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 int phoneId = mSubscriptionController.getPhoneId(subId);
6111 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6112 Phone phone = PhoneFactory.getPhone(phoneId);
6113 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006114 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6116 return retVal;
6117 } else {
6118 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6119 return false;
6120 }
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006123 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006124 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006125
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006126 /**
6127 * Check if data is enabled for a specific reason
6128 * @param subId Subscription index
6129 * @param reason the reason the data enable change is taking place
6130 * @return {@code true} if the overall data is enabled; {@code false} if not.
6131 */
6132 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006133 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006134 @TelephonyManager.DataEnabledReason int reason) {
6135 try {
6136 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6137 null);
6138 } catch (Exception e) {
6139 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006140 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006141 }
6142
6143
6144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 int phoneId = mSubscriptionController.getPhoneId(subId);
6147 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006148 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006149 + " reason=" + reason);
6150 }
6151 Phone phone = PhoneFactory.getPhone(phoneId);
6152 if (phone != null) {
6153 boolean retVal;
6154 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6155 retVal = phone.isUserDataEnabled();
6156 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006157 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006158 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006159 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006160 return retVal;
6161 } else {
6162 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006163 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006164 + subId + " retVal=false");
6165 }
6166 return false;
6167 }
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
6171 }
6172
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006173 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006174 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006175 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6176 // Skip the check if it's one of these special uids
6177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6178 }
6179
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006180 //load access rules from carrier configs, and check those as well: b/139133814
6181 SubscriptionController subController = SubscriptionController.getInstance();
6182 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6183 || subController == null) return privilegeFromSim;
6184
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006185 PackageManager pkgMgr = phone.getContext().getPackageManager();
6186 String[] packages = pkgMgr.getPackagesForUid(uid);
6187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006190 int subId = phone.getSubId();
6191 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6192 // A test override is in place for the privileges for this subId, so don't try to
6193 // read the subscription privileges.
6194 return privilegeFromSim;
6195 }
6196 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006197 SubscriptionManager subManager = (SubscriptionManager)
6198 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6199 for (String pkg : packages) {
6200 if (subManager.canManageSubscription(subInfo, pkg)) {
6201 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6202 }
6203 }
6204 return privilegeFromSim;
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
6208 }
6209
6210 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6211 String pkgName) {
6212 //load access rules from carrier configs, and check those as well: b/139133814
6213 SubscriptionController subController = SubscriptionController.getInstance();
6214 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6215 || subController == null) return privilegeFromSim;
6216
6217 final long identity = Binder.clearCallingIdentity();
6218 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006219 int subId = phone.getSubId();
6220 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6221 // A test override is in place for the privileges for this subId, so don't try to
6222 // read the subscription privileges.
6223 return privilegeFromSim;
6224 }
6225 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006226 SubscriptionManager subManager = (SubscriptionManager)
6227 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6228 return subManager.canManageSubscription(subInfo, pkgName)
6229 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006235 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006236 public int getCarrierPrivilegeStatus(int subId) {
6237 final Phone phone = getPhone(subId);
6238 if (phone == null) {
6239 loge("getCarrierPrivilegeStatus: Invalid subId");
6240 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6241 }
6242 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006243 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006244 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006245 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6246 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006247
6248 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6249 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006250 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006251 }
Junda Liu29340342014-07-10 15:23:27 -07006252
6253 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006255 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006256 final Phone phone = getPhone(subId);
6257 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006258 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006259 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6260 }
6261 UiccProfile profile =
6262 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6263 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006264 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006265 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6266 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006267 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006268 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006269 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006270 }
6271
6272 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006273 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6274 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006275 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006276 }
6277
6278 int phoneId = SubscriptionManager.getPhoneId(subId);
6279 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006280 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006281 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006282 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6283 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006284 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6285 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6286 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006287 }
6288
6289 @Override
6290 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006291 if (TextUtils.isEmpty(pkgName))
6292 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006293 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6294 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6295 UiccCard card = UiccController.getInstance().getUiccCard(i);
6296 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006297 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006298 continue;
6299 }
6300
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006301 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6302 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6303 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006304 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6305 break;
6306 }
6307 }
6308
6309 return result;
Junda Liu29340342014-07-10 15:23:27 -07006310 }
Derek Tan89e89d42014-07-08 17:00:10 -07006311
6312 @Override
Junda Liue64de782015-04-16 17:19:16 -07006313 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6314 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6315 loge("phoneId " + phoneId + " is not valid.");
6316 return null;
6317 }
6318 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006319 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006320 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006321 return null ;
6322 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006323 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006324 }
6325
Amith Yamasani6e118872016-02-19 12:53:51 -08006326 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006327 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006328 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006329 List<String> privilegedPackages = new ArrayList<>();
6330 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006331 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6332 // has UICC in that slot.
6333 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006334 if (card.hasCarrierPrivilegeRules()) {
6335 if (packages == null) {
6336 // Only check packages in user 0 for now
6337 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006338 PackageManager.MATCH_DISABLED_COMPONENTS
6339 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006340 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006341 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006342 }
6343 for (int p = packages.size() - 1; p >= 0; p--) {
6344 PackageInfo pkgInfo = packages.get(p);
6345 if (pkgInfo != null && pkgInfo.packageName != null
6346 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006347 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006348 privilegedPackages.add(pkgInfo.packageName);
6349 }
6350 }
6351 }
6352 }
6353 return privilegedPackages;
6354 }
6355
chen xuf7e9fe82019-05-09 19:31:02 -07006356 @Override
6357 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006358 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6359
6360 final long identity = Binder.clearCallingIdentity();
6361
chen xuf7e9fe82019-05-09 19:31:02 -07006362 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006363 try {
6364 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6365 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6366 }
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006369 }
6370 return privilegedPackages;
6371 }
6372
Wink Savilleb564aae2014-10-23 10:18:09 -07006373 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006374 final Phone phone = getPhone(subId);
6375 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006376 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006377 return null;
6378 }
6379 String iccId = card.getIccId();
6380 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006381 return null;
6382 }
6383 return iccId;
6384 }
6385
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006386 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006387 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6388 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006389 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006390 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 final long identity = Binder.clearCallingIdentity();
6393 try {
6394 final String iccId = getIccId(subId);
6395 final Phone phone = getPhone(subId);
6396 if (phone == null) {
6397 return false;
6398 }
6399 final String subscriberId = phone.getSubscriberId();
6400
6401 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006402 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 + subscriberId + " to " + number);
6404 }
6405
6406 if (TextUtils.isEmpty(iccId)) {
6407 return false;
6408 }
6409
6410 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6411
6412 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6413 if (alphaTag == null) {
6414 editor.remove(alphaTagPrefKey);
6415 } else {
6416 editor.putString(alphaTagPrefKey, alphaTag);
6417 }
6418
6419 // Record both the line number and IMSI for this ICCID, since we need to
6420 // track all merged IMSIs based on line number
6421 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6422 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6423 if (number == null) {
6424 editor.remove(numberPrefKey);
6425 editor.remove(subscriberPrefKey);
6426 } else {
6427 editor.putString(numberPrefKey, number);
6428 editor.putString(subscriberPrefKey, subscriberId);
6429 }
6430
6431 editor.commit();
6432 return true;
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006435 }
Derek Tan7226c842014-07-02 17:42:23 -07006436 }
6437
6438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006439 public String getLine1NumberForDisplay(int subId, String callingPackage,
6440 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006441 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006443 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006444 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006445 return null;
6446 }
Derek Tan97ebb422014-09-05 16:55:38 -07006447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 String iccId = getIccId(subId);
6451 if (iccId != null) {
6452 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6453 if (DBG_MERGE) {
6454 log("getLine1NumberForDisplay returning "
6455 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6456 }
6457 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6460 return null;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006463 }
Derek Tan7226c842014-07-02 17:42:23 -07006464 }
6465
6466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006467 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6468 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006470 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006471 return null;
6472 }
Derek Tan97ebb422014-09-05 16:55:38 -07006473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 String iccId = getIccId(subId);
6477 if (iccId != null) {
6478 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6479 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6480 }
6481 return null;
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006484 }
Derek Tan7226c842014-07-02 17:42:23 -07006485 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006486
6487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006488 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6489 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006490 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6491 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006493 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006494 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006495 return null;
6496 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006497
Jordan Liub49b04b2019-05-06 14:45:15 -07006498 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6499 // the process, where TelephonyManager was instantiated.
6500 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006501 final long identity = Binder.clearCallingIdentity();
6502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 final TelephonyManager tele = TelephonyManager.from(context);
6505 final SubscriptionManager sub = SubscriptionManager.from(context);
6506
6507 // Figure out what subscribers are currently active
6508 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509
Jordan Liub49b04b2019-05-06 14:45:15 -07006510 // Only consider subs which match the current subId
6511 // This logic can be simplified. See b/131189269 for progress.
6512 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006513 activeSubscriberIds.add(tele.getSubscriberId(subId));
6514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515
6516 // First pass, find a number override for an active subscriber
6517 String mergeNumber = null;
6518 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6519 for (String key : prefs.keySet()) {
6520 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6521 final String subscriberId = (String) prefs.get(key);
6522 if (activeSubscriberIds.contains(subscriberId)) {
6523 final String iccId = key.substring(
6524 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6525 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6526 mergeNumber = (String) prefs.get(numberKey);
6527 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006528 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 + " for active subscriber " + subscriberId);
6530 }
6531 if (!TextUtils.isEmpty(mergeNumber)) {
6532 break;
6533 }
6534 }
6535 }
6536 }
6537
6538 // Shortcut when no active merged subscribers
6539 if (TextUtils.isEmpty(mergeNumber)) {
6540 return null;
6541 }
6542
6543 // Second pass, find all subscribers under that line override
6544 final ArraySet<String> result = new ArraySet<>();
6545 for (String key : prefs.keySet()) {
6546 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6547 final String number = (String) prefs.get(key);
6548 if (mergeNumber.equals(number)) {
6549 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6550 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6551 final String subscriberId = (String) prefs.get(subscriberKey);
6552 if (!TextUtils.isEmpty(subscriberId)) {
6553 result.add(subscriberId);
6554 }
6555 }
6556 }
6557 }
6558
6559 final String[] resultArray = result.toArray(new String[result.size()]);
6560 Arrays.sort(resultArray);
6561 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006562 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6564 }
6565 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006568 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006569 }
6570
6571 @Override
zoey chen38003472019-12-13 17:16:31 +08006572 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6573 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 final TelephonyManager telephonyManager = mApp.getSystemService(
6578 TelephonyManager.class);
6579 String subscriberId = telephonyManager.getSubscriberId(subId);
6580 if (subscriberId == null) {
6581 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006582 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006583 + subId);
6584 }
6585 return null;
6586 }
6587
6588 final SubscriptionInfo info = SubscriptionController.getInstance()
6589 .getSubscriptionInfo(subId);
6590 final ParcelUuid groupUuid = info.getGroupUuid();
6591 // If it doesn't belong to any group, return just subscriberId of itself.
6592 if (groupUuid == null) {
6593 return new String[]{subscriberId};
6594 }
6595
6596 // Get all subscriberIds from the group.
6597 final List<String> mergedSubscriberIds = new ArrayList<>();
6598 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006599 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006600 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006601 for (SubscriptionInfo subInfo : groupInfos) {
6602 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6603 if (subscriberId != null) {
6604 mergedSubscriberIds.add(subscriberId);
6605 }
6606 }
6607
6608 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611
6612 }
6613 }
6614
6615 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006616 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006617 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006618 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 final Phone phone = getPhone(subId);
6623 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006627 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006628
6629 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006630 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006631 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6632 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006633 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6634 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 final Phone phone = getPhone(subId);
6639 if (phone == null) {
6640 return false;
6641 }
6642 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6643 cdmaNonRoamingList);
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006646 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006647 }
6648
6649 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006650 @Deprecated
6651 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6652 enforceModifyPermission();
6653
6654 int returnValue = 0;
6655 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006656 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006657 if(result.exception == null) {
6658 if (result.result != null) {
6659 byte[] responseData = (byte[])(result.result);
6660 if(responseData.length > oemResp.length) {
6661 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6662 responseData.length + "bytes. Buffer Size is " +
6663 oemResp.length + "bytes.");
6664 }
6665 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6666 returnValue = responseData.length;
6667 }
6668 } else {
6669 CommandException ex = (CommandException) result.exception;
6670 returnValue = ex.getCommandError().ordinal();
6671 if(returnValue > 0) returnValue *= -1;
6672 }
6673 } catch (RuntimeException e) {
6674 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6675 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6676 if(returnValue > 0) returnValue *= -1;
6677 }
6678
6679 return returnValue;
6680 }
6681
6682 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006683 public void setRadioCapability(RadioAccessFamily[] rafs) {
6684 try {
6685 ProxyController.getInstance().setRadioCapability(rafs);
6686 } catch (RuntimeException e) {
6687 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6688 }
6689 }
6690
6691 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006692 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006693 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006694 try {
6695 TelephonyPermissions
6696 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6697 mApp, phone.getSubId(), "getRadioAccessFamily");
6698 } catch (SecurityException e) {
6699 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6700 throw e;
6701 }
chen xub97461a2018-10-26 14:17:57 -07006702 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006703 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006704 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
chen xub97461a2018-10-26 14:17:57 -07006708 TelephonyPermissions
6709 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6710 mApp, phone.getSubId(), "getRadioAccessFamily");
6711 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
chen xub97461a2018-10-26 14:17:57 -07006715 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006716 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006717
6718 @Override
6719 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006720 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006725 ImsManager.getInstance(defaultPhone.getContext(),
6726 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006730 }
6731
6732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006733 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6736 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006737 return false;
6738 }
Svet Ganovb320e182015-04-16 12:30:10 -07006739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 // Check the user preference and the system-level IMS setting. Even if the user has
6743 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6744 // In the long run, we may instead need to check if there exists a connection service
6745 // which can support video calling.
6746 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006747 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 return imsManager.isVtEnabledByPlatform()
6749 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6750 && imsManager.isVtEnabledByUser();
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006754 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006755
Andrew Leea1239f22015-03-02 17:44:07 -08006756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006757 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6758 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006760 mApp, subId, callingPackage, callingFeatureId,
6761 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 return false;
6763 }
6764
6765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 CarrierConfigManager configManager =
6768 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006769 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
Andrew Leea1239f22015-03-02 17:44:07 -08006774 }
6775
6776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006777 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006779 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 return false;
6781 }
6782
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 CarrierConfigManager configManager =
6786 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006787 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
Andrew Leea1239f22015-03-02 17:44:07 -08006792 }
6793
Andrew Lee9431b832015-03-09 18:46:45 -07006794 @Override
6795 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006796 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006797 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006798 }
6799
6800 @Override
6801 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 final long identity = Binder.clearCallingIdentity();
6803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006804 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
Andrew Lee9431b832015-03-09 18:46:45 -07006808 }
6809
Hall Liuf6668912018-10-31 17:05:23 -07006810 /**
6811 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6812 * support for the feature and device firmware support.
6813 *
6814 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6815 */
6816 @Override
6817 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006819 final Phone phone = getPhone(subscriptionId);
6820 if (phone == null) {
6821 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6822 return false;
6823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6827 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006828 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 return isCarrierSupported && isDeviceSupported;
6830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
Hall Liu98187582018-01-22 19:15:32 -08006833 }
6834
Hall Liuf6668912018-10-31 17:05:23 -07006835 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006836 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6837 * RTT setting, will return true if the device and carrier both support RTT.
6838 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006839 */
6840 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006843 boolean isRttSupported = isRttSupported(subscriptionId);
6844 boolean isUserRttSettingOn = Settings.Secure.getInt(
6845 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6846 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6847 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6848 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849 } finally {
6850 Binder.restoreCallingIdentity(identity);
6851 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006852 }
6853
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006854 @Deprecated
6855 @Override
6856 public String getDeviceId(String callingPackage) {
6857 return getDeviceIdWithFeature(callingPackage, null);
6858 }
6859
Sanket Padawe7310cc72015-01-14 09:53:20 -08006860 /**
6861 * Returns the unique device ID of phone, for example, the IMEI for
6862 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6863 *
6864 * <p>Requires Permission:
6865 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6866 */
6867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006868 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006869 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006870 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006871 return null;
6872 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006873 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006874 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006875 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006876 return null;
6877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878
6879 final long identity = Binder.clearCallingIdentity();
6880 try {
6881 return phone.getDeviceId();
6882 } finally {
6883 Binder.restoreCallingIdentity(identity);
6884 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006885 }
6886
Ping Sunc67b7c22016-03-02 19:16:45 +08006887 /**
6888 * {@hide}
6889 * Returns the IMS Registration Status on a particular subid
6890 *
6891 * @param subId
6892 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006893 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006894 Phone phone = getPhone(subId);
6895 if (phone != null) {
6896 return phone.isImsRegistered();
6897 } else {
6898 return false;
6899 }
6900 }
6901
Santos Cordon7a1885b2015-02-03 11:15:19 -08006902 @Override
6903 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6907 } finally {
6908 Binder.restoreCallingIdentity(identity);
6909 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006910 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006911
Tyler Gunnf70ed162019-04-03 15:28:53 -07006912 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006913 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006914 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006916 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006917 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6918 }
6919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006928 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006929 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6930 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 Phone phone = getPhone(subscriptionId);
6934 if (phone == null) {
6935 return null;
6936 }
6937 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006943 /**
6944 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006945 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006946 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 Phone phone = getPhone(subId);
6950 if (phone != null) {
6951 return phone.isWifiCallingEnabled();
6952 } else {
6953 return false;
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006957 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006958 }
6959
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006960 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006961 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006962 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006963 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 Phone phone = getPhone(subId);
6967 if (phone != null) {
6968 return phone.isVideoEnabled();
6969 } else {
6970 return false;
6971 }
6972 } finally {
6973 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006974 }
6975 }
6976
6977 /**
6978 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6979 * defined in {@link ImsRegistrationImplBase}.
6980 */
6981 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 Phone phone = getPhone(subId);
6985 if (phone != null) {
6986 return phone.getImsRegistrationTech();
6987 } else {
6988 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6989 }
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006992 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006993 }
6994
Stuart Scott8eef64f2015-04-08 15:13:54 -07006995 @Override
6996 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006997 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006998 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6999 return;
7000 }
7001
Svet Ganovcc087f82015-05-12 20:35:54 -07007002 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007003
Svet Ganovcc087f82015-05-12 20:35:54 -07007004 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007005 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7006 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007007 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007008 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007009 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007010 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7012 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007013 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007014 // There has been issues when Sms raw table somehow stores orphan
7015 // fragments. They lead to garbled message when new fragments come
7016 // in and combined with those stale ones. In case this happens again,
7017 // user can reset all network settings which will clean up this table.
7018 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007019 // Clean up IMS settings as well here.
7020 int slotId = getSlotIndex(subId);
7021 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7022 ImsManager.getInstance(mApp, slotId).factoryReset();
7023 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007024
7025 // Erase modem config if erase modem on network setting is enabled.
7026 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7027 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7028 if (configValue != null && Boolean.parseBoolean(configValue)) {
7029 sendEraseModemConfig(getDefaultPhone());
7030 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007033 }
7034 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007035
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007036 private void cleanUpSmsRawTable(Context context) {
7037 ContentResolver resolver = context.getContentResolver();
7038 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7039 resolver.delete(uri, null, null);
7040 }
7041
Narayan Kamath1c496c22015-04-16 14:40:19 +01007042 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007043 public String getSimLocaleForSubscriber(int subId) {
7044 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7045 final Phone phone = getPhone(subId);
7046 if (phone == null) {
7047 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007048 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 final long identity = Binder.clearCallingIdentity();
7051 try {
chen xu5d3637b2019-01-21 23:31:38 -08007052 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007053 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007054 if (info == null) {
7055 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7056 return null;
7057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 // Try and fetch the locale from the carrier properties or from the SIM language
7059 // preferences (EF-PL and EF-LI)...
7060 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007062 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7063 if (localeFromDefaultSim != null) {
7064 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7065 if (DBG) log("Using locale from subId: " + subId + " locale: "
7066 + localeFromDefaultSim);
7067 return localeFromDefaultSim.toLanguageTag();
7068 } else {
7069 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 }
7071 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 // The SIM language preferences only store a language (e.g. fr = French), not an
7074 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7075 // the SIM and carrier preferences does not include a country we add the country
7076 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007077 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007079 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 return mccLocale.toLanguageTag();
7081 }
7082
7083 if (DBG) log("No locale found - returning null");
7084 return null;
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007088 }
7089
7090 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007092 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007093 }
7094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 /**
7096 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7097 */
7098 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007100 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007101 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007102
Chenjie Yu1ba97252018-01-11 18:16:20 -08007103 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007104 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007105
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007106 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007107 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7108 * representing the state of the modem.
7109 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007110 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7111 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007112 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007113 */
7114 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007115 public void requestModemActivityInfo(ResultReceiver result) {
7116 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007121 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007124 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007125 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007126
Siddharth Rayb8114062018-06-17 15:02:38 -07007127 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7128 // less than total activity duration.
7129 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7130 if (info == null) {
7131 return false;
7132 }
7133 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007134 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7135 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7136
Siddharth Rayb8114062018-06-17 15:02:38 -07007137 return (info.isValid()
7138 && (info.getSleepTimeMillis() <= activityDurationMs)
7139 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007140 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007141 && (totalTxTimeMs <= activityDurationMs));
7142 }
7143
Jack Yu85bd38a2015-11-09 11:34:32 -08007144 /**
7145 * {@hide}
7146 * Returns the service state information on specified subscription.
7147 */
7148 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007149 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7150 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007152 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007153 return null;
7154 }
7155
Hall Liuf19c44f2018-11-27 14:38:17 -08007156 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7157 LocationAccessPolicy.checkLocationPermission(mApp,
7158 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7159 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007160 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007161 .setCallingPid(Binder.getCallingPid())
7162 .setCallingUid(Binder.getCallingUid())
7163 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007164 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007165 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007166 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7167 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007168 .build());
7169
7170 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7171 LocationAccessPolicy.checkLocationPermission(mApp,
7172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007175 .setCallingPid(Binder.getCallingPid())
7176 .setCallingUid(Binder.getCallingUid())
7177 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007178 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007179 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007180 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7181 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007182 .build());
7183 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7184 boolean hasFinePermission =
7185 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7186 boolean hasCoarsePermission =
7187 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7188
Jack Yu479f40e2020-10-27 21:29:25 -07007189 final Phone phone = getPhone(subId);
7190 if (phone == null) {
7191 return null;
7192 }
7193
7194 boolean isCallingPackageDataService = phone.getDataServicePackages()
7195 .contains(callingPackage);
7196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007199 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7200 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7201 Rlog.d(LOG_TAG,
7202 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7203 return null;
7204 }
7205
Hall Liuf19c44f2018-11-27 14:38:17 -08007206 ServiceState ss = phone.getServiceState();
7207
7208 // Scrub out the location info in ServiceState depending on what level of access
7209 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007210 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007211 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7212 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007216 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007217
7218 /**
7219 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7220 *
7221 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7222 * voicemail ringtone.
7223 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7224 * PhoneAccount.
7225 */
7226 @Override
7227 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7231 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007232 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007239 }
7240
7241 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007242 * Sets the per-account voicemail ringtone.
7243 *
7244 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7245 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7246 *
7247 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7248 * voicemail ringtone.
7249 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7250 * PhoneAccount.
7251 */
7252 @Override
7253 public void setVoicemailRingtoneUri(String callingPackage,
7254 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007255 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007257 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7258 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7260 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7261 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263
7264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7267 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007268 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 }
7270 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007273 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007274 }
7275
7276 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007277 * Returns whether vibration is set for voicemail notification in Phone settings.
7278 *
7279 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7280 * voicemail vibration setting.
7281 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7282 */
7283 @Override
7284 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7288 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007289 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007292 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007296 }
7297
Youhan Wange64578a2016-05-02 15:32:42 -07007298 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007299 * Sets the per-account voicemail vibration.
7300 *
7301 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7302 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7303 *
7304 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7305 * voicemail vibration setting.
7306 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7307 * specific PhoneAccount.
7308 */
7309 @Override
7310 public void setVoicemailVibrationEnabled(String callingPackage,
7311 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007314 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7315 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7317 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7318 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007319 }
7320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
7323 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7324 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007325 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 }
7327 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007330 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007331 }
7332
7333 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007334 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7335 *
7336 * @throws SecurityException if the caller does not have the required permission
7337 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007338 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007340 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007341 }
7342
7343 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007344 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7345 * permission.
7346 *
7347 * @throws SecurityException if the caller does not have the required permission
7348 */
7349 private void enforceSendSmsPermission() {
7350 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7351 }
7352
7353 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007354 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007355 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007356 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007357 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007358 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 final long identity = Binder.clearCallingIdentity();
7360 try {
7361 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007362 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 if (componentName == null) {
7364 throw new SecurityException(
7365 "Caller not current active visual voicemail package[null]");
7366 }
7367 String vvmPackage = componentName.getPackageName();
7368 if (!callingPackage.equals(vvmPackage)) {
7369 throw new SecurityException("Caller not current active visual voicemail package["
7370 + vvmPackage + "]");
7371 }
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007374 }
7375 }
7376
7377 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007378 * Return the application ID for the app type.
7379 *
7380 * @param subId the subscription ID that this request applies to.
7381 * @param appType the uicc app type.
7382 * @return Application ID for specificied app type, or null if no uicc.
7383 */
7384 @Override
7385 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007386 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007387 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388
7389 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007390 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 if (phone == null) {
7392 return null;
7393 }
7394 String aid = null;
7395 try {
7396 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7397 .getApplicationByType(appType).getAid();
7398 } catch (Exception e) {
7399 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7400 }
7401 return aid;
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007404 }
Youhan Wange64578a2016-05-02 15:32:42 -07007405 }
7406
Youhan Wang4001d252016-05-11 10:29:41 -07007407 /**
7408 * Return the Electronic Serial Number.
7409 *
7410 * @param subId the subscription ID that this request applies to.
7411 * @return ESN or null if error.
7412 */
7413 @Override
7414 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007415 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007416 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417
7418 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007419 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 if (phone == null) {
7421 return null;
7422 }
7423 String esn = null;
7424 try {
7425 esn = phone.getEsn();
7426 } catch (Exception e) {
7427 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7428 }
7429 return esn;
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007432 }
Youhan Wang4001d252016-05-11 10:29:41 -07007433 }
7434
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007435 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007436 * Return the Preferred Roaming List Version.
7437 *
7438 * @param subId the subscription ID that this request applies to.
7439 * @return PRLVersion or null if error.
7440 */
7441 @Override
7442 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007443 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007444 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445
7446 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007447 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 if (phone == null) {
7449 return null;
7450 }
7451 String cdmaPrlVersion = null;
7452 try {
7453 cdmaPrlVersion = phone.getCdmaPrlVersion();
7454 } catch (Exception e) {
7455 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7456 }
7457 return cdmaPrlVersion;
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007460 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007461 }
7462
7463 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007464 * Get snapshot of Telephony histograms
7465 * @return List of Telephony histograms
7466 * @hide
7467 */
7468 @Override
7469 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7471 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
7475 return RIL.getTelephonyRILTimingHistograms();
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007479 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007480
7481 /**
7482 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007483 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7484 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007485 * Require system privileges. In the future we may add this to carrier APIs.
7486 *
Michele Berionne482f8202018-11-27 18:57:59 -08007487 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007488 */
7489 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007490 @TelephonyManager.SetCarrierRestrictionResult
7491 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007492 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007494
Michele Berionne482f8202018-11-27 18:57:59 -08007495 if (carrierRestrictionRules == null) {
7496 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007497 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007501 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007502 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007506 }
7507
7508 /**
7509 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007510 * Get the allowed carrier list and the excluded carrier list, including the priority between
7511 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007512 * Require system privileges. In the future we may add this to carrier APIs.
7513 *
Michele Berionne482f8202018-11-27 18:57:59 -08007514 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007515 */
7516 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007517 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007518 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007523 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7524 if (response instanceof CarrierRestrictionRules) {
7525 return (CarrierRestrictionRules) response;
7526 }
7527 // Response is an Exception of some kind,
7528 // which is signalled to the user as a NULL retval
7529 return null;
7530 } catch (Exception e) {
7531 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7532 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007536 }
7537
fionaxu59545b42016-05-25 15:53:37 -07007538 /**
fionaxu59545b42016-05-25 15:53:37 -07007539 * Action set from carrier signalling broadcast receivers to enable/disable radio
7540 * @param subId the subscription ID that this action applies to.
7541 * @param enabled control enable or disable radio.
7542 * {@hide}
7543 */
7544 @Override
7545 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7546 enforceModifyPermission();
7547 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548
7549 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007550 if (phone == null) {
7551 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7552 return;
7553 }
7554 try {
7555 phone.carrierActionSetRadioEnabled(enabled);
7556 } catch (Exception e) {
7557 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 } finally {
7559 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007560 }
7561 }
7562
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007563 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007564 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7565 * network status based on which carrier apps could apply actions accordingly,
7566 * enable/disable default url handler for example.
7567 *
7568 * @param subId the subscription ID that this action applies to.
7569 * @param report control start/stop reporting the default network status.
7570 * {@hide}
7571 */
7572 @Override
7573 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7574 enforceModifyPermission();
7575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576
7577 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007578 if (phone == null) {
7579 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7580 return;
7581 }
7582 try {
7583 phone.carrierActionReportDefaultNetworkStatus(report);
7584 } catch (Exception e) {
7585 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 } finally {
7587 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007588 }
7589 }
7590
7591 /**
fionaxud9622282017-07-17 17:51:30 -07007592 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7593 * @param subId the subscription ID that this action applies to.
7594 * {@hide}
7595 */
7596 @Override
7597 public void carrierActionResetAll(int subId) {
7598 enforceModifyPermission();
7599 final Phone phone = getPhone(subId);
7600 if (phone == null) {
7601 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7602 return;
7603 }
7604 try {
7605 phone.carrierActionResetAll();
7606 } catch (Exception e) {
7607 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7608 }
7609 }
7610
7611 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007612 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7613 * bug report is being generated.
7614 */
7615 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007616 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007617 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7618 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007619 writer.println("Permission Denial: can't dump Phone from pid="
7620 + Binder.getCallingPid()
7621 + ", uid=" + Binder.getCallingUid()
7622 + "without permission "
7623 + android.Manifest.permission.DUMP);
7624 return;
7625 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007626 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007627 }
Jack Yueb89b242016-06-22 13:27:47 -07007628
Brad Ebingerdac2f002018-04-03 15:17:52 -07007629 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007630 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7631 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7632 @NonNull String[] args) {
7633 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7634 this, in.getFileDescriptor(), out.getFileDescriptor(),
7635 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007636 }
7637
Jack Yueb89b242016-06-22 13:27:47 -07007638 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007639 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007640 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007641 * @param reason the reason the data enable change is taking place
7642 * @param enabled True if enabling the data, otherwise disabling.
7643 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007644 */
7645 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007646 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007647 boolean enabled) {
7648 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7649 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7650 try {
7651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007652 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007653 } catch (SecurityException se) {
7654 enforceModifyPermission();
7655 }
7656 } else {
7657 enforceModifyPermission();
7658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659
7660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 Phone phone = getPhone(subId);
7663 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007664 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7665 phone.carrierActionSetMeteredApnsEnabled(enabled);
7666 } else {
7667 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 }
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007672 }
7673 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007674
7675 /**
7676 * Get Client request stats
7677 * @return List of Client Request Stats
7678 * @hide
7679 */
7680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007681 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7682 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007684 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007685 return null;
7686 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007687 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 if (phone != null) {
7692 return phone.getClientRequestStats();
7693 }
7694
7695 return null;
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007699 }
7700
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007701 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007702 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007703 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007704 }
Jack Yueb4124c2017-02-16 15:32:43 -08007705
7706 /**
Grace Chen70990072017-03-24 17:21:30 -07007707 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007708 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007709 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007710 * @param state State of SIM (power down, power up, pass through)
7711 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7712 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7713 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007714 *
7715 **/
7716 @Override
Grace Chen70990072017-03-24 17:21:30 -07007717 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007718 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007719 Phone phone = PhoneFactory.getPhone(slotIndex);
7720
vagdeviaf9a5b92018-08-15 16:01:53 -07007721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007726 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 }
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007730 }
7731 }
Shuo Qiandd210312017-04-12 22:11:33 +00007732
Tyler Gunn65d45c22017-06-05 11:22:26 -07007733 private boolean isUssdApiAllowed(int subId) {
7734 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007735 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007736 if (configManager == null) {
7737 return false;
7738 }
7739 PersistableBundle pb = configManager.getConfigForSubId(subId);
7740 if (pb == null) {
7741 return false;
7742 }
7743 return pb.getBoolean(
7744 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7745 }
7746
Shuo Qiandd210312017-04-12 22:11:33 +00007747 /**
7748 * Check if phone is in emergency callback mode
7749 * @return true if phone is in emergency callback mode
7750 * @param subId sub id
7751 */
goneil9c5f4872017-12-05 14:07:56 -08007752 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007753 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007754 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007755 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 if (phone != null) {
7760 return phone.isInEcm();
7761 } else {
7762 return false;
7763 }
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007766 }
7767 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007768
7769 /**
7770 * Get the current signal strength information for the given subscription.
7771 * Because this information is not updated when the device is in a low power state
7772 * it should not be relied-upon to be current.
7773 * @param subId Subscription index
7774 * @return the most recent cached signal strength info from the modem
7775 */
7776 @Override
7777 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 Phone p = getPhone(subId);
7781 if (p == null) {
7782 return null;
7783 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 return p.getSignalStrength();
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007789 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007790
Pengquan Meng77b7f132018-08-22 14:49:57 -07007791 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007792 * Get the current modem radio state for the given slot.
7793 * @param slotIndex slot index.
7794 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007795 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007796 * @return the current radio power state from the modem
7797 */
7798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007800 Phone phone = PhoneFactory.getPhone(slotIndex);
7801 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7803 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007804 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7805 }
7806
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
7809 return phone.getRadioPowerState();
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
7812 }
7813 }
7814 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7815 }
7816
7817 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007818 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7819 *
7820 * <p>Requires one of the following permissions:
7821 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7822 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7823 * privileges.
7824 *
7825 * @param subId subscription id
7826 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7827 * {@code false}.
7828 */
7829 @Override
7830 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007831 try {
7832 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7833 null);
7834 } catch (Exception e) {
7835 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7836 mApp, subId, "isDataRoamingEnabled");
7837 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007838
Pengquan Menga1bb6272018-09-06 09:59:22 -07007839 boolean isEnabled = false;
7840 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007841 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007842 Phone phone = getPhone(subId);
7843 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007844 } finally {
7845 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007846 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007847 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007848 }
7849
7850
7851 /**
7852 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7853 *
7854 * <p> Requires permission:
7855 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7856 * privileges.
7857 *
7858 * @param subId subscription id
7859 * @param isEnabled {@code true} means enable, {@code false} means disable.
7860 */
7861 @Override
7862 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7864 mApp, subId, "setDataRoamingEnabled");
7865
Pengquan Menga1bb6272018-09-06 09:59:22 -07007866 final long identity = Binder.clearCallingIdentity();
7867 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007868 Phone phone = getPhone(subId);
7869 if (phone != null) {
7870 phone.setDataRoamingEnabled(isEnabled);
7871 }
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007874 }
7875 }
7876
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007877 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007878 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007879 TelephonyPermissions
7880 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007881 mApp, subId, "isManualNetworkSelectionAllowed");
7882
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007883 boolean isAllowed = true;
7884 final long identity = Binder.clearCallingIdentity();
7885 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007886 Phone phone = getPhone(subId);
7887 if (phone != null) {
7888 isAllowed = phone.isCspPlmnEnabled();
7889 }
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 return isAllowed;
7894 }
7895
7896 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007897 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007898 // Verify that tha callingPackage belongs to the calling UID
7899 mApp.getSystemService(AppOpsManager.class)
7900 .checkPackage(Binder.getCallingUid(), callingPackage);
7901
Jordan Liu1e142fc2019-04-22 15:10:43 -07007902 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007903 try {
7904 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007905 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007906 } catch (SecurityException e) {
7907 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7908 // has carrier privileges on an active UICC
7909 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7910 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007911 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007912 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007913 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007914
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007917 UiccController uiccController = UiccController.getInstance();
7918 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007919 if (hasReadPermission) {
7920 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007921 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007922
7923 // Remove private info if the caller doesn't have access
7924 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7925 for (UiccCardInfo cardInfo : cardInfos) {
7926 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7927 // is available
7928 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7929 if (card == null || card.getUiccProfile() == null) {
7930 // assume no access if the card or profile is unavailable
7931 filteredInfos.add(cardInfo.getUnprivileged());
7932 continue;
7933 }
7934 UiccProfile profile = card.getUiccProfile();
7935 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7936 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7937 filteredInfos.add(cardInfo);
7938 } else {
7939 filteredInfos.add(cardInfo.getUnprivileged());
7940 }
7941 }
7942 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007943 } finally {
7944 Binder.restoreCallingIdentity(identity);
7945 }
7946 }
7947
7948 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007949 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007950 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7955 if (slots == null) {
7956 Rlog.i(LOG_TAG, "slots is null.");
7957 return null;
7958 }
7959
7960 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7961 for (int i = 0; i < slots.length; i++) {
7962 UiccSlot slot = slots[i];
7963 if (slot == null) {
7964 continue;
7965 }
7966
Jordan Liu7be7e652019-05-06 18:55:02 +00007967 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 UiccCard card = slot.getUiccCard();
7969 if (card != null) {
7970 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007971 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007972 cardId = slot.getEid();
7973 if (TextUtils.isEmpty(cardId)) {
7974 cardId = slot.getIccId();
7975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 }
7977
Jordan Liu857451f2019-05-09 16:35:35 -07007978 if (cardId != null) {
7979 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7980 // if cardId is an EID, it's all digits so this is fine
7981 cardId = IccUtils.stripTrailingFs(cardId);
7982 }
7983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 int cardState = 0;
7985 switch (slot.getCardState()) {
7986 case CARDSTATE_ABSENT:
7987 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7988 break;
7989 case CARDSTATE_PRESENT:
7990 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7991 break;
7992 case CARDSTATE_ERROR:
7993 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7994 break;
7995 case CARDSTATE_RESTRICTED:
7996 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7997 break;
7998 default:
7999 break;
8000
8001 }
8002
8003 infos[i] = new UiccSlotInfo(
8004 slot.isActive(),
8005 slot.isEuicc(),
8006 cardId,
8007 cardState,
8008 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008009 slot.isExtendedApduSupported(),
8010 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 }
8012 return infos;
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008016 }
8017
8018 @Override
8019 public boolean switchSlots(int[] physicalSlots) {
8020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021
8022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008028 }
Jack Yu4c988042018-02-27 15:30:01 -08008029
8030 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008031 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 return UiccController.getInstance().getCardIdForDefaultEuicc();
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
8038 }
8039
Pengquan Meng85728fb2018-03-12 16:31:21 -07008040 /**
goneil47ffb6e2018-04-06 15:40:58 -07008041 * A test API to reload the UICC profile.
8042 *
8043 * <p>Requires that the calling app has permission
8044 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8045 * @hide
8046 */
8047 @Override
8048 public void refreshUiccProfile(int subId) {
8049 enforceModifyPermission();
8050
8051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 Phone phone = getPhone(subId);
8054 if (phone == null) {
8055 return;
8056 }
8057 UiccCard uiccCard = phone.getUiccCard();
8058 if (uiccCard == null) {
8059 return;
8060 }
8061 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8062 if (uiccProfile == null) {
8063 return;
8064 }
8065 uiccProfile.refresh();
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
8069 }
8070
8071 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008072 * Returns false if the mobile data is disabled by default, otherwise return true.
8073 */
8074 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008075 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008076 }
8077
8078 /**
8079 * Returns true if the data roaming is enabled by default, i.e the system property
8080 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8081 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8082 */
8083 private boolean getDefaultDataRoamingEnabled(int subId) {
8084 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008085 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008086 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008087 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8088 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8089 return isDataRoamingEnabled;
8090 }
8091
8092 /**
8093 * Returns the default network type for the given {@code subId}, if the default network type is
8094 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8095 */
8096 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008097 List<Integer> list = TelephonyProperties.default_network();
8098 int phoneId = mSubscriptionController.getPhoneId(subId);
8099 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8100 return list.get(phoneId);
8101 }
8102 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008103 }
fionaxua13278b2018-03-21 00:08:13 -07008104
8105 @Override
8106 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008107 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109
8110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 final Phone phone = getPhone(subId);
8113 if (phone == null) {
8114 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8115 return;
8116 }
chen xueaba88a2019-03-15 13:15:10 -07008117 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8118 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008119 if (carrierPrivilegeRules == null) {
8120 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8121 } else {
8122 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 } finally {
8125 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008126 }
fionaxua13278b2018-03-21 00:08:13 -07008127 }
8128
8129 @Override
8130 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132
8133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 final Phone phone = getPhone(subId);
8136 if (phone == null) {
8137 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8138 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8139 }
8140 return phone.getCarrierIdListVersion();
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008143 }
fionaxua13278b2018-03-21 00:08:13 -07008144 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008145
8146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008147 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8148 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008150 mApp, subId, callingPackage, callingFeatureId,
8151 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008152 return -1;
8153 }
8154
8155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
8160 }
8161 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008162
8163 @Override
8164 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008165 TelephonyPermissions
8166 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008167 mApp, subId, "getCdmaRoamingMode");
8168
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
8171 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
8175 }
8176
8177 @Override
8178 public boolean setCdmaRoamingMode(int subId, int mode) {
8179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8180 mApp, subId, "setCdmaRoamingMode");
8181
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
8184 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
8188 }
8189
8190 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008191 public int getCdmaSubscriptionMode(int subId) {
8192 TelephonyPermissions
8193 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8194 mApp, subId, "getCdmaSubscriptionMode");
8195
8196 final long identity = Binder.clearCallingIdentity();
8197 try {
8198 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
8202 }
8203
8204 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008205 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8207 mApp, subId, "setCdmaSubscriptionMode");
8208
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8212 } finally {
8213 Binder.restoreCallingIdentity(identity);
8214 }
8215 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008216
sqianc5eccab2018-10-19 18:46:41 -07008217 @Override
sqian8c685422019-02-22 15:55:18 -08008218 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008219 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008221 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8222 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008223 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8224 }
8225 final long identity = Binder.clearCallingIdentity();
8226 try {
sqian854d44b2018-12-12 16:48:18 -08008227 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8228 for (Phone phone: PhoneFactory.getPhones()) {
8229 if (phone.getEmergencyNumberTracker() != null
8230 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8231 emergencyNumberListInternal.put(
8232 phone.getSubId(),
8233 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8234 }
sqian11b7a0e2018-12-05 18:48:28 -08008235 }
sqian854d44b2018-12-12 16:48:18 -08008236 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
sqianc5eccab2018-10-19 18:46:41 -07008240 }
8241
8242 @Override
sqian8c685422019-02-22 15:55:18 -08008243 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008244 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008245 if (!exactMatch) {
8246 TelephonyPermissions
8247 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008248 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008249 }
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
sqian854d44b2018-12-12 16:48:18 -08008252 for (Phone phone: PhoneFactory.getPhones()) {
8253 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008254 && phone.getEmergencyNumberTracker()
8255 .isEmergencyNumber(number, exactMatch)) {
8256 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008257 }
sqian11b7a0e2018-12-05 18:48:28 -08008258 }
8259 return false;
8260 } finally {
8261 Binder.restoreCallingIdentity(identity);
8262 }
8263 }
8264
sqianf4ca7ed2019-01-15 18:32:07 -08008265 /**
8266 * Update emergency number list for test mode.
8267 */
8268 @Override
8269 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8270 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8271 "updateEmergencyNumberListTestMode");
8272
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 for (Phone phone: PhoneFactory.getPhones()) {
8276 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8277 if (tracker != null) {
8278 tracker.executeEmergencyNumberTestModeCommand(action, num);
8279 }
8280 }
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
8285
8286 /**
8287 * Get the full emergency number list for test mode.
8288 */
8289 @Override
8290 public List<String> getEmergencyNumberListTestMode() {
8291 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8292 "getEmergencyNumberListTestMode");
8293
8294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 Set<String> emergencyNumbers = new HashSet<>();
8297 for (Phone phone: PhoneFactory.getPhones()) {
8298 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8299 if (tracker != null) {
8300 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8301 emergencyNumbers.add(num.getNumber());
8302 }
8303 }
8304 }
8305 return new ArrayList<>(emergencyNumbers);
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
8310
chen xud6b45bd2018-10-30 22:27:10 -07008311 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008312 public int getEmergencyNumberDbVersion(int subId) {
8313 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8314
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
8317 final Phone phone = getPhone(subId);
8318 if (phone == null) {
8319 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8320 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8321 }
8322 return phone.getEmergencyNumberDbVersion();
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
8326 }
8327
8328 @Override
8329 public void notifyOtaEmergencyNumberDbInstalled() {
8330 enforceModifyPermission();
8331
8332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 for (Phone phone: PhoneFactory.getPhones()) {
8335 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8336 if (tracker != null) {
8337 tracker.updateOtaEmergencyNumberDatabase();
8338 }
8339 }
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
8345 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008346 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008347 enforceActiveEmergencySessionPermission();
8348
8349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 for (Phone phone: PhoneFactory.getPhones()) {
8352 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8353 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008354 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8355 }
8356 }
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
8361
8362 @Override
8363 public void resetOtaEmergencyNumberDbFilePath() {
8364 enforceActiveEmergencySessionPermission();
8365
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 for (Phone phone: PhoneFactory.getPhones()) {
8369 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8370 if (tracker != null) {
8371 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008372 }
8373 }
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
8377 }
8378
8379 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008380 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8381 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8382 Phone phone = getPhone(subId);
8383 if (phone == null) {
8384 return null;
8385 }
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 UiccProfile profile = UiccController.getInstance()
8389 .getUiccProfileForPhone(phone.getPhoneId());
8390 if (profile != null) {
8391 return profile.getCertsFromCarrierPrivilegeAccessRules();
8392 }
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
8396 return null;
8397 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008398
8399 /**
8400 * Enable or disable a modem stack.
8401 */
8402 @Override
8403 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8404 enforceModifyPermission();
8405
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 Phone phone = PhoneFactory.getPhone(slotIndex);
8409 if (phone == null) {
8410 return false;
8411 } else {
8412 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8413 }
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 }
Michelecea4cf22018-12-21 15:00:11 -08008418
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008419 /**
8420 * Whether a modem stack is enabled or not.
8421 */
8422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008423 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8424 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008425 Phone phone = PhoneFactory.getPhone(slotIndex);
8426 if (phone == null) return false;
8427
8428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008429 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8430 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008431 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8432 }
8433
8434 final long identity = Binder.clearCallingIdentity();
8435 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008436 try {
8437 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8438 } catch (NoSuchElementException ex) {
8439 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8440 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
8444 }
8445
Michelecea4cf22018-12-21 15:00:11 -08008446 @Override
Michele0ea7d782019-03-19 14:58:42 -07008447 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008448 enforceModifyPermission();
8449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008453 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008454 .commit();
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
8460 @Override
Michele0ea7d782019-03-19 14:58:42 -07008461 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008462 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8465 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008466 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008467 }
Michelecea4cf22018-12-21 15:00:11 -08008468
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
Michele0ea7d782019-03-19 14:58:42 -07008471 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008476
Michele0ea7d782019-03-19 14:58:42 -07008477 @TelephonyManager.IsMultiSimSupportedResult
8478 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008479 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8480 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8481 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008482 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8483 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008484 }
8485 // Check if the hardware supports multisim functionality. If usage of multisim is not
8486 // supported by the modem, indicate that it is restricted.
8487 PhoneCapability staticCapability =
8488 mPhoneConfigurationManager.getStaticPhoneCapability();
8489 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008490 loge("isMultiSimSupportedInternal: no static configuration available");
8491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008492 }
Sarah Chin7caee492020-02-18 20:49:02 +00008493 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008494 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8495 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008496 }
8497 // Check if support of multiple SIMs is restricted by carrier
8498 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008499 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008500 }
8501
Michele0ea7d782019-03-19 14:58:42 -07008502 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008503 }
8504
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008505 /**
8506 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008507 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8508 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8509 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008510 * @param numOfSims number of active sims we want to switch to
8511 */
8512 @Override
8513 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008514 if (numOfSims == 1) {
8515 enforceModifyPermission();
8516 } else {
8517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8518 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8519 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008520 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008521
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008522 try {
Michele30b57b22019-03-01 12:01:14 -08008523 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008524 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008525 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8526 return;
8527 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008528 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
8533
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008534 @Override
8535 public boolean isApplicationOnUicc(int subId, int appType) {
8536 enforceReadPrivilegedPermission("isApplicationOnUicc");
8537 Phone phone = getPhone(subId);
8538 if (phone == null) {
8539 return false;
8540 }
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 UiccCard uiccCard = phone.getUiccCard();
8544 if (uiccCard == null) {
8545 return false;
8546 }
8547 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8548 if (uiccProfile == null) {
8549 return false;
8550 }
8551 if (TelephonyManager.APPTYPE_SIM <= appType
8552 && appType <= TelephonyManager.APPTYPE_ISIM) {
8553 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8554 }
8555 return false;
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 }
8560
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008561 /**
chen xub4baa772019-04-03 10:23:41 -07008562 * Get whether making changes to modem configurations will trigger reboot.
8563 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008564 */
8565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008566 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8567 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008569 mApp, subId, callingPackage, callingFeatureId,
8570 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008571 return false;
8572 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
8578 }
8579 }
8580
Nathan Harold29f5f052019-02-15 13:41:57 -08008581 private void updateModemStateMetrics() {
8582 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8583 // TODO: check the state for each modem if the api is ready.
8584 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8585 }
8586
Pengquan Meng3889a572019-01-23 11:16:29 -08008587 @Override
8588 public int[] getSlotsMapping() {
8589 enforceReadPrivilegedPermission("getSlotsMapping");
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8594 // All logical slots should have a mapping to a physical slot.
8595 int[] logicalSlotsMapping = new int[phoneCount];
8596 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8597 for (int i = 0; i < slotInfos.length; i++) {
8598 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8599 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8600 }
8601 }
8602 return logicalSlotsMapping;
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008607
8608 /**
8609 * Get the IRadio HAL Version
8610 */
8611 @Override
8612 public int getRadioHalVersion() {
8613 Phone phone = getDefaultPhone();
8614 if (phone == null) return -1;
8615 HalVersion hv = phone.getHalVersion();
8616 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8617 return hv.major * 100 + hv.minor;
8618 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008619
8620 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008621 * Get the current calling package name.
8622 * @return the current calling package name
8623 */
8624 @Override
8625 public String getCurrentPackageName() {
8626 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8627 }
8628
8629 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008630 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8631 * corresponding network requests on a subId.
8632 *
8633 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008634 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008635 * 2) APN is un-metered for this subscription, or
8636 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008637 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008638 *
8639 * @return whether data is allowed for a apn type.
8640 *
8641 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008642 */
8643 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008644 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008645 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8646 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008647
8648 // Now that all security checks passes, perform the operation as ourselves.
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
8651 Phone phone = getPhone(subId);
8652 if (phone == null) return false;
8653
Jack Yu41407ee2019-05-13 16:54:09 -07008654 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008655 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8656 } finally {
8657 Binder.restoreCallingIdentity(identity);
8658 }
8659 }
8660
8661 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008662 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008663 enforceReadPrivilegedPermission("isApnMetered");
8664
8665 // Now that all security checks passes, perform the operation as ourselves.
8666 final long identity = Binder.clearCallingIdentity();
8667 try {
8668 Phone phone = getPhone(subId);
8669 if (phone == null) return true; // By default return true.
8670
Jack Yu41407ee2019-05-13 16:54:09 -07008671 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008672 } finally {
8673 Binder.restoreCallingIdentity(identity);
8674 }
8675 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008676
8677 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008678 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8679 int subscriptionId, IBooleanConsumer resultCallback) {
8680 enforceModifyPermission();
8681 long token = Binder.clearCallingIdentity();
8682 try {
8683 Phone phone = getPhone(subscriptionId);
8684 if (phone == null) {
8685 try {
8686 if (resultCallback != null) {
8687 resultCallback.accept(false);
8688 }
8689 } catch (RemoteException e) {
8690 // ignore
8691 }
8692 return;
8693 }
8694 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8695 Pair.create(specifiers, (x) -> {
8696 try {
8697 if (resultCallback != null) {
8698 resultCallback.accept(x);
8699 }
8700 } catch (RemoteException e) {
8701 // ignore
8702 }
8703 });
8704 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8705 } finally {
8706 Binder.restoreCallingIdentity(token);
8707 }
8708 }
8709
8710 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008711 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008712 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008713 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8714 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8715 if (iccRecords == null) {
8716 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8717 return false;
8718 }
8719 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8720 }
8721
8722 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008723 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8724 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008725 if (callingPackage == null) {
8726 callingPackage = getCurrentPackageName();
8727 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008728 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8729 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008730 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8731 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008732 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8733 }
8734 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8735 Intent intent = new Intent();
8736 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8737 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8738 // Bring up choose default SMS subscription dialog right now
8739 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8740 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8741 mApp.startActivity(intent);
8742 }
chen xud5ca2d52019-05-28 15:20:57 -07008743
8744 @Override
8745 public String getMmsUAProfUrl(int subId) {
8746 //TODO investigate if this API should require proper permission check in R b/133791609
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008749 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8750 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8751 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8752 return carrierUAProfUrl;
8753 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008754 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8755 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008756 } finally {
8757 Binder.restoreCallingIdentity(identity);
8758 }
8759 }
8760
8761 @Override
8762 public String getMmsUserAgent(int subId) {
8763 //TODO investigate if this API should require proper permission check in R b/133791609
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008766 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8767 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8768 if (!TextUtils.isEmpty(carrierUserAgent)) {
8769 return carrierUserAgent;
8770 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008771 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8772 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
8776 }
Jack Yub07d4972019-05-28 16:12:25 -07008777
8778 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008779 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8780 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008781
Jack Yub07d4972019-05-28 16:12:25 -07008782 final long identity = Binder.clearCallingIdentity();
8783 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008784 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008785 if (phone == null) return false;
8786
Hall Liua62f5da2020-09-25 10:42:19 -07008787 switch (policy) {
8788 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8789 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8790 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8791 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8792 default:
8793 throw new IllegalArgumentException(policy + " is not a valid policy");
8794 }
Jack Yub07d4972019-05-28 16:12:25 -07008795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
8799
8800 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008801 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8802 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008803 enforceModifyPermission();
8804
changbettyd5c246e2019-12-24 15:40:37 +08008805 final long identity = Binder.clearCallingIdentity();
8806 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008807 Phone phone = getPhone(subscriptionId);
8808 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008809
Hall Liua62f5da2020-09-25 10:42:19 -07008810 switch (policy) {
8811 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8812 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8813 break;
8814 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8815 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8816 break;
8817 default:
8818 throw new IllegalArgumentException(policy + " is not a valid policy");
8819 }
changbettyd5c246e2019-12-24 15:40:37 +08008820 } finally {
8821 Binder.restoreCallingIdentity(identity);
8822 }
8823 }
8824
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008825 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008826 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008827 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8828 * otherwise.
8829 */
8830 @Override
8831 public void setCepEnabled(boolean isCepEnabled) {
8832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8833
8834 final long identity = Binder.clearCallingIdentity();
8835 try {
8836 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8837 for (Phone phone : PhoneFactory.getPhones()) {
8838 Phone defaultPhone = phone.getImsPhone();
8839 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8840 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8841 ImsPhoneCallTracker imsPhoneCallTracker =
8842 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8843 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8844 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8845 + imsPhone.getMsisdn());
8846 }
8847 }
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
allenwtsu46dcc572020-01-08 18:24:03 +08008852
8853 /**
8854 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8855 *
8856 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8857 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8858 * before being read.
8859 */
8860 @Override
8861 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8862 isCompressed) {
8863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8864 mApp, subId, "notifyRcsAutoConfigurationReceived");
8865 try {
8866 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8867 if (configBinder == null) {
8868 Rlog.e(LOG_TAG, "null result for getImsConfig");
8869 } else {
8870 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8871 }
8872 } catch (RemoteException e) {
8873 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8874 }
8875 }
zoey chene02881a2019-12-30 16:11:23 +08008876
8877 @Override
8878 public boolean isIccLockEnabled(int subId) {
8879 enforceReadPrivilegedPermission("isIccLockEnabled");
8880
8881 // Now that all security checks passes, perform the operation as ourselves.
8882 final long identity = Binder.clearCallingIdentity();
8883 try {
8884 Phone phone = getPhone(subId);
8885 if (phone != null && phone.getIccCard() != null) {
8886 return phone.getIccCard().getIccLockEnabled();
8887 } else {
8888 return false;
8889 }
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
8893 }
8894
8895 /**
8896 * Set the ICC pin lock enabled or disabled.
8897 *
8898 * @return an integer representing the status of IccLock enabled or disabled in the following
8899 * three cases:
8900 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8901 * successfully.
8902 * - Positive number and zero for remaining password attempts.
8903 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8904 *
8905 */
8906 @Override
8907 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8908 enforceModifyPermission();
8909
8910 Phone phone = getPhone(subId);
8911 if (phone == null) {
8912 return 0;
8913 }
8914 // Now that all security checks passes, perform the operation as ourselves.
8915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8918 new Pair<Boolean, String>(enabled, password), phone, null);
8919 return attemptsRemaining;
8920
8921 } catch (Exception e) {
8922 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
8925 }
8926 return 0;
8927 }
8928
8929 /**
8930 * Change the ICC password used in ICC pin lock.
8931 *
8932 * @return an integer representing the status of IccLock changed in the following three cases:
8933 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8934 * - Positive number and zero for remaining password attempts.
8935 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8936 *
8937 */
8938 @Override
8939 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8940 enforceModifyPermission();
8941
8942 Phone phone = getPhone(subId);
8943 if (phone == null) {
8944 return 0;
8945 }
8946 // Now that all security checks passes, perform the operation as ourselves.
8947 final long identity = Binder.clearCallingIdentity();
8948 try {
8949 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8950 new Pair<String, String>(oldPassword, newPassword), phone, null);
8951 return attemptsRemaining;
8952
8953 } catch (Exception e) {
8954 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 return 0;
8959 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008960
8961 /**
8962 * Request for receiving user activity notification
8963 */
8964 @Override
8965 public void requestUserActivityNotification() {
8966 if (!mNotifyUserActivity.get()
8967 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8968 mNotifyUserActivity.set(true);
8969 }
8970 }
8971
8972 /**
8973 * Called when userActivity is signalled in the power manager.
8974 * This is safe to call from any thread, with any window manager locks held or not.
8975 */
8976 @Override
8977 public void userActivity() {
8978 // ***************************************
8979 // * Inherited from PhoneWindowManager *
8980 // ***************************************
8981 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8982 // WITH ITS LOCKS HELD.
8983 //
8984 // This code must be VERY careful about the locks
8985 // it acquires.
8986 // In fact, the current code acquires way too many,
8987 // and probably has lurking deadlocks.
8988
8989 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8990 throw new SecurityException("Only the OS may call notifyUserActivity()");
8991 }
8992
8993 if (mNotifyUserActivity.getAndSet(false)) {
8994 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8995 USER_ACTIVITY_NOTIFICATION_DELAY);
8996 }
8997 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008998
8999 @Override
9000 public boolean canConnectTo5GInDsdsMode() {
9001 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9002 }
Jack Yud10cdd42020-09-28 20:28:01 -07009003
9004 @Override
9005 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9006 String callingFeatureId) {
9007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9008 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9009 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9010 }
9011
9012 Phone phone = getPhone(subId);
9013 if (phone == null) {
9014 throw new RuntimeException("phone is not available");
9015 }
9016 // Now that all security checks passes, perform the operation as ourselves.
9017 final long identity = Binder.clearCallingIdentity();
9018 try {
9019 return phone.getEquivalentHomePlmns();
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
9022 }
9023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009024}