blob: ebae435bb55219ee749afb98c633deee45d31f58 [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;
Sarah Chin679c08a2020-11-18 13:39:35 -0800299 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
300 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800302 // Parameters of select command.
303 private static final int SELECT_COMMAND = 0xA4;
304 private static final int SELECT_P1 = 0x04;
305 private static final int SELECT_P2 = 0;
306 private static final int SELECT_P3 = 0x10;
307
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308 /** The singleton instance. */
309 private static PhoneInterfaceManager sInstance;
310
Wink Saville3ab207e2014-11-20 13:07:20 -0800311 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800312 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800313 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700314 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800315 private AppOpsManager mAppOps;
316 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800317 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800318 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700319 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320
Peter Wangdafb9ac2020-01-15 14:13:38 -0800321 /** User Activity */
322 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800323 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
324
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700325 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
326
Derek Tan97ebb422014-09-05 16:55:38 -0700327 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
328 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800329 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800330 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700331
Michelecea4cf22018-12-21 15:00:11 -0800332 // String to store multi SIM allowed
333 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
334
Derek Tan740e1672017-06-27 14:56:27 -0700335 // The AID of ISD-R.
336 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
337
yinxub1bed742017-04-17 11:45:04 -0700338 private NetworkScanRequestTracker mNetworkScanRequestTracker;
339
David Kelly5e06a7f2018-03-12 14:10:59 +0000340 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
341 private static final int MANUFACTURER_CODE_LENGTH = 8;
342
Derek Tan89e89d42014-07-08 17:00:10 -0700343 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700344 * Experiment flag to enable erase modem config on reset network, default value is false
345 */
346 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
347 "reset_network_erase_modem_config_enabled";
348
349 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700350 * A request object to use for transmitting data to an ICC.
351 */
352 private static final class IccAPDUArgument {
353 public int channel, cla, command, p1, p2, p3;
354 public String data;
355
356 public IccAPDUArgument(int channel, int cla, int command,
357 int p1, int p2, int p3, String data) {
358 this.channel = channel;
359 this.cla = cla;
360 this.command = command;
361 this.p1 = p1;
362 this.p2 = p2;
363 this.p3 = p3;
364 this.data = data;
365 }
366 }
367
368 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700369 * A request object to use for transmitting data to an ICC.
370 */
371 private static final class ManualNetworkSelectionArgument {
372 public OperatorInfo operatorInfo;
373 public boolean persistSelection;
374
375 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
376 this.operatorInfo = operatorInfo;
377 this.persistSelection = persistSelection;
378 }
379 }
380
381 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
383 * request after sending. The main thread will notify the request when it is complete.
384 */
385 private static final class MainThreadRequest {
386 /** The argument to use for the request */
387 public Object argument;
388 /** The result of the request that is run on the main thread */
389 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800390 // The subscriber id that this request applies to. Defaults to
391 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
392 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 // In cases where subId is unavailable, the caller needs to specify the phone.
395 public Phone phone;
396
vagdeviaf9a5b92018-08-15 16:01:53 -0700397 public WorkSource workSource;
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 public MainThreadRequest(Object argument) {
400 this.argument = argument;
401 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800402
Nathan Harold92bed182018-10-12 18:16:49 -0700403 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
404 this.argument = argument;
405 if (phone != null) {
406 this.phone = phone;
407 }
408 this.workSource = workSource;
409 }
410
vagdeviaf9a5b92018-08-15 16:01:53 -0700411 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800412 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800413 if (subId != null) {
414 this.subId = subId;
415 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700416 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 }
419
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800420 private static final class IncomingThirdPartyCallArgs {
421 public final ComponentName component;
422 public final String callId;
423 public final String callerDisplayName;
424
425 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
426 String callerDisplayName) {
427 this.component = component;
428 this.callId = callId;
429 this.callerDisplayName = callerDisplayName;
430 }
431 }
432
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 /**
434 * A handler that processes messages on the main thread in the phone process. Since many
435 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
436 * inbound binder threads to the main thread in the phone process. The Binder thread
437 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
438 * on, which will be notified when the operation completes and will contain the result of the
439 * request.
440 *
441 * <p>If a MainThreadRequest object is provided in the msg.obj field,
442 * note that request.result must be set to something non-null for the calling thread to
443 * unblock.
444 */
445 private final class MainThreadHandler extends Handler {
446 @Override
447 public void handleMessage(Message msg) {
448 MainThreadRequest request;
449 Message onCompleted;
450 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800451 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800453 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454
455 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 case CMD_HANDLE_USSD_REQUEST: {
457 request = (MainThreadRequest) msg.obj;
458 final Phone phone = getPhoneFromRequest(request);
459 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
460 String ussdRequest = ussdObject.first;
461 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700462
Pengquan Menga1bb6272018-09-06 09:59:22 -0700463 if (!isUssdApiAllowed(request.subId)) {
464 // Carrier does not support use of this API, return failure.
465 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
466 UssdResponse response = new UssdResponse(ussdRequest, null);
467 Bundle returnData = new Bundle();
468 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
469 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700470
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 request.result = true;
472 notifyRequester(request);
473 return;
474 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700475
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 try {
477 request.result = phone != null
478 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
479 } catch (CallStateException cse) {
480 request.result = false;
481 }
482 // Wake up the requesting thread
483 notifyRequester(request);
484 break;
pkanwar32d516d2016-10-14 19:37:38 -0700485 }
486
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700489 final Phone phone = getPhoneFromRequest(request);
490 request.result = phone != null ?
491 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
492 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduLogicalChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700506 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
508 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 iccArgument.channel, iccArgument.cla, iccArgument.command,
511 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 break;
515
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800525 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800527 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 } else {
529 loge("iccTransmitApduLogicalChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 break;
534
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccTransmitApduBasicChannel: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
545 request);
546 uiccCard.iccTransmitApduBasicChannel(
547 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
548 iccArgument.p3, iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("iccTransmitApduBasicChannel: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("iccTransmitApduBasicChannel: CommandException: " +
563 ar.exception);
564 } else {
565 loge("iccTransmitApduBasicChannel: Unknown exception");
566 }
567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 break;
570
571 case CMD_EXCHANGE_SIM_IO:
572 request = (MainThreadRequest) msg.obj;
573 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800574 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 if (uiccCard == null) {
576 loge("iccExchangeSimIO: No UICC");
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 } else {
580 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
581 request);
582 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
583 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
584 iccArgument.data, onCompleted);
585 }
586 break;
587
588 case EVENT_EXCHANGE_SIM_IO_DONE:
589 ar = (AsyncResult) msg.obj;
590 request = (MainThreadRequest) ar.userObj;
591 if (ar.exception == null && ar.result != null) {
592 request.result = ar.result;
593 } else {
594 request.result = new IccIoResult(0x6f, 0, (byte[])null);
595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 break;
598
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 case CMD_SEND_ENVELOPE:
600 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800601 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 if (uiccCard == null) {
603 loge("sendEnvelopeWithStatus: No UICC");
604 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
608 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
609 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 break;
611
612 case EVENT_SEND_ENVELOPE_DONE:
613 ar = (AsyncResult) msg.obj;
614 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700615 if (ar.exception == null && ar.result != null) {
616 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700618 request.result = new IccIoResult(0x6F, 0, (byte[])null);
619 if (ar.result == null) {
620 loge("sendEnvelopeWithStatus: Empty response");
621 } else if (ar.exception instanceof CommandException) {
622 loge("sendEnvelopeWithStatus: CommandException: " +
623 ar.exception);
624 } else {
625 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
626 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800629 break;
630
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 case CMD_OPEN_CHANNEL:
632 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800633 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800634 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800637 request.result = new IccOpenLogicalChannelResponse(-1,
638 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 } else {
641 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800642 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
643 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
647 case EVENT_OPEN_CHANNEL_DONE:
648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 int[] result = (int[]) ar.result;
653 int channelId = result[0];
654 byte[] selectResponse = null;
655 if (result.length > 1) {
656 selectResponse = new byte[result.length - 1];
657 for (int i = 1; i < result.length; ++i) {
658 selectResponse[i - 1] = (byte) result[i];
659 }
660 }
661 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 if (ar.result == null) {
665 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 if (ar.exception != null) {
668 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
669 }
670
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700671 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700672 if (ar.exception instanceof CommandException) {
673 CommandException.Error error =
674 ((CommandException) (ar.exception)).getCommandError();
675 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700676 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700677 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700678 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 }
680 }
681 openChannelResp = new IccOpenLogicalChannelResponse(
682 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700684 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
688 case CMD_CLOSE_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800690 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 if (uiccCard == null) {
692 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900693 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
697 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
698 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 break;
700
701 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800702 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
703 break;
704
705 case CMD_NV_READ_ITEM:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
709 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 ar = (AsyncResult) msg.obj;
714 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800715 if (ar.exception == null && ar.result != null) {
716 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800718 request.result = "";
719 if (ar.result == null) {
720 loge("nvReadItem: Empty response");
721 } else if (ar.exception instanceof CommandException) {
722 loge("nvReadItem: CommandException: " +
723 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800725 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 }
727 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 break;
730
Jake Hambye994d462014-02-03 13:10:13 -0800731 case CMD_NV_WRITE_ITEM:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
734 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700736 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
739 case EVENT_NV_WRITE_ITEM_DONE:
740 handleNullReturnEvent(msg, "nvWriteItem");
741 break;
742
743 case CMD_NV_WRITE_CDMA_PRL:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800747 break;
748
749 case EVENT_NV_WRITE_CDMA_PRL_DONE:
750 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
751 break;
752
chen xu6dac5ab2018-10-26 17:39:23 -0700753 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800754 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700755 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800756 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800757 break;
758
chen xu6dac5ab2018-10-26 17:39:23 -0700759 case EVENT_RESET_MODEM_CONFIG_DONE:
760 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
Sooraj Sasindran37444802020-08-11 10:40:43 -0700763 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
766 request);
767 Phone phone = getPhoneFromRequest(request);
768 if (phone != null) {
769 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
770 } else {
771 loge("isNRDualConnectivityEnabled: No phone object");
772 request.result = false;
773 notifyRequester(request);
774 }
775 break;
776 }
777
778 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
781 if (ar.exception == null && ar.result != null) {
782 request.result = ar.result;
783 } else {
784 // request.result must be set to something non-null
785 // for the calling thread to unblock
786 if (request.result != null) {
787 request.result = ar.result;
788 } else {
789 request.result = false;
790 }
791 if (ar.result == null) {
792 loge("isNRDualConnectivityEnabled: Empty response");
793 } else if (ar.exception instanceof CommandException) {
794 loge("isNRDualConnectivityEnabled: CommandException: "
795 + ar.exception);
796 } else {
797 loge("isNRDualConnectivityEnabled: Unknown exception");
798 }
799 }
800 notifyRequester(request);
801 break;
802
803 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
806 Phone phone = getPhoneFromRequest(request);
807 if (phone != null) {
808 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
809 request.workSource);
810 } else {
811 loge("enableNrDualConnectivity: No phone object");
812 request.result =
813 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
814 notifyRequester(request);
815 }
816 break;
817 }
818
819 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null) {
823 request.result =
824 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
825 } else {
826 request.result =
827 TelephonyManager
828 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
829 if (ar.exception instanceof CommandException) {
830 CommandException.Error error =
831 ((CommandException) (ar.exception)).getCommandError();
832 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
833 request.result =
834 TelephonyManager
835 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
836 }
837 loge("enableNrDualConnectivity" + ": CommandException: "
838 + ar.exception);
839 } else {
840 loge("enableNrDualConnectivity" + ": Unknown exception");
841 }
842 }
843 notifyRequester(request);
844 break;
845 }
846
Jake Hamby7c27be32014-03-03 13:25:59 -0800847 case CMD_GET_PREFERRED_NETWORK_TYPE:
848 request = (MainThreadRequest) msg.obj;
849 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700850 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800851 break;
852
853 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result; // Integer
858 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530859 // request.result must be set to something non-null
860 // for the calling thread to unblock
861 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800862 if (ar.result == null) {
863 loge("getPreferredNetworkType: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("getPreferredNetworkType: CommandException: " +
866 ar.exception);
867 } else {
868 loge("getPreferredNetworkType: Unknown exception");
869 }
870 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800872 break;
873
874 case CMD_SET_PREFERRED_NETWORK_TYPE:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
877 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700878 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 break;
880
881 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
882 handleNullReturnEvent(msg, "setPreferredNetworkType");
883 break;
884
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000885 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
886 request = (MainThreadRequest)msg.obj;
887 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000889 break;
890
891 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
892 ar = (AsyncResult)msg.obj;
893 request = (MainThreadRequest)ar.userObj;
894 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000896 break;
897
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800898 case CMD_SET_VOICEMAIL_NUMBER:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
901 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800902 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
903 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800904 break;
905
906 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
907 handleNullReturnEvent(msg, "setVoicemailNumber");
908 break;
909
Stuart Scott54788802015-03-30 13:18:01 -0700910 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
913 request);
914 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
915 break;
916
917 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
918 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
919 break;
920
Shishir Agrawal302c8692015-06-19 13:49:39 -0700921 case CMD_PERFORM_NETWORK_SCAN:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
924 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
925 break;
926
Hall Liu27d24262020-09-18 19:04:59 -0700927 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700930 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
931 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
932 request.argument;
933 int callForwardingReason = args.first;
934 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800935 break;
Hall Liu27d24262020-09-18 19:04:59 -0700936 }
937 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700940 TelephonyManager.CallForwardingInfoCallback callback =
941 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
942 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800943 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700944 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800945 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
946 for (CallForwardInfo callForwardInfo : callForwardInfos) {
947 // Service Class is a bit mask per 3gpp 27.007. Search for
948 // any service for voice call.
949 if ((callForwardInfo.serviceClass
950 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700951 callForwardingInfo = new CallForwardingInfo(true,
952 callForwardInfo.reason,
953 callForwardInfo.number,
954 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800955 break;
956 }
957 }
958 // Didn't find a call forward info for voice call.
959 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700960 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
961 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800962 }
Hall Liu27d24262020-09-18 19:04:59 -0700963 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800964 } else {
965 if (ar.result == null) {
966 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
967 }
968 if (ar.exception != null) {
969 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
970 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700971 int errorCode = TelephonyManager
972 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700977 errorCode = TelephonyManager
978 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800979 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700980 errorCode = TelephonyManager
981 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800982 }
983 }
Hall Liu27d24262020-09-18 19:04:59 -0700984 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800985 }
Shuo Qian4a594052020-01-23 11:59:30 -0800986 break;
Hall Liu27d24262020-09-18 19:04:59 -0700987 }
Shuo Qian4a594052020-01-23 11:59:30 -0800988
Hall Liu27d24262020-09-18 19:04:59 -0700989 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700992 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800993 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700994 ((Pair<CallForwardingInfo, Consumer<Integer>>)
995 request.argument).first;
996 request.phone.setCallForwardingOption(
997 callForwardingInfoToSet.isEnabled()
998 ? CommandsInterface.CF_ACTION_ENABLE
999 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001000 callForwardingInfoToSet.getReason(),
1001 callForwardingInfoToSet.getNumber(),
1002 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1003 break;
Hall Liu27d24262020-09-18 19:04:59 -07001004 }
Shuo Qian4a594052020-01-23 11:59:30 -08001005
Hall Liu27d24262020-09-18 19:04:59 -07001006 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001009 Consumer<Integer> callback =
1010 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1011 request.argument).second;
1012 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001013 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001014 int errorCode = TelephonyManager.CallForwardingInfoCallback
1015 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001016 if (ar.exception instanceof CommandException) {
1017 CommandException.Error error =
1018 ((CommandException) (ar.exception)).getCommandError();
1019 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager.CallForwardingInfoCallback
1021 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001023 errorCode = TelephonyManager.CallForwardingInfoCallback
1024 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001025 }
1026 }
1027 callback.accept(errorCode);
1028 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001029 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001030 }
Shuo Qian4a594052020-01-23 11:59:30 -08001031 break;
Hall Liu27d24262020-09-18 19:04:59 -07001032 }
Shuo Qian4a594052020-01-23 11:59:30 -08001033
Hall Liu27d24262020-09-18 19:04:59 -07001034 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1037 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1038 break;
Hall Liu27d24262020-09-18 19:04:59 -07001039 }
Shuo Qian4a594052020-01-23 11:59:30 -08001040
Hall Liu27d24262020-09-18 19:04:59 -07001041 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001044 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001045 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1046 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001047 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001048 // Service Class is a bit mask per 3gpp 27.007.
1049 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001050 if (callForwardResults.length > 1
1051 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001052 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001053 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001054 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1055 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001056 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001057 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001058 }
1059 } else {
1060 if (ar.result == null) {
1061 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1062 }
1063 if (ar.exception != null) {
1064 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1065 }
1066 if (ar.exception instanceof CommandException) {
1067 CommandException.Error error =
1068 ((CommandException) (ar.exception)).getCommandError();
1069 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1070 callForwardingStatus =
1071 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1072 }
1073 }
1074 }
Hall Liu27d24262020-09-18 19:04:59 -07001075 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001076 break;
Hall Liu27d24262020-09-18 19:04:59 -07001077 }
Shuo Qian4a594052020-01-23 11:59:30 -08001078
Hall Liu27d24262020-09-18 19:04:59 -07001079 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001082 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1083 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
Shuo Qian4a594052020-01-23 11:59:30 -08001086
Hall Liu27d24262020-09-18 19:04:59 -07001087 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001090 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1091 Consumer<Integer> callback =
1092 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1093 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001095 if (ar.exception instanceof CommandException) {
1096 CommandException.Error error =
1097 ((CommandException) (ar.exception)).getCommandError();
1098 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1099 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1100 } else {
1101 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1102 }
1103 } else {
1104 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1105 }
1106 } else {
1107 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1108 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001109 }
Shuo Qian4a594052020-01-23 11:59:30 -08001110 break;
Hall Liu27d24262020-09-18 19:04:59 -07001111 }
Shuo Qian4a594052020-01-23 11:59:30 -08001112
Shishir Agrawal302c8692015-06-19 13:49:39 -07001113 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 CellNetworkScanResult cellScanResult;
1117 if (ar.exception == null && ar.result != null) {
1118 cellScanResult = new CellNetworkScanResult(
1119 CellNetworkScanResult.STATUS_SUCCESS,
1120 (List<OperatorInfo>) ar.result);
1121 } else {
1122 if (ar.result == null) {
1123 loge("getCellNetworkScanResults: Empty response");
1124 }
1125 if (ar.exception != null) {
1126 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1127 }
1128 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1129 if (ar.exception instanceof CommandException) {
1130 CommandException.Error error =
1131 ((CommandException) (ar.exception)).getCommandError();
1132 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1133 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1134 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1135 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1136 }
1137 }
1138 cellScanResult = new CellNetworkScanResult(errorCode, null);
1139 }
1140 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001142 break;
1143
1144 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1145 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001146 ManualNetworkSelectionArgument selArg =
1147 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001148 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1149 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001150 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1151 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001152 break;
1153
1154 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
1157 if (ar.exception == null) {
1158 request.result = true;
1159 } else {
1160 request.result = false;
1161 loge("setNetworkSelectionModeManual " + ar.exception);
1162 }
1163 notifyRequester(request);
1164 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 break;
1166
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001167 case CMD_GET_MODEM_ACTIVITY_INFO:
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001170 if (defaultPhone != null) {
1171 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001172 } else {
1173 ResultReceiver result = (ResultReceiver) request.argument;
1174 Bundle bundle = new Bundle();
1175 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001176 new ModemActivityInfo(0, 0, 0,
1177 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001178 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001179 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001180 break;
1181
Hall Liud0f208c2020-10-14 16:54:44 -07001182 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001185 ResultReceiver result = (ResultReceiver) request.argument;
1186
Hall Liud0f208c2020-10-14 16:54:44 -07001187 ModemActivityInfo ret = null;
1188 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001189 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001190 // Update the last modem activity info and the result of the request.
1191 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1192 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001193 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001194 int[] txTimeMs = info.getTransmitTimeMillis();
1195 int[] lastModemTxTimeMs = mLastModemActivityInfo
1196 .getTransmitTimeMillis();
1197 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1198 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1199 }
Hall Liu49656c02020-10-09 19:00:11 -07001200 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001201 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1202 + mLastModemActivityInfo.getSleepTimeMillis());
1203 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1204 + mLastModemActivityInfo.getIdleTimeMillis());
1205 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1206 mLastModemActivityInfo.setReceiveTimeMillis(
1207 info.getReceiveTimeMillis()
1208 + mLastModemActivityInfo.getReceiveTimeMillis());
1209 }
Hall Liu49656c02020-10-09 19:00:11 -07001210 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001211 mLastModemActivityInfo.getSleepTimeMillis(),
1212 mLastModemActivityInfo.getIdleTimeMillis(),
1213 mLastModemActivityInfo.getTransmitTimeMillis(),
1214 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 } else {
1216 if (ar.result == null) {
1217 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001218 error = TelephonyManager.ModemActivityInfoException
1219 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 } else if (ar.exception instanceof CommandException) {
1221 loge("queryModemActivityInfo: CommandException: " +
1222 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001223 error = TelephonyManager.ModemActivityInfoException
1224 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 } else {
1226 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001227 error = TelephonyManager.ModemActivityInfoException
1228 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 }
1230 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001232 if (ret != null) {
1233 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1234 } else {
1235 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1236 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001237 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001240 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241
Meng Wang1a7c35a2016-05-05 20:56:15 -07001242 case CMD_SET_ALLOWED_CARRIERS:
1243 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001244 CarrierRestrictionRules argument =
1245 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001246 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001247 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001248 break;
1249
1250 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1251 ar = (AsyncResult) msg.obj;
1252 request = (MainThreadRequest) ar.userObj;
1253 if (ar.exception == null && ar.result != null) {
1254 request.result = ar.result;
1255 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001256 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1257 if (ar.exception instanceof CommandException) {
1258 loge("setAllowedCarriers: CommandException: " + ar.exception);
1259 CommandException.Error error =
1260 ((CommandException) (ar.exception)).getCommandError();
1261 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1262 request.result =
1263 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1264 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 } else {
1266 loge("setAllowedCarriers: Unknown exception");
1267 }
1268 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001269 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 break;
1271
1272 case CMD_GET_ALLOWED_CARRIERS:
1273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001275 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 break;
1277
1278 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 if (ar.exception == null && ar.result != null) {
1282 request.result = ar.result;
1283 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001284 request.result = new IllegalStateException(
1285 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 if (ar.result == null) {
1287 loge("getAllowedCarriers: Empty response");
1288 } else if (ar.exception instanceof CommandException) {
1289 loge("getAllowedCarriers: CommandException: " +
1290 ar.exception);
1291 } else {
1292 loge("getAllowedCarriers: Unknown exception");
1293 }
1294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001296 break;
1297
Nathan Haroldb3014052017-01-25 15:57:32 -08001298 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1299 ar = (AsyncResult) msg.obj;
1300 request = (MainThreadRequest) ar.userObj;
1301 if (ar.exception == null && ar.result != null) {
1302 request.result = ar.result;
1303 } else {
1304 request.result = new IllegalArgumentException(
1305 "Failed to retrieve Forbidden Plmns");
1306 if (ar.result == null) {
1307 loge("getForbiddenPlmns: Empty response");
1308 } else {
1309 loge("getForbiddenPlmns: Unknown exception");
1310 }
1311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001313 break;
1314
1315 case CMD_GET_FORBIDDEN_PLMNS:
1316 request = (MainThreadRequest) msg.obj;
1317 uiccCard = getUiccCardFromRequest(request);
1318 if (uiccCard == null) {
1319 loge("getForbiddenPlmns() UiccCard is null");
1320 request.result = new IllegalArgumentException(
1321 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001323 break;
1324 }
1325 Integer appType = (Integer) request.argument;
1326 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1327 if (uiccApp == null) {
1328 loge("getForbiddenPlmns() no app with specified type -- "
1329 + appType);
1330 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001332 break;
1333 } else {
1334 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1335 + " specified type -- " + appType);
1336 }
1337 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1338 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1339 onCompleted);
1340 break;
1341
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001342 case CMD_SWITCH_SLOTS:
1343 request = (MainThreadRequest) msg.obj;
1344 int[] physicalSlots = (int[]) request.argument;
1345 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1346 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1347 break;
1348
1349 case EVENT_SWITCH_SLOTS_DONE:
1350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
1352 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001353 notifyRequester(request);
1354 break;
1355 case CMD_GET_NETWORK_SELECTION_MODE:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1358 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1359 break;
1360
1361 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 if (ar.exception != null) {
1365 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1366 } else {
1367 int mode = ((int[]) ar.result)[0];
1368 if (mode == 0) {
1369 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1370 } else {
1371 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001373 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
1375 break;
1376 case CMD_GET_CDMA_ROAMING_MODE:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1379 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1380 break;
1381 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 if (ar.exception != null) {
1385 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1386 } else {
1387 request.result = ((int[]) ar.result)[0];
1388 }
1389 notifyRequester(request);
1390 break;
1391 case CMD_SET_CDMA_ROAMING_MODE:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1394 int mode = (int) request.argument;
1395 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1396 break;
1397 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 request.result = ar.exception == null;
1401 notifyRequester(request);
1402 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001403 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1406 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1407 break;
1408 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1413 } else {
1414 request.result = ((int[]) ar.result)[0];
1415 }
1416 notifyRequester(request);
1417 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001418 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1421 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001422 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1423 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001424 break;
1425 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 request.result = ar.exception == null;
1429 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001430 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001431 case CMD_GET_ALL_CELL_INFO:
1432 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001433 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001434 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001435 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001436 case EVENT_GET_ALL_CELL_INFO_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001439 // If a timeout occurs, the response will be null
1440 request.result = (ar.exception == null && ar.result != null)
1441 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001442 synchronized (request) {
1443 request.notifyAll();
1444 }
1445 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001446 case CMD_REQUEST_CELL_INFO_UPDATE:
1447 request = (MainThreadRequest) msg.obj;
1448 request.phone.requestCellInfoUpdate(request.workSource,
1449 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1450 break;
1451 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1455 try {
1456 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001457 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001458 cb.onError(
1459 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1460 ar.exception.getClass().getName(),
1461 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001463 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001464 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 } else {
1466 // use the result as returned
1467 cb.onCellInfo((List<CellInfo>) ar.result);
1468 }
1469 } catch (RemoteException re) {
1470 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1471 }
1472 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001473 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 request = (MainThreadRequest) msg.obj;
1475 WorkSource ws = (WorkSource) request.argument;
1476 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001477 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001479 }
1480 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
1483 if (ar.exception == null) {
1484 request.result = ar.result;
1485 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001486 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001488 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 }
1490
1491 synchronized (request) {
1492 request.notifyAll();
1493 }
1494 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001495 }
chen xu6dac5ab2018-10-26 17:39:23 -07001496 case CMD_MODEM_REBOOT:
1497 request = (MainThreadRequest) msg.obj;
1498 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001499 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001500 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001501 case EVENT_CMD_MODEM_REBOOT_DONE:
1502 handleNullReturnEvent(msg, "rebootModem");
1503 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001504 case CMD_REQUEST_ENABLE_MODEM:
1505 request = (MainThreadRequest) msg.obj;
1506 boolean enable = (boolean) request.argument;
1507 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001508 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001509 PhoneConfigurationManager.getInstance()
1510 .enablePhone(request.phone, enable, onCompleted);
1511 break;
1512 case EVENT_ENABLE_MODEM_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001516 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001517 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001518 if ((boolean) request.result) {
1519 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1520 updateModemStateMetrics();
1521 } else {
1522 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1523 + ar.exception);
1524 }
1525 notifyRequester(request);
1526 break;
1527 case CMD_GET_MODEM_STATUS:
1528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1530 PhoneConfigurationManager.getInstance()
1531 .getPhoneStatusFromModem(request.phone, onCompleted);
1532 break;
1533 case EVENT_GET_MODEM_STATUS_DONE:
1534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 int id = request.phone.getPhoneId();
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 //update the cache as modem status has changed
1540 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1541 (boolean) request.result);
1542 } else {
1543 // Return true if modem status cannot be retrieved. For most cases,
1544 // modem status is on. And for older version modems, GET_MODEM_STATUS
1545 // and disable modem are not supported. Modem is always on.
1546 // TODO: this should be fixed in R to support a third
1547 // status UNKNOWN b/131631629
1548 request.result = true;
1549 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1550 + ar.exception);
1551 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001552 notifyRequester(request);
1553 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001554 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1557 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1558 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1559 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1560 break;
1561 }
1562 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1566 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1567 args.second.accept(ar.exception == null);
1568 notifyRequester(request);
1569 break;
1570 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001571 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1574 Phone phone = getPhoneFromRequest(request);
1575 if (phone != null) {
1576 phone.getSystemSelectionChannels(onCompleted);
1577 } else {
1578 loge("getSystemSelectionChannels: No phone object");
1579 request.result = new ArrayList<RadioAccessSpecifier>();
1580 notifyRequester(request);
1581 }
1582 break;
1583 }
1584 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 if (ar.exception == null && ar.result != null) {
1588 request.result = ar.result;
1589 } else {
1590 request.result = new IllegalArgumentException(
1591 "Failed to retrieve system selection channels");
1592 if (ar.result == null) {
1593 loge("getSystemSelectionChannels: Empty response");
1594 } else {
1595 loge("getSystemSelectionChannels: Unknown exception");
1596 }
1597 }
1598 notifyRequester(request);
1599 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001600 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 if (ar.exception == null && ar.result != null) {
1604 request.result = ar.result;
1605 } else {
1606 request.result = -1;
1607 loge("Failed to set Forbidden Plmns");
1608 if (ar.result == null) {
1609 loge("setForbidenPlmns: Empty response");
1610 } else if (ar.exception != null) {
1611 loge("setForbiddenPlmns: Exception: " + ar.exception);
1612 request.result = -1;
1613 } else {
1614 loge("setForbiddenPlmns: Unknown exception");
1615 }
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_FORBIDDEN_PLMNS:
1620 request = (MainThreadRequest) msg.obj;
1621 uiccCard = getUiccCardFromRequest(request);
1622 if (uiccCard == null) {
1623 loge("setForbiddenPlmns: UiccCard is null");
1624 request.result = -1;
1625 notifyRequester(request);
1626 break;
1627 }
1628 Pair<Integer, List<String>> setFplmnsArgs =
1629 (Pair<Integer, List<String>>) request.argument;
1630 appType = setFplmnsArgs.first;
1631 List<String> fplmns = setFplmnsArgs.second;
1632 uiccApp = uiccCard.getApplicationByType(appType);
1633 if (uiccApp == null) {
1634 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1635 request.result = -1;
1636 loge("Failed to get UICC App");
1637 notifyRequester(request);
1638 } else {
1639 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1640 ((SIMRecords) uiccApp.getIccRecords())
1641 .setForbiddenPlmns(onCompleted, fplmns);
1642 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001643 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001644 case CMD_ERASE_MODEM_CONFIG:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1647 defaultPhone.eraseModemConfig(onCompleted);
1648 break;
1649 case EVENT_ERASE_MODEM_CONFIG_DONE:
1650 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001651 break;
zoey chene02881a2019-12-30 16:11:23 +08001652
1653 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1654 request = (MainThreadRequest) msg.obj;
1655 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1656 Pair<String, String> changed = (Pair<String, String>) request.argument;
1657 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1658 changed.first, changed.second, onCompleted);
1659 break;
1660 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 if (ar.exception == null) {
1664 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1665 } else {
1666 request.result = msg.arg1;
1667 }
1668 notifyRequester(request);
1669 break;
1670
1671 case CMD_SET_ICC_LOCK_ENABLED:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1674 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1675 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1676 enabled.first, enabled.second, onCompleted);
1677 break;
1678 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 if (ar.exception == null) {
1682 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1683 } else {
1684 request.result = msg.arg1;
1685 }
1686 notifyRequester(request);
1687 break;
1688
Peter Wangdafb9ac2020-01-15 14:13:38 -08001689 case MSG_NOTIFY_USER_ACTIVITY:
1690 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001691 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001692 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1693 getDefaultPhone().getContext().sendBroadcastAsUser(
1694 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1695 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 default:
1697 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1698 break;
1699 }
1700 }
Jake Hambye994d462014-02-03 13:10:13 -08001701
Pengquan Menga1bb6272018-09-06 09:59:22 -07001702 private void notifyRequester(MainThreadRequest request) {
1703 synchronized (request) {
1704 request.notifyAll();
1705 }
1706 }
1707
Jake Hambye994d462014-02-03 13:10:13 -08001708 private void handleNullReturnEvent(Message msg, String command) {
1709 AsyncResult ar = (AsyncResult) msg.obj;
1710 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = true;
1713 } else {
1714 request.result = false;
1715 if (ar.exception instanceof CommandException) {
1716 loge(command + ": CommandException: " + ar.exception);
1717 } else {
1718 loge(command + ": Unknown exception");
1719 }
1720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001721 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
1725 /**
1726 * Posts the specified command to be executed on the main thread,
1727 * waits for the request to complete, and returns the result.
1728 * @see #sendRequestAsync
1729 */
1730 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001731 return sendRequest(
1732 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001733 }
1734
1735 /**
1736 * Posts the specified command to be executed on the main thread,
1737 * waits for the request to complete, and returns the result.
1738 * @see #sendRequestAsync
1739 */
1740 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1741 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001742 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001743 }
1744
1745 /**
1746 * Posts the specified command to be executed on the main thread,
1747 * waits for the request to complete, and returns the result.
1748 * @see #sendRequestAsync
1749 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001750 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001751 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001752 }
1753
1754 /**
1755 * Posts the specified command to be executed on the main thread,
1756 * waits for the request to complete, and returns the result.
1757 * @see #sendRequestAsync
1758 */
Nathan Harold92bed182018-10-12 18:16:49 -07001759 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1760 return sendRequest(command, argument, subId, null, workSource);
1761 }
1762
1763 /**
1764 * Posts the specified command to be executed on the main thread,
1765 * waits for the request to complete, and returns the result.
1766 * @see #sendRequestAsync
1767 */
1768 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1769 return sendRequest(
1770 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1771 }
1772
1773 /**
1774 * Posts the specified command to be executed on the main thread,
1775 * waits for the request to complete, and returns the result.
1776 * @see #sendRequestAsync
1777 */
1778 private Object sendRequest(
1779 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1781 throw new RuntimeException("This method will deadlock if called from the main thread.");
1782 }
1783
Nathan Harold92bed182018-10-12 18:16:49 -07001784 MainThreadRequest request = null;
1785 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1786 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1787 } else if (phone != null) {
1788 request = new MainThreadRequest(argument, phone, workSource);
1789 } else {
1790 request = new MainThreadRequest(argument, subId, workSource);
1791 }
1792
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 Message msg = mMainThreadHandler.obtainMessage(command, request);
1794 msg.sendToTarget();
1795
1796 // Wait for the request to complete
1797 synchronized (request) {
1798 while (request.result == null) {
1799 try {
1800 request.wait();
1801 } catch (InterruptedException e) {
1802 // Do nothing, go back and wait until the request is complete
1803 }
1804 }
1805 }
1806 return request.result;
1807 }
1808
1809 /**
1810 * Asynchronous ("fire and forget") version of sendRequest():
1811 * Posts the specified command to be executed on the main thread, and
1812 * returns immediately.
1813 * @see #sendRequest
1814 */
1815 private void sendRequestAsync(int command) {
1816 mMainThreadHandler.sendEmptyMessage(command);
1817 }
1818
1819 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001820 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001821 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001822 */
1823 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001824 sendRequestAsync(command, argument, null, null);
1825 }
1826
1827 /**
1828 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1829 * @see {@link #sendRequest(int,Object)}
1830 */
1831 private void sendRequestAsync(
1832 int command, Object argument, Phone phone, WorkSource workSource) {
1833 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001834 Message msg = mMainThreadHandler.obtainMessage(command, request);
1835 msg.sendToTarget();
1836 }
1837
1838 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 * Initialize the singleton PhoneInterfaceManager instance.
1840 * This is only done once, at startup, from PhoneApp.onCreate().
1841 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001842 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 synchronized (PhoneInterfaceManager.class) {
1844 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001845 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 } else {
1847 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1848 }
1849 return sInstance;
1850 }
1851 }
1852
1853 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001854 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001857 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001858 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1860 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001861 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001862 mTelephonySharedPreferences =
1863 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001864 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001865 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001866 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001867
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 publish();
1869 }
1870
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001871 private Phone getDefaultPhone() {
1872 Phone thePhone = getPhone(getDefaultSubscription());
1873 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 private void publish() {
1877 if (DBG) log("publish: " + this);
1878
Peter Wangc035ce42020-01-08 21:00:22 -08001879 TelephonyFrameworkInitializer
1880 .getTelephonyServiceManager()
1881 .getTelephonyServiceRegisterer()
1882 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Stuart Scott584921c2015-01-15 17:10:34 -08001885 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001886 if (request.phone != null) {
1887 return request.phone;
1888 } else {
1889 return getPhoneFromSubId(request.subId);
1890 }
1891 }
1892
1893 private Phone getPhoneFromSubId(int subId) {
1894 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1895 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001896 }
1897
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001898 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1899 Phone phone = getPhoneFromRequest(request);
1900 return phone == null ? null :
1901 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1902 }
1903
Wink Saville36469e72014-06-11 15:17:00 -07001904 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001905 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001906 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908
Naina Nallurid63128d2019-09-17 14:10:30 -07001909 private void sendEraseModemConfig(Phone phone) {
1910 if (phone != null) {
1911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1912 mApp, phone.getSubId(), "eraseModemConfig");
1913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1916 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
1919 }
1920 }
1921 }
1922
Peter Wang44b186e2020-01-13 23:33:09 -08001923 private boolean isImsAvailableOnDevice() {
1924 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1925 if (pm == null) {
1926 // For some reason package manger is not available.. This will fail internally anyway,
1927 // so do not throw error and allow.
1928 return true;
1929 }
1930 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1931 }
1932
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001934 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001935 }
1936
Wink Savilleb564aae2014-10-23 10:18:09 -07001937 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 if (DBG) log("dial: " + number);
1939 // No permission check needed here: This is just a wrapper around the
1940 // ACTION_DIAL intent, which is available to any app since it puts up
1941 // the UI before it does anything.
1942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 String url = createTelUrl(number);
1946 if (url == null) {
1947 return;
1948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001950 // PENDING: should we just silently fail if phone is offhook or ringing?
1951 PhoneConstants.State state = mCM.getState(subId);
1952 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1953 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1954 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1955 mApp.startActivity(intent);
1956 }
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960 }
1961
1962 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001963 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001964 }
1965
Wink Savilleb564aae2014-10-23 10:18:09 -07001966 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 if (DBG) log("call: " + number);
1968
1969 // This is just a wrapper around the ACTION_CALL intent, but we still
1970 // need to do a permission check since we're calling startActivity()
1971 // from the context of the phone app.
1972 enforceCallPermission();
1973
Jordan Liu1617b712019-07-10 15:06:26 -07001974 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 != AppOpsManager.MODE_ALLOWED) {
1976 return;
1977 }
1978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 String url = createTelUrl(number);
1982 if (url == null) {
1983 return;
1984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 boolean isValid = false;
1987 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1988 if (slist != null) {
1989 for (SubscriptionInfo subInfoRecord : slist) {
1990 if (subInfoRecord.getSubscriptionId() == subId) {
1991 isValid = true;
1992 break;
1993 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001994 }
Wink Saville08874612014-08-31 19:19:58 -07001995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 if (!isValid) {
1997 return;
1998 }
Wink Saville08874612014-08-31 19:19:58 -07001999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2001 intent.putExtra(SUBSCRIPTION_KEY, subId);
2002 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2003 mApp.startActivity(intent);
2004 } finally {
2005 Binder.restoreCallingIdentity(identity);
2006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
Wink Savilleb564aae2014-10-23 10:18:09 -07002009 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002010 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002011 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2012 }
2013
Wink Savilleb564aae2014-10-23 10:18:09 -07002014 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002015 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002016 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2017 }
2018
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2025 checkSimPin.start();
2026 return checkSimPin.unlockSim(null, pin);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
2029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Wink Savilleb564aae2014-10-23 10:18:09 -07002032 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034
2035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2038 checkSimPuk.start();
2039 return checkSimPuk.unlockSim(puk, pin);
2040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 }
2044
2045 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002046 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 * a synchronous one.
2048 */
2049 private static class UnlockSim extends Thread {
2050
2051 private final IccCard mSimCard;
2052
2053 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002054 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2055 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056
2057 // For replies from SimCard interface
2058 private Handler mHandler;
2059
2060 // For async handler to identify request type
2061 private static final int SUPPLY_PIN_COMPLETE = 100;
2062
2063 public UnlockSim(IccCard simCard) {
2064 mSimCard = simCard;
2065 }
2066
2067 @Override
2068 public void run() {
2069 Looper.prepare();
2070 synchronized (UnlockSim.this) {
2071 mHandler = new Handler() {
2072 @Override
2073 public void handleMessage(Message msg) {
2074 AsyncResult ar = (AsyncResult) msg.obj;
2075 switch (msg.what) {
2076 case SUPPLY_PIN_COMPLETE:
2077 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2078 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002079 mRetryCount = msg.arg1;
2080 if (ar.exception != null) {
2081 if (ar.exception instanceof CommandException &&
2082 ((CommandException)(ar.exception)).getCommandError()
2083 == CommandException.Error.PASSWORD_INCORRECT) {
2084 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002085 } //When UiccCardApp dispose,handle message and return exception
2086 else if (ar.exception instanceof CommandException &&
2087 ((CommandException) (ar.exception)).getCommandError()
2088 == CommandException.Error.ABORTED) {
2089 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002090 } else {
2091 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2092 }
2093 } else {
2094 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 mDone = true;
2097 UnlockSim.this.notifyAll();
2098 }
2099 break;
2100 }
2101 }
2102 };
2103 UnlockSim.this.notifyAll();
2104 }
2105 Looper.loop();
2106 }
2107
2108 /*
2109 * Use PIN or PUK to unlock SIM card
2110 *
2111 * If PUK is null, unlock SIM card with PIN
2112 *
2113 * If PUK is not null, unlock SIM card with PUK and set PIN code
2114 */
Wink Saville9de0f752013-10-22 19:04:03 -07002115 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116
2117 while (mHandler == null) {
2118 try {
2119 wait();
2120 } catch (InterruptedException e) {
2121 Thread.currentThread().interrupt();
2122 }
2123 }
2124 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2125
2126 if (puk == null) {
2127 mSimCard.supplyPin(pin, callback);
2128 } else {
2129 mSimCard.supplyPuk(puk, pin, callback);
2130 }
2131
2132 while (!mDone) {
2133 try {
2134 Log.d(LOG_TAG, "wait for done");
2135 wait();
2136 } catch (InterruptedException e) {
2137 // Restore the interrupted status
2138 Thread.currentThread().interrupt();
2139 }
2140 }
2141 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002142 int[] resultArray = new int[2];
2143 resultArray[0] = mResult;
2144 resultArray[1] = mRetryCount;
2145 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147 }
2148
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002149 /**
2150 * This method has been removed due to privacy and stability concerns.
2151 */
2152 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002154 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2155 return;
Wink Saville36469e72014-06-11 15:17:00 -07002156 }
2157
Nathan Harold1f889d82020-06-04 17:05:26 -07002158 @Override
2159 public void updateServiceLocationWithPackageName(String callingPackage) {
2160 mApp.getSystemService(AppOpsManager.class)
2161 .checkPackage(Binder.getCallingUid(), callingPackage);
2162
2163 final int targetSdk = getTargetSdk(callingPackage);
2164 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2165 // Callers targeting S have no business invoking this method.
2166 return;
2167 }
2168
2169 LocationAccessPolicy.LocationPermissionResult locationResult =
2170 LocationAccessPolicy.checkLocationPermission(mApp,
2171 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2172 .setCallingPackage(callingPackage)
2173 .setCallingFeatureId(null)
2174 .setCallingPid(Binder.getCallingPid())
2175 .setCallingUid(Binder.getCallingUid())
2176 .setMethod("updateServiceLocation")
2177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2178 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2179 .build());
2180 // Apps that lack location permission have no business calling this method;
2181 // however, because no permission was declared in the public API, denials must
2182 // all be "soft".
2183 switch (locationResult) {
2184 case DENIED_HARD: /* fall through */
2185 case DENIED_SOFT:
2186 return;
2187 }
2188
2189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 final long identity = Binder.clearCallingIdentity();
2191 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002192 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002194 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195 }
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002201 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 @Override
2203 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002204 return isRadioOnWithFeature(callingPackage, null);
2205 }
2206
2207
2208 @Override
2209 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2210 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2211 callingFeatureId);
2212 }
2213
2214 @Deprecated
2215 @Override
2216 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2217 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002221 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2222 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002224 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 return false;
2226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 return isRadioOnForSubscriber(subId);
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
2233 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 }
2235
2236 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 final Phone phone = getPhone(subId);
2240 if (phone != null) {
2241 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2242 } else {
2243 return false;
2244 }
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 }
2249
2250 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002251 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
Wink Saville36469e72014-06-11 15:17:00 -07002253
Wink Savilleb564aae2014-10-23 10:18:09 -07002254 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 if (phone != null) {
2261 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 }
Wink Saville36469e72014-06-11 15:17:00 -07002266 }
2267
2268 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002269 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
Wink Savilleb564aae2014-10-23 10:18:09 -07002272 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 if (phone == null) {
2279 return false;
2280 }
2281 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2282 toggleRadioOnOffForSubscriber(subId);
2283 }
2284 return true;
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
Wink Saville36469e72014-06-11 15:17:00 -07002289
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002290 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002291 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002292 /*
2293 * If any of the Radios are available, it will need to be
2294 * shutdown. So return true if any Radio is available.
2295 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2299 Phone phone = PhoneFactory.getPhone(i);
2300 if (phone != null && phone.isRadioAvailable()) return true;
2301 }
2302 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2303 return false;
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002306 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002307 }
2308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002310 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311 enforceModifyPermission();
2312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2316 logv("Shutting down Phone " + i);
2317 shutdownRadioUsingPhoneId(i);
2318 }
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002321 }
2322 }
2323
2324 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002325 Phone phone = PhoneFactory.getPhone(phoneId);
2326 if (phone != null && phone.isRadioAvailable()) {
2327 phone.shutdownRadio();
2328 }
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333
2334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2337 if (defaultPhone != null) {
2338 defaultPhone.setRadioPower(turnOn);
2339 return true;
2340 } else {
2341 loge("There's no default phone.");
2342 return false;
2343 }
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002346 }
Wink Saville36469e72014-06-11 15:17:00 -07002347 }
2348
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351
2352 final long identity = Binder.clearCallingIdentity();
2353 try {
2354 final Phone phone = getPhone(subId);
2355 if (phone != null) {
2356 phone.setRadioPower(turnOn);
2357 return true;
2358 } else {
2359 return false;
2360 }
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
Wink Saville36469e72014-06-11 15:17:00 -07002366 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 public boolean enableDataConnectivity() {
2369 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 int subId = mSubscriptionController.getDefaultDataSubId();
2374 final Phone phone = getPhone(subId);
2375 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002376 phone.getDataEnabledSettings().setDataEnabled(
2377 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 return true;
2379 } else {
2380 return false;
2381 }
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 }
2386
Wink Saville36469e72014-06-11 15:17:00 -07002387 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 public boolean disableDataConnectivity() {
2390 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391
2392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 int subId = mSubscriptionController.getDefaultDataSubId();
2395 final Phone phone = getPhone(subId);
2396 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002397 phone.getDataEnabledSettings().setDataEnabled(
2398 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 return true;
2400 } else {
2401 return false;
2402 }
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
Sanket Padawe356d7632015-06-22 14:03:32 -07002408 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002409 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002414 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 } else {
2416 return false;
2417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
2423 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002424 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002425 }
2426
pkanwarae03a6b2016-11-06 20:37:09 -08002427 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 enforceCallPermission();
2429
2430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2433 return;
2434 }
2435 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2436 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
2439 }
pkanwar32d516d2016-10-14 19:37:38 -07002440 };
2441
Wink Savilleb564aae2014-10-23 10:18:09 -07002442 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444
2445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2448 return false;
2449 }
2450 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002457 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
2459
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002460 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 Phone phone = PhoneFactory.getPhone(slotIndex);
2464 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2465 PhoneConstantConversions.convertCallState(phone.getState());
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Sanket Padawe356d7632015-06-22 14:03:32 -07002471 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002472 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002473 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2474 }
2475
2476 @Override
2477 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002480 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 if (phone != null) {
2482 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2483 } else {
2484 return PhoneConstantConversions.convertDataState(
2485 PhoneConstants.DataState.DISCONNECTED);
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002493 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002494 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2495 }
2496
2497 @Override
2498 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502 if (phone != null) {
2503 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2504 } else {
2505 return TelephonyManager.DATA_ACTIVITY_NONE;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
2512 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002513 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002514 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002515 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002516
2517 LocationAccessPolicy.LocationPermissionResult locationResult =
2518 LocationAccessPolicy.checkLocationPermission(mApp,
2519 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2520 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002521 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002522 .setCallingPid(Binder.getCallingPid())
2523 .setCallingUid(Binder.getCallingUid())
2524 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002525 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002526 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2527 .build());
2528 switch (locationResult) {
2529 case DENIED_HARD:
2530 throw new SecurityException("Not allowed to access cell location");
2531 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002532 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2533 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 }
2535
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002536 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002540 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002541 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Svetoslav64fad262015-04-14 14:35:21 -07002545 }
2546
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002548 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002549 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2550 // registered cell info, so return a NULL country instead.
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002553 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2554 // Get default phone in this case.
2555 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2556 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002557 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002559 if (phone == null) return "";
2560 ServiceStateTracker sst = phone.getServiceStateTracker();
2561 if (sst == null) return "";
2562 LocaleTracker lt = sst.getLocaleTracker();
2563 if (lt == null) return "";
2564 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2565 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2566 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002570 }
2571
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002572 /**
2573 * This method was removed due to potential issues caused by performing partial
2574 * updates of service state, and lack of a credible use case.
2575 *
2576 * This has the ability to break the telephony implementation by disabling notification of
2577 * changes in device connectivity. DO NOT USE THIS!
2578 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002579 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 public void enableLocationUpdates() {
2581 mApp.enforceCallingOrSelfPermission(
2582 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002585 /**
2586 * This method was removed due to potential issues caused by performing partial
2587 * updates of service state, and lack of a credible use case.
2588 *
2589 * This has the ability to break the telephony implementation by disabling notification of
2590 * changes in device connectivity. DO NOT USE THIS!
2591 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 @Override
2593 public void disableLocationUpdates() {
2594 mApp.enforceCallingOrSelfPermission(
2595 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 }
2597
Nathan Harold31d7ff32018-10-15 20:20:30 -07002598 /**
2599 * Returns the target SDK version number for a given package name.
2600 *
Nathan Haroldec184742019-07-10 17:04:16 -07002601 * This call MUST be invoked before clearing the calling UID.
2602 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002603 * @return target SDK if the package is found or INT_MAX.
2604 */
2605 private int getTargetSdk(String packageName) {
2606 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002607 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002608 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002609 if (ai != null) return ai.targetSdkVersion;
2610 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002611 loge("Failed to get package info for pkg="
2612 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002613 }
2614 return Integer.MAX_VALUE;
2615 }
2616
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 @Override
2618 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002619 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2620 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002621 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002622 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2623 throw new SecurityException(
2624 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2625 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002626
Jordan Liu1617b712019-07-10 15:06:26 -07002627 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2629 return null;
2630 }
Svetoslav64fad262015-04-14 14:35:21 -07002631
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002632 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002634 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002635 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636
Nathan Haroldf180aac2018-06-01 18:43:55 -07002637 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2638 for (CellInfo ci : info) {
2639 if (ci instanceof CellInfoGsm) {
2640 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2641 } else if (ci instanceof CellInfoWcdma) {
2642 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002645 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002648 private List<CellInfo> getCachedCellInfo() {
2649 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2650 for (Phone phone : PhoneFactory.getPhones()) {
2651 List<CellInfo> info = phone.getAllCellInfo();
2652 if (info != null) cellInfos.addAll(info);
2653 }
2654 return cellInfos;
2655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656
2657 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002658 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002659 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002660 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002661
2662 LocationAccessPolicy.LocationPermissionResult locationResult =
2663 LocationAccessPolicy.checkLocationPermission(mApp,
2664 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2665 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002666 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002667 .setCallingPid(Binder.getCallingPid())
2668 .setCallingUid(Binder.getCallingUid())
2669 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002670 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002671 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2672 .build());
2673 switch (locationResult) {
2674 case DENIED_HARD:
2675 throw new SecurityException("Not allowed to access cell info");
2676 case DENIED_SOFT:
2677 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002680 final int targetSdk = getTargetSdk(callingPackage);
2681 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2682 return getCachedCellInfo();
2683 }
2684
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002685 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2690 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002691 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002692 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 if (info != null) cellInfos.addAll(info);
2694 }
2695 return cellInfos;
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699 }
2700
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002701 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002702 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2703 String callingFeatureId) {
2704 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2705 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002706 }
2707
2708 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002709 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2710 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002711 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002712 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002713 }
2714
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002715 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2716 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002717 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002718 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002719
2720 LocationAccessPolicy.LocationPermissionResult locationResult =
2721 LocationAccessPolicy.checkLocationPermission(mApp,
2722 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2723 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002724 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002725 .setCallingPid(Binder.getCallingPid())
2726 .setCallingUid(Binder.getCallingUid())
2727 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002728 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2729 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002730 .build());
2731 switch (locationResult) {
2732 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002733 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2734 // Safetynet logging for b/154934934
2735 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2736 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002737 throw new SecurityException("Not allowed to access cell info");
2738 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002739 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2740 // Safetynet logging for b/154934934
2741 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2742 }
Nathan Harold5320c422019-05-09 10:26:08 -07002743 try {
2744 cb.onCellInfo(new ArrayList<CellInfo>());
2745 } catch (RemoteException re) {
2746 // Drop without consequences
2747 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002748 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002749 }
2750
Nathan Harolda939a962019-05-09 10:13:47 -07002751
2752 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002753 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2754
2755 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2756 }
2757
2758 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002760 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Shishir Agrawala9f32182016-04-12 12:00:16 -07002771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002772 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002773 Phone phone = PhoneFactory.getPhone(slotIndex);
2774 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002775 return null;
2776 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002777 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002778 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002779 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002780 return null;
2781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 return phone.getImei();
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002789 }
2790
2791 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002792 public String getTypeAllocationCodeForSlot(int slotIndex) {
2793 Phone phone = PhoneFactory.getPhone(slotIndex);
2794 String tac = null;
2795 if (phone != null) {
2796 String imei = phone.getImei();
2797 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2798 }
2799 return tac;
2800 }
2801
2802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002804 Phone phone = PhoneFactory.getPhone(slotIndex);
2805 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002806 return null;
2807 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002808
Jeff Davidson913390f2018-02-23 17:11:49 -08002809 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002810 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002811 callingPackage, callingFeatureId, "getMeidForSlot")) {
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.getMeid();
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Jack Yu2af8d712017-03-15 17:14:14 -07002821 }
2822
2823 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002824 public String getManufacturerCodeForSlot(int slotIndex) {
2825 Phone phone = PhoneFactory.getPhone(slotIndex);
2826 String manufacturerCode = null;
2827 if (phone != null) {
2828 String meid = phone.getMeid();
2829 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2830 }
2831 return manufacturerCode;
2832 }
2833
2834 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2836 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002837 Phone phone = PhoneFactory.getPhone(slotIndex);
2838 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 return null;
2840 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002841 int subId = phone.getSubId();
2842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 mApp, subId, callingPackage, callingFeatureId,
2844 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002845 return null;
2846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 return phone.getDeviceSvn();
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002854 }
2855
fionaxu43304da2017-11-27 22:51:16 -08002856 @Override
2857 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
2861 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
fionaxu43304da2017-11-27 22:51:16 -08002865 }
2866
2867 @Override
2868 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 final Phone phone = getPhone(subId);
2872 return phone == null ? null : phone.getCarrierName();
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
fionaxu43304da2017-11-27 22:51:16 -08002876 }
2877
calvinpanffe225e2018-11-01 19:43:06 +08002878 @Override
chen xu0026ca62019-03-06 15:28:50 -08002879 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002884 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
chen xu0026ca62019-03-06 15:28:50 -08002891 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002895 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
chen xu651eec72018-11-11 19:03:44 -08002901 @Override
chen xu864e11c2018-12-06 22:10:03 -08002902 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2903 if (!isSubscriptionMccMnc) {
2904 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2905 }
chen xu651eec72018-11-11 19:03:44 -08002906 final Phone phone = PhoneFactory.getPhone(slotIndex);
2907 if (phone == null) {
2908 return TelephonyManager.UNKNOWN_CARRIER_ID;
2909 }
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
2916 }
2917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 //
2919 // Internal helper methods.
2920 //
2921
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002922 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2924 *
2925 * @throws SecurityException if the caller does not have the required permission
2926 */
2927 private void enforceModifyPermission() {
2928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2929 }
2930
Shuo Qiancd19c462020-01-16 20:51:11 -08002931 /**
2932 * Make sure the caller is system.
2933 *
2934 * @throws SecurityException if the caller is not system.
2935 */
2936 private void enforceSystemCaller() {
2937 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2938 throw new SecurityException("Caller must be system");
2939 }
2940 }
2941
Shuo Qian3b6ee772019-11-13 17:43:31 -08002942 private void enforceActiveEmergencySessionPermission() {
2943 mApp.enforceCallingOrSelfPermission(
2944 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2945 }
2946
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 /**
2948 * Make sure the caller has the CALL_PHONE permission.
2949 *
2950 * @throws SecurityException if the caller does not have the required permission
2951 */
2952 private void enforceCallPermission() {
2953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2954 }
2955
paulhu5a773602019-08-23 19:17:33 +08002956 private void enforceSettingsPermission() {
2957 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002958 }
2959
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 private String createTelUrl(String number) {
2961 if (TextUtils.isEmpty(number)) {
2962 return null;
2963 }
2964
Jake Hambye994d462014-02-03 13:10:13 -08002965 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
2967
Ihab Awadf9e92732013-12-05 18:02:52 -08002968 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2970 }
2971
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002972 private static void logv(String msg) {
2973 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2974 }
2975
Ihab Awadf9e92732013-12-05 18:02:52 -08002976 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2978 }
2979
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002980 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002982 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002983 }
2984
Sanket Padawe356d7632015-06-22 14:03:32 -07002985 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002986 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 final Phone phone = PhoneFactory.getPhone(slotIndex);
2990 if (phone == null) {
2991 return PhoneConstants.PHONE_TYPE_NONE;
2992 } else {
2993 return phone.getPhoneType();
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 }
2999
3000 /**
3001 * Returns the CDMA ERI icon index to display
3002 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003004 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3005 return getCdmaEriIconIndexForSubscriber(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 getCdmaEriIconIndexForSubscriber(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 "getCdmaEriIconIndexForSubscriber")) {
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.getCdmaEriIconIndex();
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 icon mode,
3033 * 0 - ON
3034 * 1 - FLASHING
3035 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003037 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3038 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3039 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003040 }
3041
Sanket Padawe356d7632015-06-22 14:03:32 -07003042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003043 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3044 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003046 mApp, subId, callingPackage, callingFeatureId,
3047 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003048 return -1;
3049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 final Phone phone = getPhone(subId);
3054 if (phone != null) {
3055 return phone.getCdmaEriIconMode();
3056 } else {
3057 return -1;
3058 }
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
3064 /**
3065 * Returns the CDMA ERI text,
3066 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003068 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3069 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3070 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003071 }
3072
Sanket Padawe356d7632015-06-22 14:03:32 -07003073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003074 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3075 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003077 mApp, subId, callingPackage, callingFeatureId,
3078 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003079 return null;
3080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 return phone.getCdmaEriText();
3087 } else {
3088 return null;
3089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 }
3094
3095 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003096 * Returns the CDMA MDN.
3097 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003099 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3101 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 return phone.getLine1Number();
3108 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 return null;
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003114 }
3115 }
3116
3117 /**
3118 * Returns the CDMA MIN.
3119 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003120 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003121 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3123 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
3128 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3129 return phone.getCdmaMin();
3130 } else {
3131 return null;
3132 }
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003135 }
3136 }
3137
Hall Liud892bec2018-11-30 14:51:45 -08003138 @Override
3139 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3140 INumberVerificationCallback callback, String callingPackage) {
3141 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3142 != PERMISSION_GRANTED) {
3143 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3144 }
3145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3146
3147 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3148 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3149 throw new SecurityException("Calling package must be configured in the device config");
3150 }
3151
3152 if (range == null) {
3153 throw new NullPointerException("Range must be non-null");
3154 }
3155
3156 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003157 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003158
3159 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3160 }
3161
Junda Liuca05d5d2014-08-14 22:36:34 -07003162 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 * Returns true if CDMA provisioning needs to run.
3164 */
3165 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003175 * Sets the voice mail number of a given subId.
3176 */
3177 @Override
3178 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003179 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3180 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3185 new Pair<String, String>(alphaTag, number), new Integer(subId));
3186 return success;
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003190 }
3191
Ta-wei Yen87c49842016-05-13 21:19:52 -07003192 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003193 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003195 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3196 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003197 if (!TextUtils.equals(callingPackage, systemDialer)) {
3198 throw new SecurityException("caller must be system dialer");
3199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3204 if (phoneAccountHandle == null) {
3205 return null;
3206 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003210 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003211 }
3212
3213 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003214 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3215 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003216 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003218 mApp, subId, callingPackage, callingFeatureId,
3219 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003220 return null;
3221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003229 }
3230
3231 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003232 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3233 VisualVoicemailSmsFilterSettings settings) {
3234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003243 }
3244
3245 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003246 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248
3249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003256 }
3257
3258 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003259 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3260 String callingPackage, int subId) {
3261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003270 }
3271
3272 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003273 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003283 }
3284
3285 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003286 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3287 String callingAttributionTag, int subId, String number, int port, String text,
3288 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003290 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003291 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003292 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003293 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3294 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003295 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003296
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003297 /**
fionaxu0152e512016-11-14 13:36:14 -08003298 * Sets the voice activation state of a given subId.
3299 */
3300 @Override
3301 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3303 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 if (phone != null) {
3309 phone.setVoiceActivationState(activationState);
3310 } else {
3311 loge("setVoiceActivationState fails with invalid subId: " + subId);
3312 }
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003315 }
3316 }
3317
3318 /**
3319 * Sets the data activation state of a given subId.
3320 */
3321 @Override
3322 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3324 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
3329 if (phone != null) {
3330 phone.setDataActivationState(activationState);
3331 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003332 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 }
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003336 }
3337 }
3338
3339 /**
3340 * Returns the voice activation state of a given subId.
3341 */
3342 @Override
3343 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345
fionaxu0152e512016-11-14 13:36:14 -08003346 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (phone != null) {
3350 return phone.getVoiceActivationState();
3351 } else {
3352 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3353 }
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003356 }
3357 }
3358
3359 /**
3360 * Returns the data activation state of a given subId.
3361 */
3362 @Override
3363 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365
fionaxu0152e512016-11-14 13:36:14 -08003366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 if (phone != null) {
3370 return phone.getDataActivationState();
3371 } else {
3372 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3373 }
3374 } finally {
3375 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003376 }
3377 }
3378
3379 /**
Wink Saville36469e72014-06-11 15:17:00 -07003380 * Returns the unread count of voicemails for a subId
3381 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003382 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003383 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3384 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003386 mApp, subId, callingPackage, callingFeatureId,
3387 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003388 return 0;
3389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 final Phone phone = getPhone(subId);
3393 if (phone != null) {
3394 return phone.getVoiceMessageCount();
3395 } else {
3396 return 0;
3397 }
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
3402
3403 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003404 * returns true, if the device is in a state where both voice and data
3405 * are supported simultaneously. This can change based on location or network condition.
3406 */
3407 @Override
3408 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 final Phone phone = getPhone(subId);
3412 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003416 }
3417
3418 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003419 * Send the dialer code if called from the current default dialer or the caller has
3420 * carrier privilege.
3421 * @param inputCode The dialer code to send
3422 */
3423 @Override
3424 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003427 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3428 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003429 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003430 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003431 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
fionaxu235cc5e2017-03-06 22:25:57 -08003440 }
3441
Pengquan Menga1bb6272018-09-06 09:59:22 -07003442 @Override
3443 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003444 TelephonyPermissions
3445 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3446 mApp, subId, "getNetworkSelectionMode");
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 if (!isActiveSubscription(subId)) {
3450 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3451 }
3452 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003455 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003456 }
3457
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003459 public boolean isInEmergencySmsMode() {
3460 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 for (Phone phone : PhoneFactory.getPhones()) {
3464 if (phone.isInEmergencySmsMode()) {
3465 return true;
3466 }
3467 }
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 return false;
3472 }
3473
shilu366312e2019-12-17 09:28:10 -08003474 /**
3475 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3476 * @param subId The subscription to use to check the configuration.
3477 * @param c The callback that will be used to send the result.
3478 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003479 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003480 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3481 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003482 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3483 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003484
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003485 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3487 "IMS not available on device.");
3488 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 final long token = Binder.clearCallingIdentity();
3490 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003491 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003494 } catch (ImsException e) {
3495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 } finally {
3497 Binder.restoreCallingIdentity(token);
3498 }
3499 }
3500
shilu366312e2019-12-17 09:28:10 -08003501 /**
3502 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3503 * @param subId The subscription to use to check the configuration.
3504 * @param c The callback that will be used to send the result.
3505 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003507 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003508 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3509 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003510 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3511 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3512 }
Meng Wangafbc5852019-09-19 17:37:13 -07003513 final long token = Binder.clearCallingIdentity();
3514 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003515 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003516 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3517 .removeRegistrationCallbackForSubscription(c, subId);
3518 } catch (ImsException e) {
3519 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3520 + "is inactive, ignoring unregister.");
3521 // If the subscription is no longer active, just return, since the callback
3522 // will already have been removed internally.
3523 } finally {
3524 Binder.restoreCallingIdentity(token);
3525 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 }
3527
Brad Ebingera34a6c22019-10-22 17:36:18 -07003528 /**
3529 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3530 */
3531 @Override
3532 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3533 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3534 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.getImsRegistrationState(regState -> {
3547 try {
3548 consumer.accept((regState == null)
3549 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3550 } catch (RemoteException e) {
3551 // Ignore if the remote process is no longer available to call back.
3552 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3553 }
3554 });
3555 } finally {
3556 Binder.restoreCallingIdentity(token);
3557 }
3558 }
3559
3560 /**
3561 * Get the transport type for the IMS service registration state.
3562 */
3563 @Override
3564 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003565 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3566 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003567 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3568 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3569 "IMS not available on device.");
3570 }
3571 final long token = Binder.clearCallingIdentity();
3572 try {
3573 Phone phone = getPhone(subId);
3574 if (phone == null) {
3575 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3576 + subId + "'");
3577 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3578 }
3579 phone.getImsRegistrationTech(regTech -> {
3580 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3581 int regTechConverted = (regTech == null)
3582 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3583 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3584 regTechConverted);
3585 try {
3586 consumer.accept(regTechConverted);
3587 } catch (RemoteException e) {
3588 // Ignore if the remote process is no longer available to call back.
3589 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3590 }
3591 });
3592 } finally {
3593 Binder.restoreCallingIdentity(token);
3594 }
3595 }
3596
shilu366312e2019-12-17 09:28:10 -08003597 /**
3598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3599 * @param subId The subscription to use to check the configuration.
3600 * @param c The callback that will be used to send the result.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003603 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3604 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003605 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3606 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003607 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3608 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3609 "IMS not available on device.");
3610 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3612 final long token = Binder.clearCallingIdentity();
3613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003614 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003616 } catch (ImsException e) {
3617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 } finally {
3619 Binder.restoreCallingIdentity(token);
3620 }
3621 }
3622
shilu366312e2019-12-17 09:28:10 -08003623 /**
3624 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3625 * @param subId The subscription to use to check the configuration.
3626 * @param c The callback that will be used to send the result.
3627 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003629 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003630 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3631 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3633 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3634 }
Meng Wangafbc5852019-09-19 17:37:13 -07003635
3636 final long token = Binder.clearCallingIdentity();
3637 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003638 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003639 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003640 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003641 } catch (ImsException e) {
3642 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3643 + "is inactive, ignoring unregister.");
3644 // If the subscription is no longer active, just return, since the callback
3645 // will already have been removed internally.
3646 } finally {
3647 Binder.restoreCallingIdentity(token);
3648 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 }
3650
3651 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003652 public boolean isCapable(int subId, int capability, int regTech) {
3653 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3655 final long token = Binder.clearCallingIdentity();
3656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3661 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003663 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3664 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 } finally {
3666 Binder.restoreCallingIdentity(token);
3667 }
3668 }
3669
3670 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003671 public boolean isAvailable(int subId, int capability, int regTech) {
3672 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 final long token = Binder.clearCallingIdentity();
3674 try {
3675 Phone phone = getPhone(subId);
3676 if (phone == null) return false;
3677 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003678 } catch (com.android.ims.ImsException e) {
3679 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3680 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 } finally {
3682 Binder.restoreCallingIdentity(token);
3683 }
3684 }
3685
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003686 /**
3687 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3688 * subscription.
3689 * @param subId The subscription to use to check the configuration.
3690 * @param callback The callback that will be used to send the result.
3691 * @param capability The MmTelFeature capability that will be used to send the result.
3692 * @param transportType The transport type of the MmTelFeature capability.
3693 */
3694 @Override
3695 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3696 int transportType) {
3697 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3698 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3699 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3700 "IMS not available on device.");
3701 }
3702 final long token = Binder.clearCallingIdentity();
3703 try {
3704 int slotId = getSlotIndex(subId);
3705 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3706 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3707 + subId + "'");
3708 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3709 }
3710 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3711 transportType, aBoolean -> {
3712 try {
3713 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3714 } catch (RemoteException e) {
3715 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3716 + "running. Ignore");
3717 }
3718 });
3719 } finally {
3720 Binder.restoreCallingIdentity(token);
3721 }
3722 }
3723
shilu366312e2019-12-17 09:28:10 -08003724 /**
3725 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3726 * @param subId The subscription to use to check the configuration.
3727 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 @Override
3729 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003730 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3731 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003732
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3734 final long token = Binder.clearCallingIdentity();
3735 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003736 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003738 } catch (ImsException e) {
3739 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 } finally {
3741 Binder.restoreCallingIdentity(token);
3742 }
3743 }
3744
3745 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003746 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003748 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 } catch (ImsException e) {
3755 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
shilu366312e2019-12-17 09:28:10 -08003761 /**
3762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3763 * @param subId The subscription to use to check the configuration.
3764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003766 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003767 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3768 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003772 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3773 } catch (ImsException e) {
3774 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
3778 }
3779
3780 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003781 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003783 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003788 } catch (ImsException e) {
3789 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
3793 }
3794
shilu366312e2019-12-17 09:28:10 -08003795 /**
3796 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3797 * @param subId The subscription to use to check the configuration.
3798 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 @Override
3800 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003801 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3802 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003806 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003808 } catch (ImsException e) {
3809 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
3813 }
3814
3815 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003816 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003818 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003823 } catch (ImsException e) {
3824 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 }
3829
shilu366312e2019-12-17 09:28:10 -08003830 /**
3831 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3832 * @param subId The subscription to use to check the configuration.
3833 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 @Override
3835 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003836 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3837 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003841 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003843 } catch (ImsException e) {
3844 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003851 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003853 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003857 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003859 } catch (ImsException e) {
3860 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
3866 @Override
3867 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3869 "setVoWiFiNonPersistent");
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003873 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003874 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 } catch (ImsException e) {
3876 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
3880 }
3881
shilu366312e2019-12-17 09:28:10 -08003882 /**
3883 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3884 * @param subId The subscription to use to check the configuration.
3885 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 @Override
3887 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003888 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3889 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003893 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003895 } catch (ImsException e) {
3896 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
3900 }
3901
3902 @Override
3903 public void setVoWiFiModeSetting(int subId, int mode) {
3904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3905 "setVoWiFiModeSetting");
3906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916 }
3917
3918 @Override
3919 public int getVoWiFiRoamingModeSetting(int subId) {
3920 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (ImsException e) {
3927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 }
3932
3933 @Override
3934 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3936 "setVoWiFiRoamingModeSetting");
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003942 } catch (ImsException e) {
3943 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 }
3948
3949 @Override
3950 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3952 "setRttCapabilityEnabled");
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003956 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 @Override
3969 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3971 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003977 } catch (ImsException e) {
3978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003984 @Override
3985 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3986 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003989 if (!isImsAvailableOnDevice()) {
3990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3991 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003992 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003994 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003995 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (ImsException e) {
3997 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
4001 }
4002
4003 @Override
4004 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4005 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4006 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4009 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004013 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004015 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4016 + "is inactive, ignoring unregister.");
4017 // If the subscription is no longer active, just return, since the callback will already
4018 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
4022 }
4023
allenwtsu99c623b2020-01-03 18:24:23 +08004024
4025 private void checkModifyPhoneStatePermission(int subId, String message) {
4026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4027 message);
4028 }
4029
4030 private boolean isImsProvisioningRequired(int subId, int capability,
4031 boolean isMmtelCapability) {
4032 Phone phone = getPhone(subId);
4033 if (phone == null) {
4034 loge("phone instance null for subid " + subId);
4035 return false;
4036 }
4037 if (isMmtelCapability) {
4038 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4039 return false;
4040 }
4041 } else {
4042 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4043 return false;
4044 }
4045 }
4046 return true;
4047 }
4048
4049 @Override
4050 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4051 boolean isProvisioned) {
4052 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4053
4054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4057 if (!isImsProvisioningRequired(subId, capability, false)) {
4058 return;
4059 }
4060
4061 // this capability requires provisioning, route to the correct API.
4062 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4063 switch (capability) {
4064 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4065 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4066 ims.setEabProvisioned(isProvisioned);
4067 break;
4068 default: {
4069 throw new IllegalArgumentException("Tried to set provisioning for "
4070 + "rcs capability '" + capability + "', which does not require "
4071 + "provisioning.");
4072 }
4073 }
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
4077
4078 }
4079
4080
4081 @Override
4082 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4083 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4087 if (!isImsProvisioningRequired(subId, capability, false)) {
4088 return true;
4089 }
4090
4091 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4092 switch (capability) {
4093 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4095 return ims.isEabProvisionedOnDevice();
4096
4097 default: {
4098 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4099 + "capability '" + capability + "', which does not require "
4100 + "provisioning.");
4101 }
4102 }
4103
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
4107 }
4108
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004109 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4111 boolean isProvisioned) {
4112 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4113 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4114 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4115 }
allenwtsu99c623b2020-01-03 18:24:23 +08004116 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004120 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 return;
4122 }
4123
4124 // this capability requires provisioning, route to the correct API.
4125 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4126 switch (capability) {
4127 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4128 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4129 ims.setVolteProvisioned(isProvisioned);
4130 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4131 ims.setWfcProvisioned(isProvisioned);
4132 }
4133 break;
4134 }
4135 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4136 // There is currently no difference in VT provisioning type.
4137 ims.setVtProvisioned(isProvisioned);
4138 break;
4139 }
4140 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4141 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4142 // change the capability of the feature instead if needed.
4143 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4144 == isProvisioned) {
4145 // No change in provisioning.
4146 return;
4147 }
4148 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4149 try {
4150 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4153 + ", Exception" + e.getMessage());
4154 }
4155 break;
4156 }
4157 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004158 throw new IllegalArgumentException("Tried to set provisioning for "
4159 + "MmTel capability '" + capability + "', which does not require "
4160 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004161 }
4162 }
4163
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 @Override
4170 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4171 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4172 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4173 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4174 }
4175 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004179 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 return true;
4181 }
4182
4183 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4184 switch (capability) {
4185 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4186 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4187 return ims.isVolteProvisionedOnDevice();
4188 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4189 return ims.isWfcProvisionedOnDevice();
4190 }
4191 // This should never happen, since we are checking tech above to make sure it
4192 // is either LTE or IWLAN.
4193 throw new IllegalArgumentException("Invalid radio technology for voice "
4194 + "capability.");
4195 }
4196 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4197 // There is currently no difference in VT provisioning type.
4198 return ims.isVtProvisionedOnDevice();
4199 }
4200 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4201 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4202 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4203 }
4204 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004205 throw new IllegalArgumentException(
4206 "Tried to get provisioning for MmTel capability '" + capability
4207 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004208 }
4209 }
4210
4211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
4214 }
4215
4216 @Override
4217 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4218 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4219 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4220 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4221 }
4222 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4223 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4224 return (provisionedBits & capability) > 0;
4225 }
4226
4227 @Override
4228 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4229 boolean isProvisioned) {
4230 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4231 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4232 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4233 }
4234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4235 "setProvisioningStatusForCapability");
4236 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4237 // If the current provisioning status for capability already matches isProvisioned,
4238 // do nothing.
4239 if (((provisionedBits & capability) > 0) == isProvisioned) {
4240 return;
4241 }
4242 if (isProvisioned) {
4243 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4244 } else {
4245 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4246 }
4247 }
4248
4249 /**
4250 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4251 * technology. The bitfield should mirror the bitfield defined by
4252 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4253 */
4254 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4255 String key = getMmTelProvisioningKey(subId, tech);
4256 // Default is no capabilities are provisioned.
4257 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4258 }
4259
4260 /**
4261 * Sets the MmTel capability provisioning bitfield (defined by
4262 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4263 * technology specified.
4264 *
4265 * Note: This is a synchronous command and should not be called on UI thread.
4266 */
4267 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4268 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4269 String key = getMmTelProvisioningKey(subId, tech);
4270 editor.putInt(key, newField);
4271 editor.commit();
4272 }
4273
4274 private static String getMmTelProvisioningKey(int subId, int tech) {
4275 // resulting key is provision_ims_mmtel_{subId}_{tech}
4276 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4277 }
4278
4279 /**
4280 * Query CarrierConfig to see if the specified capability requires provisioning for the
4281 * carrier associated with the subscription id.
4282 */
4283 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4284 int capability) {
4285 CarrierConfigManager configManager = new CarrierConfigManager(context);
4286 PersistableBundle c = configManager.getConfigForSubId(subId);
4287 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004288 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004289 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4290 false);
4291 boolean requireVoiceVtProvisioning = c.getBoolean(
4292 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4293
4294 // First check to make sure that the capability requires provisioning.
4295 switch (capability) {
4296 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4297 // intentional fallthrough
4298 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4299 if (requireVoiceVtProvisioning) {
4300 // Voice and Video requires provisioning
4301 return true;
4302 }
4303 break;
4304 }
4305 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4306 if (requireUtProvisioning) {
4307 // UT requires provisioning
4308 return true;
4309 }
4310 break;
4311 }
4312 }
4313 return false;
4314 }
4315
allenwtsu99c623b2020-01-03 18:24:23 +08004316 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4317 int capability) {
4318 CarrierConfigManager configManager = new CarrierConfigManager(context);
4319 PersistableBundle c = configManager.getConfigForSubId(subId);
4320
4321 boolean requireRcsProvisioning = c.getBoolean(
4322 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4323
4324 // First check to make sure that the capability requires provisioning.
4325 switch (capability) {
4326 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4327 // intentional fallthrough
4328 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4329 if (requireRcsProvisioning) {
4330 // OPTION or PRESENCE requires provisioning
4331 return true;
4332 }
4333 break;
4334 }
4335 }
4336 return false;
4337 }
4338
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004339 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004340 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4342 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4343 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004344 enforceReadPrivilegedPermission("getImsProvisioningInt");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 int slotId = getSlotIndex(subId);
4349 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4350 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4351 + subId + "' for key:" + key);
4352 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4353 }
4354 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004356 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4357 + subId + "' for key:" + key);
4358 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
4364 @Override
4365 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4367 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4368 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004369 enforceReadPrivilegedPermission("getImsProvisioningString");
4370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 int slotId = getSlotIndex(subId);
4374 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4375 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4376 + subId + "' for key:" + key);
4377 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4378 }
4379 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004381 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4382 + subId + "' for key:" + key);
4383 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
4389 @Override
4390 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004391 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4392 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4393 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4395 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004399 int slotId = getSlotIndex(subId);
4400 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4401 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4402 + subId + "' for key:" + key);
4403 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4404 }
4405 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004406 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4408 + "' for key:" + key);
4409 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
4415 @Override
4416 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4418 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4419 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4421 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425 int slotId = getSlotIndex(subId);
4426 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4427 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4428 + subId + "' for key:" + key);
4429 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4430 }
4431 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004432 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004433 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4434 + "' for key:" + key);
4435 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
4439 }
4440
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004441 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 int slotId = SubscriptionManager.getSlotIndex(subId);
4443 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004444 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4445 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 }
4447 return slotId;
4448 }
4449
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004450 private int getSlotIndex(int subId) {
4451 int slotId = SubscriptionManager.getSlotIndex(subId);
4452 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4453 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4454 }
4455 return slotId;
4456 }
4457
Wink Saville36469e72014-06-11 15:17:00 -07004458 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004459 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004460 */
4461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004462 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4463 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004464 final int targetSdk = getTargetSdk(callingPackage);
4465 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004467 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004468 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004469 mApp, subId, callingPackage, callingFeatureId,
4470 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004471 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4472 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 final Phone phone = getPhone(subId);
4477 if (phone != null) {
4478 return phone.getServiceState().getDataNetworkType();
4479 } else {
4480 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004485 }
4486
4487 /**
4488 * Returns the data network type
4489 */
4490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004491 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4492 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4493 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004494 }
4495
4496 /**
4497 * Returns the data network type for a subId
4498 */
4499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004500 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4501 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004503 mApp, subId, callingPackage, callingFeatureId,
4504 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004505 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4506 }
4507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 final Phone phone = getPhone(subId);
4511 if (phone != null) {
4512 return phone.getServiceState().getDataNetworkType();
4513 } else {
4514 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4515 }
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004519 }
4520
4521 /**
Wink Saville36469e72014-06-11 15:17:00 -07004522 * Returns the Voice network type for a subId
4523 */
4524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004525 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4526 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004528 mApp, subId, callingPackage, callingFeatureId,
4529 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004530 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4531 }
4532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 final Phone phone = getPhone(subId);
4536 if (phone != null) {
4537 return phone.getServiceState().getVoiceNetworkType();
4538 } else {
4539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4540 }
4541 } finally {
4542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004544 }
4545
4546 /**
4547 * @return true if a ICC card is present
4548 */
4549 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004550 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004551 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4552 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004553 }
4554
4555 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004556 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004557 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004558 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004559 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 final Phone phone = PhoneFactory.getPhone(slotIndex);
4563 if (phone != null) {
4564 return phone.getIccCard().hasIccCard();
4565 } else {
4566 return false;
4567 }
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004571 }
4572
4573 /**
4574 * Return if the current radio is LTE on CDMA. This
4575 * is a tri-state return value as for a period of time
4576 * the mode may be unknown.
4577 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004578 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004579 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004580 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004581 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004583 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4584 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4585 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004586 }
4587
Sanket Padawe356d7632015-06-22 14:03:32 -07004588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004589 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4590 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004591 try {
4592 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4593 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004594 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4595 }
4596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 final long identity = Binder.clearCallingIdentity();
4598 try {
4599 final Phone phone = getPhone(subId);
4600 if (phone == null) {
4601 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4602 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004603 return TelephonyProperties.lte_on_cdma_device()
4604 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 }
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004608 }
Wink Saville36469e72014-06-11 15:17:00 -07004609 }
4610
Wink Saville36469e72014-06-11 15:17:00 -07004611 /**
4612 * {@hide}
4613 * Returns Default subId, 0 in the case of single standby.
4614 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004615 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004616 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004617 }
4618
Shishir Agrawala9f32182016-04-12 12:00:16 -07004619 private int getSlotForDefaultSubscription() {
4620 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4621 }
4622
Wink Savilleb564aae2014-10-23 10:18:09 -07004623 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004624 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004625 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004626
Pengquan Menge92a50d2018-09-21 15:54:48 -07004627 private boolean isActiveSubscription(int subId) {
4628 return mSubscriptionController.isActiveSubId(subId);
4629 }
4630
Ihab Awadf2177b72013-11-25 13:33:23 -08004631 /**
4632 * @see android.telephony.TelephonyManager.WifiCallingChoices
4633 */
4634 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004637 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4639 getWhenToMakeWifiCallsDefaultPreference());
4640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004643 }
4644
4645 /**
4646 * @see android.telephony.TelephonyManager.WifiCallingChoices
4647 */
4648 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004652 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004657 }
4658
Sailesh Nepald1e68152013-12-12 19:08:02 -08004659 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004660 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004661 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004662 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004663
Jordan Liu4c733742019-02-28 12:03:40 -08004664 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4665 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4666 if (phoneId == -1) {
4667 throw new IllegalArgumentException("Given slot index: " + slotIndex
4668 + " does not correspond to an active phone");
4669 }
4670 return PhoneFactory.getPhone(phoneId);
4671 }
4672
Shishir Agrawal566b7612013-10-28 14:41:00 -07004673 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004674 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4675 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4677 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004679 if (DBG) {
4680 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4681 }
4682 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4683 p2);
4684 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004685
Jordan Liu4c733742019-02-28 12:03:40 -08004686
4687 @Override
4688 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4689 int slotIndex, String callingPackage, String aid, int p2) {
4690 enforceModifyPermission();
4691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4692 if (DBG) {
4693 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4694 }
4695 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4696 callingPackage, aid, p2);
4697 }
4698
4699 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4700 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 if (TextUtils.equals(ISDR_AID, aid)) {
4704 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004705 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4706 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 if (bestComponent == null
4708 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4709 loge("The calling package is not allowed to access ISD-R.");
4710 throw new SecurityException(
4711 "The calling package is not allowed to access ISD-R.");
4712 }
Derek Tan740e1672017-06-27 14:56:27 -07004713 }
Derek Tan740e1672017-06-27 14:56:27 -07004714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004716 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4717 null /* workSource */);
4718 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 return response;
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004723 }
4724
4725 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004726 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4728 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004729 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4730 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004732
Jordan Liu4c733742019-02-28 12:03:40 -08004733 @Override
4734 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4735 enforceModifyPermission();
4736 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4737 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4738 channel);
4739 }
4740
4741 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 if (channel < 0) {
4745 return false;
4746 }
Jordan Liu4c733742019-02-28 12:03:40 -08004747 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4748 null /* workSource */);
4749 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 return success;
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004754 }
4755
4756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004757 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004758 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4760 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004761 if (DBG) {
4762 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4763 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4764 + p3 + " data=" + data);
4765 }
4766 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4767 command, p1, p2, p3, data);
4768 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004769
Jordan Liu4c733742019-02-28 12:03:40 -08004770 @Override
4771 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4772 int command, int p1, int p2, int p3, String data) {
4773 enforceModifyPermission();
4774 if (DBG) {
4775 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4776 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4777 + p3 + " data=" + data);
4778 }
4779 return iccTransmitApduLogicalChannelWithPermission(
4780 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4781 data);
4782 }
4783
4784 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4785 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 final long identity = Binder.clearCallingIdentity();
4787 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004788 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 return "";
4790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004793 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4794 null /* workSource */);
4795 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 // Append the returned status code to the end of the response payload.
4798 String s = Integer.toHexString(
4799 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4800 if (response.payload != null) {
4801 s = IccUtils.bytesToHexString(response.payload) + s;
4802 }
4803 return s;
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004806 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004807 }
Jake Hambye994d462014-02-03 13:10:13 -08004808
Evan Charltonc66da362014-05-16 14:06:40 -07004809 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004810 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4811 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4813 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004815 if (DBG) {
4816 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4817 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4818 }
4819 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4820 cla, command, p1, p2, p3, data);
4821 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004822
Jordan Liu4c733742019-02-28 12:03:40 -08004823 @Override
4824 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4825 int command, int p1, int p2, int p3, String data) {
4826 enforceModifyPermission();
4827 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4828 if (DBG) {
4829 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4830 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4831 + " data=" + data);
4832 }
4833
4834 return iccTransmitApduBasicChannelWithPermission(
4835 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4836 p2, p3, data);
4837 }
4838
4839 // open APDU basic channel assuming the caller has sufficient permissions
4840 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4841 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4845 && TextUtils.equals(ISDR_AID, data)) {
4846 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004847 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4848 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 if (bestComponent == null
4850 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4851 loge("The calling package is not allowed to select ISD-R.");
4852 throw new SecurityException(
4853 "The calling package is not allowed to select ISD-R.");
4854 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004855 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004858 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4859 null /* workSource */);
4860 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 // Append the returned status code to the end of the response payload.
4863 String s = Integer.toHexString(
4864 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4865 if (response.payload != null) {
4866 s = IccUtils.bytesToHexString(response.payload) + s;
4867 }
4868 return s;
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004871 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004872 }
4873
4874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004875 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004876 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4878 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 if (DBG) {
4883 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4884 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4885 }
4886
4887 IccIoResult response =
4888 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4889 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4890 subId);
4891
4892 if (DBG) {
4893 log("Exchange SIM_IO [R]" + response);
4894 }
4895
4896 byte[] result = null;
4897 int length = 2;
4898 if (response.payload != null) {
4899 length = 2 + response.payload.length;
4900 result = new byte[length];
4901 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4902 } else {
4903 result = new byte[length];
4904 }
4905
4906 result[length - 1] = (byte) response.sw2;
4907 result[length - 2] = (byte) response.sw1;
4908 return result;
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004911 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004912 }
4913
Nathan Haroldb3014052017-01-25 15:57:32 -08004914 /**
4915 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4916 * on a particular subscription
4917 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004918 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4919 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004921 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004922 return null;
4923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (appType != TelephonyManager.APPTYPE_USIM
4928 && appType != TelephonyManager.APPTYPE_SIM) {
4929 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4930 return null;
4931 }
4932 Object response = sendRequest(
4933 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4934 if (response instanceof String[]) {
4935 return (String[]) response;
4936 }
yincheng zhao2737e882019-09-06 17:06:54 -07004937 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004939 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 } finally {
4941 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004942 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004943 }
4944
yincheng zhao2737e882019-09-06 17:06:54 -07004945 /**
4946 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4947 * subscription.
4948 *
4949 * @param subId the id of the subscription.
4950 * @param appType the uicc app type, must be USIM or SIM.
4951 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4952 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004953 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004954 * @return number of fplmns that is successfully written to the SIM.
4955 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004956 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4957 String callingFeatureId) {
4958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4959 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004960 if (DBG) logv("no permissions for setForbiddenplmns");
4961 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4962 }
4963 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4964 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4965 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4966 }
4967 if (fplmns == null) {
4968 throw new IllegalArgumentException("Fplmn List provided is null");
4969 }
4970 for (String fplmn : fplmns) {
4971 if (!CellIdentity.isValidPlmn(fplmn)) {
4972 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4973 }
4974 }
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 Object response = sendRequest(
4978 CMD_SET_FORBIDDEN_PLMNS,
4979 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4980 subId);
4981 return (int) response;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
4985 }
4986
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004988 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4990 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4995 if (response.payload == null) {
4996 return "";
4997 }
Evan Charltonc66da362014-05-16 14:06:40 -07004998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 // Append the returned status code to the end of the response payload.
5000 String s = Integer.toHexString(
5001 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5002 s = IccUtils.bytesToHexString(response.payload) + s;
5003 return s;
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
Evan Charltonc66da362014-05-16 14:06:40 -07005007 }
5008
Jake Hambye994d462014-02-03 13:10:13 -08005009 /**
5010 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5011 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5012 *
5013 * @param itemID the ID of the item to read
5014 * @return the NV item as a String, or null on error.
5015 */
5016 @Override
5017 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5020 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021
5022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005025 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5027 return value;
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Jake Hambye994d462014-02-03 13:10:13 -08005031 }
5032
5033 /**
5034 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5035 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5036 *
5037 * @param itemID the ID of the item to read
5038 * @param itemValue the value to write, as a String
5039 * @return true on success; false on any failure
5040 */
5041 @Override
5042 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5045 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5050 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005051 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5053 return success;
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
Jake Hambye994d462014-02-03 13:10:13 -08005057 }
5058
5059 /**
5060 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5061 * Used for device configuration by some CDMA operators.
5062 *
5063 * @param preferredRoamingList byte array containing the new PRL
5064 * @return true on success; false on any failure
5065 */
5066 @Override
5067 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5075 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5076 return success;
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
Jake Hambye994d462014-02-03 13:10:13 -08005080 }
5081
5082 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005083 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005084 * Used for device configuration by some CDMA operators.
5085 *
chen xu6dac5ab2018-10-26 17:39:23 -07005086 * @param slotIndex - device slot.
5087 *
Jake Hambye994d462014-02-03 13:10:13 -08005088 * @return true on success; false on any failure
5089 */
5090 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005091 public boolean resetModemConfig(int slotIndex) {
5092 Phone phone = PhoneFactory.getPhone(slotIndex);
5093 if (phone != null) {
5094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096
chen xu6dac5ab2018-10-26 17:39:23 -07005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5100 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5101 return success;
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 }
chen xu6dac5ab2018-10-26 17:39:23 -07005106 return false;
5107 }
5108
5109 /**
5110 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5111 *
5112 * @param slotIndex - device slot.
5113 *
5114 * @return true on success; false on any failure
5115 */
5116 @Override
5117 public boolean rebootModem(int slotIndex) {
5118 Phone phone = PhoneFactory.getPhone(slotIndex);
5119 if (phone != null) {
5120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5121 mApp, phone.getSubId(), "rebootModem");
5122
5123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5126 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5127 return success;
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
5130 }
5131 }
5132 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005133 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005134
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005135 public String[] getPcscfAddress(String apnType, String callingPackage,
5136 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005137 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5139 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005140 return new String[0];
5141 }
5142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005145 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Wink Saville36469e72014-06-11 15:17:00 -07005149 }
5150
Brad Ebinger51f743a2017-01-23 13:50:20 -08005151 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005152 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5153 * {@link #disableIms(int)}.
5154 * @param slotIndex device slot.
5155 */
5156 public void resetIms(int slotIndex) {
5157 enforceModifyPermission();
5158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 if (mImsResolver == null) {
5162 // may happen if the does not support IMS.
5163 return;
5164 }
5165 mImsResolver.disableIms(slotIndex);
5166 mImsResolver.enableIms(slotIndex);
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
5170 }
5171
5172 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005173 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5174 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005175 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005176 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005177 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178
5179 final long identity = Binder.clearCallingIdentity();
5180 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005181 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005182 // may happen if the device does not support IMS.
5183 return;
5184 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005185 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005189 }
5190
5191 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005192 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5193 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005194 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005195 public void disableIms(int slotId) {
5196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197
5198 final long identity = Binder.clearCallingIdentity();
5199 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005200 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005201 // may happen if the device does not support IMS.
5202 return;
5203 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005204 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005208 }
5209
5210 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005211 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5212 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005213 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005214 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005215 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005220 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5222 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005223 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005224 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005228 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005229 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005230 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5231 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005232 @Override
5233 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005234 enforceModifyPermission();
5235
5236 final long identity = Binder.clearCallingIdentity();
5237 try {
5238 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005239 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
5245 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005246 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005247 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005248 */
5249 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005254 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005255 // may happen if the device does not support IMS.
5256 return null;
5257 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005258 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005262 }
5263
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005264 /**
5265 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005266 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005267 */
5268 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005273 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005274 // may happen if the device does not support IMS.
5275 return null;
5276 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005277 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005281 }
5282
Brad Ebinger884c07b2018-02-15 16:17:40 -08005283 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005284 * Sets the ImsService Package Name that Telephony will bind to.
5285 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005286 * @param slotIndex the slot ID that the ImsService should bind for.
5287 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005288 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005289 * @param featureTypes An integer array of feature types associated with a packageName.
5290 * @param packageName The name of the package that the current configuration will be replaced
5291 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005292 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005293 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005294 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5295 int[] featureTypes, String packageName) {
5296 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5299 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005300 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005304 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005305 // may happen if the device does not support IMS.
5306 return false;
5307 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005308 Map<Integer, String> featureConfig = new HashMap<>();
5309 for (int featureType : featureTypes) {
5310 featureConfig.put(featureType, packageName);
5311 }
5312 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5313 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005317 }
5318
5319 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005320 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005321 *
5322 * @param slotId The slot that the ImsService is associated with.
5323 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5324 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005325 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005326 * @return the package name of the ImsService configuration.
5327 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005328 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5329 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005330 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005331 TelephonyPermissions
5332 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5333 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5334 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005338 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005339 // may happen if the device does not support IMS.
5340 return "";
5341 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005342 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005343 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5344 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005348 }
5349
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005350 /**
5351 * Get the MmTelFeature state associated with the requested subscription id.
5352 * @param subId The subscription that the MmTelFeature is associated with.
5353 * @param callback A callback with an integer containing the
5354 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5355 */
5356 @Override
5357 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5358 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5359 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5360 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5361 "IMS not available on device.");
5362 }
5363 final long token = Binder.clearCallingIdentity();
5364 try {
5365 int slotId = getSlotIndex(subId);
5366 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5367 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5368 + subId + "'");
5369 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5370 }
5371 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5372 try {
5373 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5374 } catch (RemoteException e) {
5375 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5376 + "Ignore");
5377 }
5378 });
5379 } finally {
5380 Binder.restoreCallingIdentity(token);
5381 }
5382 }
5383
Wink Saville36469e72014-06-11 15:17:00 -07005384 public void setImsRegistrationState(boolean registered) {
5385 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386
5387 final long identity = Binder.clearCallingIdentity();
5388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
Wink Saville36469e72014-06-11 15:17:00 -07005393 }
5394
5395 /**
Stuart Scott54788802015-03-30 13:18:01 -07005396 * Set the network selection mode to automatic.
5397 *
5398 */
5399 @Override
5400 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5402 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
5404 final long identity = Binder.clearCallingIdentity();
5405 try {
shilufc958392020-01-20 11:36:01 -08005406 if (!isActiveSubscription(subId)) {
5407 return;
5408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5410 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Stuart Scott54788802015-03-30 13:18:01 -07005414 }
5415
Jack Yud10cdd42020-09-28 20:28:01 -07005416 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005417 * Ask the radio to connect to the input network and change selection mode to manual.
5418 *
5419 * @param subId the id of the subscription.
5420 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5421 * the operator to attach to.
5422 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5423 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5424 * normal network selection next time.
5425 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005426 */
5427 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005428 public boolean setNetworkSelectionModeManual(
5429 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5431 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005432
5433 if (!isActiveSubscription(subId)) {
5434 return false;
5435 }
5436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 final long identity = Binder.clearCallingIdentity();
5438 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005439 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005441 if (DBG) {
5442 log("setNetworkSelectionModeManual: subId: " + subId
5443 + " operator: " + operatorInfo);
5444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005449 }
shilu84f6e8b2019-12-19 13:58:01 -08005450 /**
5451 * Get the manual network selection
5452 *
5453 * @param subId the id of the subscription.
5454 *
5455 * @return the previously saved user selected PLMN
5456 */
5457 @Override
5458 public String getManualNetworkSelectionPlmn(int subId) {
5459 TelephonyPermissions
5460 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5461 mApp, subId, "getManualNetworkSelectionPlmn");
5462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005466 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005467 }
5468
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005471 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005472 }
5473 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5474 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5475 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
5479 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005480
5481 /**
5482 * Scans for available networks.
5483 */
5484 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005485 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5486 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5488 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005489 LocationAccessPolicy.LocationPermissionResult locationResult =
5490 LocationAccessPolicy.checkLocationPermission(mApp,
5491 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5492 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005493 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005494 .setCallingPid(Binder.getCallingPid())
5495 .setCallingUid(Binder.getCallingUid())
5496 .setMethod("getCellNetworkScanResults")
5497 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005498 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5499 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005500 .build());
5501 switch (locationResult) {
5502 case DENIED_HARD:
5503 throw new SecurityException("Not allowed to access scan results -- location");
5504 case DENIED_SOFT:
5505 return null;
5506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
Pengquan Menga1bb6272018-09-06 09:59:22 -07005508 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 try {
5510 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005511 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005516 }
5517
5518 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005519 * Get the call forwarding info, given the call forwarding reason.
5520 */
5521 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005522 public void getCallForwarding(int subId, int callForwardingReason,
5523 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005524 enforceReadPrivilegedPermission("getCallForwarding");
5525 long identity = Binder.clearCallingIdentity();
5526 try {
5527 if (DBG) {
5528 log("getCallForwarding: subId " + subId
5529 + " callForwardingReason" + callForwardingReason);
5530 }
Hall Liu27d24262020-09-18 19:04:59 -07005531
5532 Phone phone = getPhone(subId);
5533 if (phone == null) {
5534 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005535 callback.onError(
5536 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005537 } catch (RemoteException e) {
5538 // ignore
5539 }
5540 return;
5541 }
5542
5543 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5544 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5545 @Override
5546 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5547 try {
5548 callback.onCallForwardingInfoAvailable(info);
5549 } catch (RemoteException e) {
5550 // ignore
5551 }
5552 }
5553
5554 @Override
5555 public void onError(int error) {
5556 try {
5557 callback.onError(error);
5558 } catch (RemoteException e) {
5559 // ignore
5560 }
5561 }
5562 });
5563 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
5567 }
5568
5569 /**
5570 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5571 * reason, the number to forward, and the timeout before the forwarding is attempted.
5572 */
5573 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005574 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5575 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005576 enforceModifyPermission();
5577 long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (DBG) {
5580 log("setCallForwarding: subId " + subId
5581 + " callForwardingInfo" + callForwardingInfo);
5582 }
Hall Liu27d24262020-09-18 19:04:59 -07005583
5584 Phone phone = getPhone(subId);
5585 if (phone == null) {
5586 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005587 callback.accept(
5588 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005589 } catch (RemoteException e) {
5590 // ignore
5591 }
5592 return;
5593 }
5594
5595 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5596 FunctionalUtils.ignoreRemoteException(callback::accept));
5597
5598 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 /**
Hall Liu27d24262020-09-18 19:04:59 -07005605 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005606 */
5607 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005608 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005609 enforceReadPrivilegedPermission("getCallForwarding");
5610 long identity = Binder.clearCallingIdentity();
5611 try {
Hall Liu27d24262020-09-18 19:04:59 -07005612
5613 Phone phone = getPhone(subId);
5614 if (phone == null) {
5615 try {
5616 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5617 } catch (RemoteException e) {
5618 // ignore
5619 }
5620 return;
5621 }
5622
5623 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5624
Shuo Qian4a594052020-01-23 11:59:30 -08005625 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005626 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
5630 }
5631
5632 /**
Hall Liu27d24262020-09-18 19:04:59 -07005633 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005634 */
5635 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005636 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005637 enforceModifyPermission();
5638 long identity = Binder.clearCallingIdentity();
5639 try {
Hall Liu27d24262020-09-18 19:04:59 -07005640 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5641
5642 Phone phone = getPhone(subId);
5643 if (phone == null) {
5644 try {
5645 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5646 } catch (RemoteException e) {
5647 // ignore
5648 }
5649 return;
5650 }
5651
5652 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5653 FunctionalUtils.ignoreRemoteException(callback::accept));
5654
5655 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
5659 }
5660
5661 /**
yinxub1bed742017-04-17 11:45:04 -07005662 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005663 *
yinxub1bed742017-04-17 11:45:04 -07005664 * @param subId id of the subscription
5665 * @param request contains the radio access networks with bands/channels to scan
5666 * @param messenger callback messenger for scan results or errors
5667 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005668 * @return the id of the requested scan which can be used to stop the scan.
5669 */
5670 @Override
5671 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005672 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005675 LocationAccessPolicy.LocationPermissionResult locationResult =
5676 LocationAccessPolicy.checkLocationPermission(mApp,
5677 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5678 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005679 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005680 .setCallingPid(Binder.getCallingPid())
5681 .setCallingUid(Binder.getCallingUid())
5682 .setMethod("requestNetworkScan")
5683 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005684 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5685 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005686 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005687 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005688 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5689 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005690 if (e != null) {
5691 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5692 throw e;
5693 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005694 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005695 return TelephonyScanManager.INVALID_SCAN_ID;
5696 }
5697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 }
Hall Liu912dfd32019-04-25 14:02:26 -07005699 int callingUid = Binder.getCallingUid();
5700 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 return mNetworkScanRequestTracker.startNetworkScan(
5704 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005705 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
yinxu504e1392017-04-12 16:03:22 -07005709 }
5710
Hall Liub2ac8ef2019-02-28 15:56:23 -08005711 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005712 NetworkScanRequest request, int subId, String callingPackage) {
5713 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005714 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5715 boolean hasNetworkScanPermission =
5716 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5717 == PERMISSION_GRANTED;
5718
5719 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5720 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5721 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005722 }
5723
5724 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5725 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005726 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5727 return new SecurityException("Specific channels must not be"
5728 + " scanned without location access.");
5729 }
5730 }
5731 }
5732
Hall Liub2ac8ef2019-02-28 15:56:23 -08005733 return null;
5734 }
5735
yinxu504e1392017-04-12 16:03:22 -07005736 /**
5737 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005738 *
5739 * @param subId id of the subscription
5740 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005741 */
5742 @Override
5743 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5745 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
Hall Liu912dfd32019-04-25 14:02:26 -07005747 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 final long identity = Binder.clearCallingIdentity();
5749 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005750 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
yinxu504e1392017-04-12 16:03:22 -07005754 }
5755
5756 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005757 * Get the calculated preferred network type.
5758 * Used for debugging incorrect network type.
5759 *
5760 * @return the preferred network type, defined in RILConstants.java.
5761 */
5762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005763 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 final Phone defaultPhone = getDefaultPhone();
5765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005767 return RILConstants.PREFERRED_NETWORK_MODE;
5768 }
5769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005773 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Junda Liu84d15a22014-07-02 11:21:04 -07005777 }
5778
5779 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005780 * Get the preferred network type.
5781 * Used for device configuration by some CDMA operators.
5782 *
5783 * @return the preferred network type, defined in RILConstants.java.
5784 */
5785 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005786 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005787 TelephonyPermissions
5788 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5789 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 if (DBG) log("getPreferredNetworkType");
5794 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5795 int networkType = (result != null ? result[0] : -1);
5796 if (DBG) log("getPreferredNetworkType: " + networkType);
5797 return networkType;
5798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005801 }
5802
5803 /**
5804 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005805 *
5806 * @param networkType the preferred network type, defined in RILConstants.java.
5807 * @return true on success; false on any failure.
5808 */
5809 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005810 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5812 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
calvinpan8ed33732020-03-12 14:17:55 +08005816 Boolean success = (Boolean) sendRequest(
5817 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005818
5819 if (success) {
5820 Settings.Global.putInt(mApp.getContentResolver(),
5821 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5822 }
calvinpan8ed33732020-03-12 14:17:55 +08005823 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5824 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005827 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005828 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005829
5830 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005831 * Get the allowed network types that store in the telephony provider.
5832 *
5833 * @param subId the id of the subscription.
5834 * @return allowedNetworkTypes the allowed network types.
5835 */
5836 @Override
5837 public long getAllowedNetworkTypes(int subId) {
5838 TelephonyPermissions
5839 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5840 mApp, subId, "getAllowedNetworkTypes");
5841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 return SubscriptionManager.getLongSubscriptionProperty(
5845 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
5851 /**
5852 * Set the allowed network types.
5853 *
5854 * @param subId the id of the subscription.
5855 * @param allowedNetworkTypes the allowed network types.
5856 * @return true on success; false on any failure.
5857 */
5858 @Override
5859 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5861 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005862
calvinpan8ed33732020-03-12 14:17:55 +08005863 SubscriptionManager.setSubscriptionProperty(subId,
5864 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5865 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005866
calvinpan8ed33732020-03-12 14:17:55 +08005867 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5868 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5869 RILConstants.PREFERRED_NETWORK_MODE);
5870 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005871 }
5872
5873 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005874 * Get the allowed network types for certain reason.
5875 *
5876 * @param subId the id of the subscription.
5877 * @param reason the reason the allowed network type change is taking place
5878 * @return the allowed network types.
5879 */
5880 @Override
5881 public long getAllowedNetworkTypesForReason(int subId,
5882 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5883 TelephonyPermissions
5884 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5885 mApp, subId, "getAllowedNetworkTypesForReason");
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
5892 }
5893
5894 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005895 * Enable/Disable E-UTRA-NR Dual Connectivity
5896 * @param subId subscription id of the sim card
5897 * @param nrDualConnectivityState expected NR dual connectivity state
5898 * This can be passed following states
5899 * <ol>
5900 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5901 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5902 * <li>Disable NR dual connectivity and force secondary cell to be released
5903 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5904 * </ol>
5905 * @return operation result.
5906 */
5907 @Override
5908 public int setNrDualConnectivityState(int subId,
5909 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, subId, "enableNRDualConnectivity");
5912 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5916 nrDualConnectivityState, subId,
5917 workSource);
5918 if (DBG) log("enableNRDualConnectivity result: " + result);
5919 return result;
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
5923 }
5924
5925 /**
5926 * Is E-UTRA-NR Dual Connectivity enabled
5927 * @return true if dual connectivity is enabled else false
5928 */
5929 @Override
5930 public boolean isNrDualConnectivityEnabled(int subId) {
5931 TelephonyPermissions
5932 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5933 mApp, subId, "isNRDualConnectivityEnabled");
5934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5938 null, subId, workSource);
5939 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5940 return isEnabled;
5941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
5944 }
5945
5946 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07005947 * get carrier bandwidth per primary and secondary carrier
5948 * @param subId subscription id of the sim card
5949 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5950 */
5951 @Override
5952 public CarrierBandwidth getCarrierBandwidth(int subId) {
5953 TelephonyPermissions
5954 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5955 mApp, subId, "isNRDualConnectivityEnabled");
5956 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5957 final long identity = Binder.clearCallingIdentity();
5958 try {
5959 CarrierBandwidth carrierBandwidth =
5960 getPhoneFromSubId(subId).getCarrierBandwidth();
5961 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5962 return carrierBandwidth;
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
5966 }
5967
5968 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005969 * Get the effective allowed network types on the device.
5970 * This API will return an intersection of allowed network types for all reasons,
5971 * including the configuration done through setAllowedNetworkTypes
5972 *
5973 * @param subId the id of the subscription.
5974 * @return the allowed network types
5975 */
5976 @Override
5977 public long getEffectiveAllowedNetworkTypes(int subId) {
5978 TelephonyPermissions
5979 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5980 mApp, subId, "getEffectiveAllowedNetworkTypes");
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
5983 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
5987 }
5988
5989 /**
5990 * Set the allowed network types of the device and
5991 * provide the reason triggering the allowed network change.
5992 *
5993 * @param subId the id of the subscription.
5994 * @param reason the reason the allowed network type change is taking place
5995 * @param allowedNetworkTypes the allowed network types.
5996 * @return true on success; false on any failure.
5997 */
5998 @Override
5999 public boolean setAllowedNetworkTypesForReason(int subId,
6000 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6002 mApp, subId, "setAllowedNetworkTypesForReason");
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
6005 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6006 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6007 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6008 RILConstants.PREFERRED_NETWORK_MODE);
6009 return setPreferredNetworkType(subId, preferredNetworkMode);
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
6013 }
6014
6015 /**
Miaoa84611c2019-03-15 09:21:10 +08006016 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006017 *
Miaoa84611c2019-03-15 09:21:10 +08006018 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006019 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006020 * @hide
6021 */
6022 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006023 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006026 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 try {
Miaoa84611c2019-03-15 09:21:10 +08006028 if (phone != null) {
6029 return phone.hasMatchedTetherApnSetting();
6030 } else {
6031 return false;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006035 }
Junda Liu475951f2014-11-07 16:45:03 -08006036 }
6037
6038 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006039 * Enable or disable always reporting signal strength changes from radio.
6040 *
6041 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6042 */
6043 @Override
6044 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6045 enforceModifyPermission();
6046 enforceSystemCaller();
6047
6048 final long identity = Binder.clearCallingIdentity();
6049 final Phone phone = getPhone(subId);
6050 try {
6051 if (phone != null) {
6052 if (DBG) {
6053 log("setAlwaysReportSignalStrength: subId=" + subId
6054 + " isEnable=" + isEnable);
6055 }
6056 phone.setAlwaysReportSignalStrength(isEnable);
6057 } else {
6058 loge("setAlwaysReportSignalStrength: no phone found for subId="
6059 + subId);
6060 }
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
6064 }
6065
6066 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006067 * Get the user enabled state of Mobile Data.
6068 *
6069 * TODO: remove and use isUserDataEnabled.
6070 * This can't be removed now because some vendor codes
6071 * calls through ITelephony directly while they should
6072 * use TelephonyManager.
6073 *
6074 * @return true on enabled
6075 */
6076 @Override
6077 public boolean getDataEnabled(int subId) {
6078 return isUserDataEnabled(subId);
6079 }
6080
6081 /**
6082 * Get whether mobile data is enabled per user setting.
6083 *
6084 * There are other factors deciding whether mobile data is actually enabled, but they are
6085 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006086 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006087 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006088 *
6089 * @return {@code true} if data is enabled else {@code false}
6090 */
6091 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006092 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006093 try {
6094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6095 null);
6096 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6098 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 int phoneId = mSubscriptionController.getPhoneId(subId);
6104 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6105 Phone phone = PhoneFactory.getPhone(phoneId);
6106 if (phone != null) {
6107 boolean retVal = phone.isUserDataEnabled();
6108 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6109 return retVal;
6110 } else {
6111 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6112 return false;
6113 }
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006116 }
6117 }
6118
6119 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006120 * Checks if the device is capable of mobile data by considering whether whether the
6121 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6122 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006123 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006124 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006125 */
6126 @Override
6127 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006128 try {
6129 try {
6130 mApp.enforceCallingOrSelfPermission(
6131 android.Manifest.permission.ACCESS_NETWORK_STATE,
6132 null);
6133 } catch (Exception e) {
6134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6135 "isDataEnabled");
6136 }
6137 } catch (Exception e) {
6138 enforceReadPrivilegedPermission("isDataEnabled");
6139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 int phoneId = mSubscriptionController.getPhoneId(subId);
6144 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6145 Phone phone = PhoneFactory.getPhone(phoneId);
6146 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006147 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6149 return retVal;
6150 } else {
6151 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6152 return false;
6153 }
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006156 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006157 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006158
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006159 /**
6160 * Check if data is enabled for a specific reason
6161 * @param subId Subscription index
6162 * @param reason the reason the data enable change is taking place
6163 * @return {@code true} if the overall data is enabled; {@code false} if not.
6164 */
6165 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006166 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006167 @TelephonyManager.DataEnabledReason int reason) {
6168 try {
6169 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6170 null);
6171 } catch (Exception e) {
6172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006173 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006174 }
6175
6176
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 int phoneId = mSubscriptionController.getPhoneId(subId);
6180 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006181 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006182 + " reason=" + reason);
6183 }
6184 Phone phone = PhoneFactory.getPhone(phoneId);
6185 if (phone != null) {
6186 boolean retVal;
6187 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6188 retVal = phone.isUserDataEnabled();
6189 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006190 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006191 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006192 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006193 return retVal;
6194 } else {
6195 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006196 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006197 + subId + " retVal=false");
6198 }
6199 return false;
6200 }
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
6204 }
6205
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006206 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006207 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006208 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6209 // Skip the check if it's one of these special uids
6210 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6211 }
6212
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006213 //load access rules from carrier configs, and check those as well: b/139133814
6214 SubscriptionController subController = SubscriptionController.getInstance();
6215 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6216 || subController == null) return privilegeFromSim;
6217
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006218 PackageManager pkgMgr = phone.getContext().getPackageManager();
6219 String[] packages = pkgMgr.getPackagesForUid(uid);
6220
6221 final long identity = Binder.clearCallingIdentity();
6222 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006223 int subId = phone.getSubId();
6224 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6225 // A test override is in place for the privileges for this subId, so don't try to
6226 // read the subscription privileges.
6227 return privilegeFromSim;
6228 }
6229 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006230 SubscriptionManager subManager = (SubscriptionManager)
6231 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6232 for (String pkg : packages) {
6233 if (subManager.canManageSubscription(subInfo, pkg)) {
6234 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6235 }
6236 }
6237 return privilegeFromSim;
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
6241 }
6242
6243 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6244 String pkgName) {
6245 //load access rules from carrier configs, and check those as well: b/139133814
6246 SubscriptionController subController = SubscriptionController.getInstance();
6247 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6248 || subController == null) return privilegeFromSim;
6249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006252 int subId = phone.getSubId();
6253 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6254 // A test override is in place for the privileges for this subId, so don't try to
6255 // read the subscription privileges.
6256 return privilegeFromSim;
6257 }
6258 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006259 SubscriptionManager subManager = (SubscriptionManager)
6260 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6261 return subManager.canManageSubscription(subInfo, pkgName)
6262 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
6266 }
6267
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006268 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006269 public int getCarrierPrivilegeStatus(int subId) {
6270 final Phone phone = getPhone(subId);
6271 if (phone == null) {
6272 loge("getCarrierPrivilegeStatus: Invalid subId");
6273 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6274 }
6275 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006276 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006277 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006278 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6279 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006280
6281 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6282 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006283 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006284 }
Junda Liu29340342014-07-10 15:23:27 -07006285
6286 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006288 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006289 final Phone phone = getPhone(subId);
6290 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006291 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006292 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6293 }
6294 UiccProfile profile =
6295 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6296 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006297 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006298 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6299 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006300 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006301 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006302 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 }
6304
6305 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006306 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6307 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006308 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006309 }
6310
6311 int phoneId = SubscriptionManager.getPhoneId(subId);
6312 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006313 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006314 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006315 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6316 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006317 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6318 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6319 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006320 }
6321
6322 @Override
6323 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006324 if (TextUtils.isEmpty(pkgName))
6325 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006326 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6327 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6328 UiccCard card = UiccController.getInstance().getUiccCard(i);
6329 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006330 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006331 continue;
6332 }
6333
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006334 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6335 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6336 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006337 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6338 break;
6339 }
6340 }
6341
6342 return result;
Junda Liu29340342014-07-10 15:23:27 -07006343 }
Derek Tan89e89d42014-07-08 17:00:10 -07006344
6345 @Override
Junda Liue64de782015-04-16 17:19:16 -07006346 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6347 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6348 loge("phoneId " + phoneId + " is not valid.");
6349 return null;
6350 }
6351 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006352 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006353 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006354 return null ;
6355 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006356 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006357 }
6358
Amith Yamasani6e118872016-02-19 12:53:51 -08006359 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006360 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006361 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006362 List<String> privilegedPackages = new ArrayList<>();
6363 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006364 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6365 // has UICC in that slot.
6366 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006367 if (card.hasCarrierPrivilegeRules()) {
6368 if (packages == null) {
6369 // Only check packages in user 0 for now
6370 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006371 PackageManager.MATCH_DISABLED_COMPONENTS
6372 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006373 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006374 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006375 }
6376 for (int p = packages.size() - 1; p >= 0; p--) {
6377 PackageInfo pkgInfo = packages.get(p);
6378 if (pkgInfo != null && pkgInfo.packageName != null
6379 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006380 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006381 privilegedPackages.add(pkgInfo.packageName);
6382 }
6383 }
6384 }
6385 }
6386 return privilegedPackages;
6387 }
6388
chen xuf7e9fe82019-05-09 19:31:02 -07006389 @Override
6390 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006391 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6392
6393 final long identity = Binder.clearCallingIdentity();
6394
chen xuf7e9fe82019-05-09 19:31:02 -07006395 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006396 try {
6397 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6398 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6399 }
6400 } finally {
6401 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006402 }
6403 return privilegedPackages;
6404 }
6405
Wink Savilleb564aae2014-10-23 10:18:09 -07006406 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006407 final Phone phone = getPhone(subId);
6408 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006409 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006410 return null;
6411 }
6412 String iccId = card.getIccId();
6413 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006414 return null;
6415 }
6416 return iccId;
6417 }
6418
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006419 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006420 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6421 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006422 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006423 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 final String iccId = getIccId(subId);
6428 final Phone phone = getPhone(subId);
6429 if (phone == null) {
6430 return false;
6431 }
6432 final String subscriberId = phone.getSubscriberId();
6433
6434 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006435 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 + subscriberId + " to " + number);
6437 }
6438
6439 if (TextUtils.isEmpty(iccId)) {
6440 return false;
6441 }
6442
6443 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6444
6445 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6446 if (alphaTag == null) {
6447 editor.remove(alphaTagPrefKey);
6448 } else {
6449 editor.putString(alphaTagPrefKey, alphaTag);
6450 }
6451
6452 // Record both the line number and IMSI for this ICCID, since we need to
6453 // track all merged IMSIs based on line number
6454 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6455 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6456 if (number == null) {
6457 editor.remove(numberPrefKey);
6458 editor.remove(subscriberPrefKey);
6459 } else {
6460 editor.putString(numberPrefKey, number);
6461 editor.putString(subscriberPrefKey, subscriberId);
6462 }
6463
6464 editor.commit();
6465 return true;
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006468 }
Derek Tan7226c842014-07-02 17:42:23 -07006469 }
6470
6471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006472 public String getLine1NumberForDisplay(int subId, String callingPackage,
6473 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006474 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006476 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006477 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006478 return null;
6479 }
Derek Tan97ebb422014-09-05 16:55:38 -07006480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 String iccId = getIccId(subId);
6484 if (iccId != null) {
6485 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6486 if (DBG_MERGE) {
6487 log("getLine1NumberForDisplay returning "
6488 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6489 }
6490 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6493 return null;
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006496 }
Derek Tan7226c842014-07-02 17:42:23 -07006497 }
6498
6499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006500 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6501 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006503 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006504 return null;
6505 }
Derek Tan97ebb422014-09-05 16:55:38 -07006506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 String iccId = getIccId(subId);
6510 if (iccId != null) {
6511 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6512 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6513 }
6514 return null;
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006517 }
Derek Tan7226c842014-07-02 17:42:23 -07006518 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006519
6520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006521 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6522 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006523 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6524 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006526 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006527 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006528 return null;
6529 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006530
Jordan Liub49b04b2019-05-06 14:45:15 -07006531 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6532 // the process, where TelephonyManager was instantiated.
6533 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006534 final long identity = Binder.clearCallingIdentity();
6535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006536 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 final TelephonyManager tele = TelephonyManager.from(context);
6538 final SubscriptionManager sub = SubscriptionManager.from(context);
6539
6540 // Figure out what subscribers are currently active
6541 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
Jordan Liub49b04b2019-05-06 14:45:15 -07006543 // Only consider subs which match the current subId
6544 // This logic can be simplified. See b/131189269 for progress.
6545 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006546 activeSubscriberIds.add(tele.getSubscriberId(subId));
6547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548
6549 // First pass, find a number override for an active subscriber
6550 String mergeNumber = null;
6551 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6552 for (String key : prefs.keySet()) {
6553 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6554 final String subscriberId = (String) prefs.get(key);
6555 if (activeSubscriberIds.contains(subscriberId)) {
6556 final String iccId = key.substring(
6557 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6558 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6559 mergeNumber = (String) prefs.get(numberKey);
6560 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006561 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 + " for active subscriber " + subscriberId);
6563 }
6564 if (!TextUtils.isEmpty(mergeNumber)) {
6565 break;
6566 }
6567 }
6568 }
6569 }
6570
6571 // Shortcut when no active merged subscribers
6572 if (TextUtils.isEmpty(mergeNumber)) {
6573 return null;
6574 }
6575
6576 // Second pass, find all subscribers under that line override
6577 final ArraySet<String> result = new ArraySet<>();
6578 for (String key : prefs.keySet()) {
6579 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6580 final String number = (String) prefs.get(key);
6581 if (mergeNumber.equals(number)) {
6582 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6583 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6584 final String subscriberId = (String) prefs.get(subscriberKey);
6585 if (!TextUtils.isEmpty(subscriberId)) {
6586 result.add(subscriberId);
6587 }
6588 }
6589 }
6590 }
6591
6592 final String[] resultArray = result.toArray(new String[result.size()]);
6593 Arrays.sort(resultArray);
6594 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006595 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6597 }
6598 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006599 } finally {
6600 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006601 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006602 }
6603
6604 @Override
zoey chen38003472019-12-13 17:16:31 +08006605 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6606 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 final TelephonyManager telephonyManager = mApp.getSystemService(
6611 TelephonyManager.class);
6612 String subscriberId = telephonyManager.getSubscriberId(subId);
6613 if (subscriberId == null) {
6614 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006615 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006616 + subId);
6617 }
6618 return null;
6619 }
6620
6621 final SubscriptionInfo info = SubscriptionController.getInstance()
6622 .getSubscriptionInfo(subId);
6623 final ParcelUuid groupUuid = info.getGroupUuid();
6624 // If it doesn't belong to any group, return just subscriberId of itself.
6625 if (groupUuid == null) {
6626 return new String[]{subscriberId};
6627 }
6628
6629 // Get all subscriberIds from the group.
6630 final List<String> mergedSubscriberIds = new ArrayList<>();
6631 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006632 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006633 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006634 for (SubscriptionInfo subInfo : groupInfos) {
6635 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6636 if (subscriberId != null) {
6637 mergedSubscriberIds.add(subscriberId);
6638 }
6639 }
6640
6641 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644
6645 }
6646 }
6647
6648 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006649 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006650 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006651 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 final Phone phone = getPhone(subId);
6656 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6657 } finally {
6658 Binder.restoreCallingIdentity(identity);
6659 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006660 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006661
6662 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006663 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006664 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6665 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6667 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 final Phone phone = getPhone(subId);
6672 if (phone == null) {
6673 return false;
6674 }
6675 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6676 cdmaNonRoamingList);
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006679 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006680 }
6681
6682 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006683 @Deprecated
6684 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6685 enforceModifyPermission();
6686
6687 int returnValue = 0;
6688 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006689 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006690 if(result.exception == null) {
6691 if (result.result != null) {
6692 byte[] responseData = (byte[])(result.result);
6693 if(responseData.length > oemResp.length) {
6694 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6695 responseData.length + "bytes. Buffer Size is " +
6696 oemResp.length + "bytes.");
6697 }
6698 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6699 returnValue = responseData.length;
6700 }
6701 } else {
6702 CommandException ex = (CommandException) result.exception;
6703 returnValue = ex.getCommandError().ordinal();
6704 if(returnValue > 0) returnValue *= -1;
6705 }
6706 } catch (RuntimeException e) {
6707 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6708 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6709 if(returnValue > 0) returnValue *= -1;
6710 }
6711
6712 return returnValue;
6713 }
6714
6715 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006716 public void setRadioCapability(RadioAccessFamily[] rafs) {
6717 try {
6718 ProxyController.getInstance().setRadioCapability(rafs);
6719 } catch (RuntimeException e) {
6720 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6721 }
6722 }
6723
6724 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006725 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006726 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006727 try {
6728 TelephonyPermissions
6729 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6730 mApp, phone.getSubId(), "getRadioAccessFamily");
6731 } catch (SecurityException e) {
6732 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6733 throw e;
6734 }
chen xub97461a2018-10-26 14:17:57 -07006735 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006736 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006737 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 final long identity = Binder.clearCallingIdentity();
6740 try {
chen xub97461a2018-10-26 14:17:57 -07006741 TelephonyPermissions
6742 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6743 mApp, phone.getSubId(), "getRadioAccessFamily");
6744 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
chen xub97461a2018-10-26 14:17:57 -07006748 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006749 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006750
6751 @Override
6752 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006753 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755
6756 final long identity = Binder.clearCallingIdentity();
6757 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006758 ImsManager.getInstance(defaultPhone.getContext(),
6759 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006763 }
6764
6765 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006766 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006767 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6769 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006770 return false;
6771 }
Svet Ganovb320e182015-04-16 12:30:10 -07006772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 // Check the user preference and the system-level IMS setting. Even if the user has
6776 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6777 // In the long run, we may instead need to check if there exists a connection service
6778 // which can support video calling.
6779 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006780 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 return imsManager.isVtEnabledByPlatform()
6782 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6783 && imsManager.isVtEnabledByUser();
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006787 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006788
Andrew Leea1239f22015-03-02 17:44:07 -08006789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6791 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006793 mApp, subId, callingPackage, callingFeatureId,
6794 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 return false;
6796 }
6797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
6800 CarrierConfigManager configManager =
6801 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006802 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
Andrew Leea1239f22015-03-02 17:44:07 -08006807 }
6808
6809 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006810 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006812 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 return false;
6814 }
6815
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 CarrierConfigManager configManager =
6819 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006820 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
Andrew Leea1239f22015-03-02 17:44:07 -08006825 }
6826
Andrew Lee9431b832015-03-09 18:46:45 -07006827 @Override
6828 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006829 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006830 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006831 }
6832
6833 @Override
6834 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 final long identity = Binder.clearCallingIdentity();
6836 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006837 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 } finally {
6839 Binder.restoreCallingIdentity(identity);
6840 }
Andrew Lee9431b832015-03-09 18:46:45 -07006841 }
6842
Hall Liuf6668912018-10-31 17:05:23 -07006843 /**
6844 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6845 * support for the feature and device firmware support.
6846 *
6847 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6848 */
6849 @Override
6850 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006852 final Phone phone = getPhone(subscriptionId);
6853 if (phone == null) {
6854 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6855 return false;
6856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6860 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 return isCarrierSupported && isDeviceSupported;
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
Hall Liu98187582018-01-22 19:15:32 -08006866 }
6867
Hall Liuf6668912018-10-31 17:05:23 -07006868 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006869 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6870 * RTT setting, will return true if the device and carrier both support RTT.
6871 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006872 */
6873 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 final long identity = Binder.clearCallingIdentity();
6875 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006876 boolean isRttSupported = isRttSupported(subscriptionId);
6877 boolean isUserRttSettingOn = Settings.Secure.getInt(
6878 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6879 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6880 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6881 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 } finally {
6883 Binder.restoreCallingIdentity(identity);
6884 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006885 }
6886
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006887 @Deprecated
6888 @Override
6889 public String getDeviceId(String callingPackage) {
6890 return getDeviceIdWithFeature(callingPackage, null);
6891 }
6892
Sanket Padawe7310cc72015-01-14 09:53:20 -08006893 /**
6894 * Returns the unique device ID of phone, for example, the IMEI for
6895 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6896 *
6897 * <p>Requires Permission:
6898 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6899 */
6900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006901 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006902 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006903 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006904 return null;
6905 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006906 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006907 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006908 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006909 return null;
6910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911
6912 final long identity = Binder.clearCallingIdentity();
6913 try {
6914 return phone.getDeviceId();
6915 } finally {
6916 Binder.restoreCallingIdentity(identity);
6917 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006918 }
6919
Ping Sunc67b7c22016-03-02 19:16:45 +08006920 /**
6921 * {@hide}
6922 * Returns the IMS Registration Status on a particular subid
6923 *
6924 * @param subId
6925 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006926 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006927 Phone phone = getPhone(subId);
6928 if (phone != null) {
6929 return phone.isImsRegistered();
6930 } else {
6931 return false;
6932 }
6933 }
6934
Santos Cordon7a1885b2015-02-03 11:15:19 -08006935 @Override
6936 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006943 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006944
Tyler Gunnf70ed162019-04-03 15:28:53 -07006945 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006946 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006947 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006949 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006950 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6951 }
6952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 }
6959
6960 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006961 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006962 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6963 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 Phone phone = getPhone(subscriptionId);
6967 if (phone == null) {
6968 return null;
6969 }
6970 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
6973 }
6974 }
6975
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006976 /**
6977 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006978 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006979 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 Phone phone = getPhone(subId);
6983 if (phone != null) {
6984 return phone.isWifiCallingEnabled();
6985 } else {
6986 return false;
6987 }
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006990 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006991 }
6992
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006993 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006994 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006995 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006996 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 Phone phone = getPhone(subId);
7000 if (phone != null) {
7001 return phone.isVideoEnabled();
7002 } else {
7003 return false;
7004 }
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007007 }
7008 }
7009
7010 /**
7011 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7012 * defined in {@link ImsRegistrationImplBase}.
7013 */
7014 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 Phone phone = getPhone(subId);
7018 if (phone != null) {
7019 return phone.getImsRegistrationTech();
7020 } else {
7021 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7022 }
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007025 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007026 }
7027
Stuart Scott8eef64f2015-04-08 15:13:54 -07007028 @Override
7029 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007030 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007031 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7032 return;
7033 }
7034
Svet Ganovcc087f82015-05-12 20:35:54 -07007035 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007036
Svet Ganovcc087f82015-05-12 20:35:54 -07007037 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007038 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7039 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007040 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007041 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007042 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007043 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007044 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7045 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007046 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007047 // There has been issues when Sms raw table somehow stores orphan
7048 // fragments. They lead to garbled message when new fragments come
7049 // in and combined with those stale ones. In case this happens again,
7050 // user can reset all network settings which will clean up this table.
7051 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007052 // Clean up IMS settings as well here.
7053 int slotId = getSlotIndex(subId);
7054 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7055 ImsManager.getInstance(mApp, slotId).factoryReset();
7056 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007057
7058 // Erase modem config if erase modem on network setting is enabled.
7059 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7060 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7061 if (configValue != null && Boolean.parseBoolean(configValue)) {
7062 sendEraseModemConfig(getDefaultPhone());
7063 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007064 } finally {
7065 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007066 }
7067 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007068
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007069 private void cleanUpSmsRawTable(Context context) {
7070 ContentResolver resolver = context.getContentResolver();
7071 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7072 resolver.delete(uri, null, null);
7073 }
7074
Narayan Kamath1c496c22015-04-16 14:40:19 +01007075 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007076 public String getSimLocaleForSubscriber(int subId) {
7077 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7078 final Phone phone = getPhone(subId);
7079 if (phone == null) {
7080 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007081 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 final long identity = Binder.clearCallingIdentity();
7084 try {
chen xu5d3637b2019-01-21 23:31:38 -08007085 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007086 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007087 if (info == null) {
7088 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7089 return null;
7090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 // Try and fetch the locale from the carrier properties or from the SIM language
7092 // preferences (EF-PL and EF-LI)...
7093 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007095 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7096 if (localeFromDefaultSim != null) {
7097 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7098 if (DBG) log("Using locale from subId: " + subId + " locale: "
7099 + localeFromDefaultSim);
7100 return localeFromDefaultSim.toLanguageTag();
7101 } else {
7102 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 }
7104 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 // The SIM language preferences only store a language (e.g. fr = French), not an
7107 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7108 // the SIM and carrier preferences does not include a country we add the country
7109 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007110 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007112 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 return mccLocale.toLanguageTag();
7114 }
7115
7116 if (DBG) log("No locale found - returning null");
7117 return null;
7118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007121 }
7122
7123 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007125 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007126 }
7127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 /**
7129 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7130 */
7131 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007132 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007133 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007134 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007135
Chenjie Yu1ba97252018-01-11 18:16:20 -08007136 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007137 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007138
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007139 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007140 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7141 * representing the state of the modem.
7142 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007143 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7144 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007145 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007146 */
7147 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007148 public void requestModemActivityInfo(ResultReceiver result) {
7149 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007150 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007154 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 } finally {
7156 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007157 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007158 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007159
Siddharth Rayb8114062018-06-17 15:02:38 -07007160 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7161 // less than total activity duration.
7162 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7163 if (info == null) {
7164 return false;
7165 }
7166 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007167 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7168 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7169
Siddharth Rayb8114062018-06-17 15:02:38 -07007170 return (info.isValid()
7171 && (info.getSleepTimeMillis() <= activityDurationMs)
7172 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007173 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007174 && (totalTxTimeMs <= activityDurationMs));
7175 }
7176
Jack Yu85bd38a2015-11-09 11:34:32 -08007177 /**
7178 * {@hide}
7179 * Returns the service state information on specified subscription.
7180 */
7181 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007182 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7183 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007186 return null;
7187 }
7188
Hall Liuf19c44f2018-11-27 14:38:17 -08007189 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7190 LocationAccessPolicy.checkLocationPermission(mApp,
7191 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7192 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007193 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007194 .setCallingPid(Binder.getCallingPid())
7195 .setCallingUid(Binder.getCallingUid())
7196 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007197 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007198 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007199 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7200 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007201 .build());
7202
7203 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7204 LocationAccessPolicy.checkLocationPermission(mApp,
7205 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7206 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007207 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007208 .setCallingPid(Binder.getCallingPid())
7209 .setCallingUid(Binder.getCallingUid())
7210 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007211 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007212 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007213 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7214 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007215 .build());
7216 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7217 boolean hasFinePermission =
7218 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7219 boolean hasCoarsePermission =
7220 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7221
Jack Yu479f40e2020-10-27 21:29:25 -07007222 final Phone phone = getPhone(subId);
7223 if (phone == null) {
7224 return null;
7225 }
7226
7227 boolean isCallingPackageDataService = phone.getDataServicePackages()
7228 .contains(callingPackage);
7229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 final long identity = Binder.clearCallingIdentity();
7231 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007232 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7233 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7234 Rlog.d(LOG_TAG,
7235 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7236 return null;
7237 }
7238
Hall Liuf19c44f2018-11-27 14:38:17 -08007239 ServiceState ss = phone.getServiceState();
7240
7241 // Scrub out the location info in ServiceState depending on what level of access
7242 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007243 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007244 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7245 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007249 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007250
7251 /**
7252 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7253 *
7254 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7255 * voicemail ringtone.
7256 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7257 * PhoneAccount.
7258 */
7259 @Override
7260 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7264 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007265 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007272 }
7273
7274 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007275 * Sets the per-account voicemail ringtone.
7276 *
7277 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7278 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7279 *
7280 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7281 * voicemail ringtone.
7282 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7283 * PhoneAccount.
7284 */
7285 @Override
7286 public void setVoicemailRingtoneUri(String callingPackage,
7287 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007288 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007290 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7291 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7293 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7294 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7300 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007301 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 }
7303 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007306 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007307 }
7308
7309 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007310 * Returns whether vibration is set for voicemail notification in Phone settings.
7311 *
7312 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7313 * voicemail vibration setting.
7314 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7315 */
7316 @Override
7317 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7321 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007322 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007329 }
7330
Youhan Wange64578a2016-05-02 15:32:42 -07007331 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007332 * Sets the per-account voicemail vibration.
7333 *
7334 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7335 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7336 *
7337 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7338 * voicemail vibration setting.
7339 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7340 * specific PhoneAccount.
7341 */
7342 @Override
7343 public void setVoicemailVibrationEnabled(String callingPackage,
7344 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007345 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007346 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007347 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7348 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7350 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7351 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007352 }
7353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7357 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007358 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 }
7360 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007363 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007364 }
7365
7366 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007367 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7368 *
7369 * @throws SecurityException if the caller does not have the required permission
7370 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007371 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007372 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007373 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007374 }
7375
7376 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007377 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7378 * permission.
7379 *
7380 * @throws SecurityException if the caller does not have the required permission
7381 */
7382 private void enforceSendSmsPermission() {
7383 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7384 }
7385
7386 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007387 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007388 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007389 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007390 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007391 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 final long identity = Binder.clearCallingIdentity();
7393 try {
7394 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007395 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 if (componentName == null) {
7397 throw new SecurityException(
7398 "Caller not current active visual voicemail package[null]");
7399 }
7400 String vvmPackage = componentName.getPackageName();
7401 if (!callingPackage.equals(vvmPackage)) {
7402 throw new SecurityException("Caller not current active visual voicemail package["
7403 + vvmPackage + "]");
7404 }
7405 } finally {
7406 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007407 }
7408 }
7409
7410 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007411 * Return the application ID for the app type.
7412 *
7413 * @param subId the subscription ID that this request applies to.
7414 * @param appType the uicc app type.
7415 * @return Application ID for specificied app type, or null if no uicc.
7416 */
7417 @Override
7418 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007419 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007420 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421
7422 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007423 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 if (phone == null) {
7425 return null;
7426 }
7427 String aid = null;
7428 try {
7429 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7430 .getApplicationByType(appType).getAid();
7431 } catch (Exception e) {
7432 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7433 }
7434 return aid;
7435 } finally {
7436 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007437 }
Youhan Wange64578a2016-05-02 15:32:42 -07007438 }
7439
Youhan Wang4001d252016-05-11 10:29:41 -07007440 /**
7441 * Return the Electronic Serial Number.
7442 *
7443 * @param subId the subscription ID that this request applies to.
7444 * @return ESN or null if error.
7445 */
7446 @Override
7447 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007448 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007449 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450
7451 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007452 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 if (phone == null) {
7454 return null;
7455 }
7456 String esn = null;
7457 try {
7458 esn = phone.getEsn();
7459 } catch (Exception e) {
7460 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7461 }
7462 return esn;
7463 } finally {
7464 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007465 }
Youhan Wang4001d252016-05-11 10:29:41 -07007466 }
7467
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007468 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007469 * Return the Preferred Roaming List Version.
7470 *
7471 * @param subId the subscription ID that this request applies to.
7472 * @return PRLVersion or null if error.
7473 */
7474 @Override
7475 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007476 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007477 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478
7479 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007480 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 if (phone == null) {
7482 return null;
7483 }
7484 String cdmaPrlVersion = null;
7485 try {
7486 cdmaPrlVersion = phone.getCdmaPrlVersion();
7487 } catch (Exception e) {
7488 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7489 }
7490 return cdmaPrlVersion;
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007493 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007494 }
7495
7496 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007497 * Get snapshot of Telephony histograms
7498 * @return List of Telephony histograms
7499 * @hide
7500 */
7501 @Override
7502 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7504 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 return RIL.getTelephonyRILTimingHistograms();
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007512 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007513
7514 /**
7515 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007516 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7517 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007518 * Require system privileges. In the future we may add this to carrier APIs.
7519 *
Michele Berionne482f8202018-11-27 18:57:59 -08007520 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007521 */
7522 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007523 @TelephonyManager.SetCarrierRestrictionResult
7524 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007525 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007527
Michele Berionne482f8202018-11-27 18:57:59 -08007528 if (carrierRestrictionRules == null) {
7529 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007530 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 final long identity = Binder.clearCallingIdentity();
7533 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007534 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007535 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007539 }
7540
7541 /**
7542 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007543 * Get the allowed carrier list and the excluded carrier list, including the priority between
7544 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007545 * Require system privileges. In the future we may add this to carrier APIs.
7546 *
Michele Berionne482f8202018-11-27 18:57:59 -08007547 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007548 */
7549 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007550 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007551 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553
7554 final long identity = Binder.clearCallingIdentity();
7555 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007556 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7557 if (response instanceof CarrierRestrictionRules) {
7558 return (CarrierRestrictionRules) response;
7559 }
7560 // Response is an Exception of some kind,
7561 // which is signalled to the user as a NULL retval
7562 return null;
7563 } catch (Exception e) {
7564 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7565 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007569 }
7570
fionaxu59545b42016-05-25 15:53:37 -07007571 /**
fionaxu59545b42016-05-25 15:53:37 -07007572 * Action set from carrier signalling broadcast receivers to enable/disable radio
7573 * @param subId the subscription ID that this action applies to.
7574 * @param enabled control enable or disable radio.
7575 * {@hide}
7576 */
7577 @Override
7578 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7579 enforceModifyPermission();
7580 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581
7582 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007583 if (phone == null) {
7584 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7585 return;
7586 }
7587 try {
7588 phone.carrierActionSetRadioEnabled(enabled);
7589 } catch (Exception e) {
7590 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007593 }
7594 }
7595
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007596 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007597 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7598 * network status based on which carrier apps could apply actions accordingly,
7599 * enable/disable default url handler for example.
7600 *
7601 * @param subId the subscription ID that this action applies to.
7602 * @param report control start/stop reporting the default network status.
7603 * {@hide}
7604 */
7605 @Override
7606 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7607 enforceModifyPermission();
7608 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609
7610 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007611 if (phone == null) {
7612 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7613 return;
7614 }
7615 try {
7616 phone.carrierActionReportDefaultNetworkStatus(report);
7617 } catch (Exception e) {
7618 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007621 }
7622 }
7623
7624 /**
fionaxud9622282017-07-17 17:51:30 -07007625 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7626 * @param subId the subscription ID that this action applies to.
7627 * {@hide}
7628 */
7629 @Override
7630 public void carrierActionResetAll(int subId) {
7631 enforceModifyPermission();
7632 final Phone phone = getPhone(subId);
7633 if (phone == null) {
7634 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7635 return;
7636 }
7637 try {
7638 phone.carrierActionResetAll();
7639 } catch (Exception e) {
7640 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7641 }
7642 }
7643
7644 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007645 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7646 * bug report is being generated.
7647 */
7648 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007649 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007650 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7651 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007652 writer.println("Permission Denial: can't dump Phone from pid="
7653 + Binder.getCallingPid()
7654 + ", uid=" + Binder.getCallingUid()
7655 + "without permission "
7656 + android.Manifest.permission.DUMP);
7657 return;
7658 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007659 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007660 }
Jack Yueb89b242016-06-22 13:27:47 -07007661
Brad Ebingerdac2f002018-04-03 15:17:52 -07007662 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007663 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7664 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7665 @NonNull String[] args) {
7666 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7667 this, in.getFileDescriptor(), out.getFileDescriptor(),
7668 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007669 }
7670
Jack Yueb89b242016-06-22 13:27:47 -07007671 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007672 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007673 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007674 * @param reason the reason the data enable change is taking place
7675 * @param enabled True if enabling the data, otherwise disabling.
7676 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007677 */
7678 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007679 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007680 boolean enabled) {
7681 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7682 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7683 try {
7684 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007685 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007686 } catch (SecurityException se) {
7687 enforceModifyPermission();
7688 }
7689 } else {
7690 enforceModifyPermission();
7691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subId);
7696 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007697 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7698 phone.carrierActionSetMeteredApnsEnabled(enabled);
7699 } else {
7700 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007705 }
7706 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007707
7708 /**
7709 * Get Client request stats
7710 * @return List of Client Request Stats
7711 * @hide
7712 */
7713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007714 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7715 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007717 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007718 return null;
7719 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007720 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 if (phone != null) {
7725 return phone.getClientRequestStats();
7726 }
7727
7728 return null;
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007732 }
7733
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007734 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007735 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007736 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007737 }
Jack Yueb4124c2017-02-16 15:32:43 -08007738
7739 /**
Grace Chen70990072017-03-24 17:21:30 -07007740 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007741 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007742 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007743 * @param state State of SIM (power down, power up, pass through)
7744 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7745 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7746 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007747 *
7748 **/
7749 @Override
Grace Chen70990072017-03-24 17:21:30 -07007750 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007751 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007752 Phone phone = PhoneFactory.getPhone(slotIndex);
7753
vagdeviaf9a5b92018-08-15 16:01:53 -07007754 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 final long identity = Binder.clearCallingIdentity();
7757 try {
7758 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007759 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 }
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007763 }
7764 }
Shuo Qiandd210312017-04-12 22:11:33 +00007765
Tyler Gunn65d45c22017-06-05 11:22:26 -07007766 private boolean isUssdApiAllowed(int subId) {
7767 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007769 if (configManager == null) {
7770 return false;
7771 }
7772 PersistableBundle pb = configManager.getConfigForSubId(subId);
7773 if (pb == null) {
7774 return false;
7775 }
7776 return pb.getBoolean(
7777 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7778 }
7779
Shuo Qiandd210312017-04-12 22:11:33 +00007780 /**
7781 * Check if phone is in emergency callback mode
7782 * @return true if phone is in emergency callback mode
7783 * @param subId sub id
7784 */
goneil9c5f4872017-12-05 14:07:56 -08007785 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007786 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007787 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007788 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789
7790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 if (phone != null) {
7793 return phone.isInEcm();
7794 } else {
7795 return false;
7796 }
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007799 }
7800 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007801
7802 /**
7803 * Get the current signal strength information for the given subscription.
7804 * Because this information is not updated when the device is in a low power state
7805 * it should not be relied-upon to be current.
7806 * @param subId Subscription index
7807 * @return the most recent cached signal strength info from the modem
7808 */
7809 @Override
7810 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 Phone p = getPhone(subId);
7814 if (p == null) {
7815 return null;
7816 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 return p.getSignalStrength();
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007822 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007823
Pengquan Meng77b7f132018-08-22 14:49:57 -07007824 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007825 * Get the current modem radio state for the given slot.
7826 * @param slotIndex slot index.
7827 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007828 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007829 * @return the current radio power state from the modem
7830 */
7831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007832 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007833 Phone phone = PhoneFactory.getPhone(slotIndex);
7834 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7836 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007837 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7838 }
7839
7840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 return phone.getRadioPowerState();
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
7846 }
7847 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7848 }
7849
7850 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007851 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7852 *
7853 * <p>Requires one of the following permissions:
7854 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7855 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7856 * privileges.
7857 *
7858 * @param subId subscription id
7859 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7860 * {@code false}.
7861 */
7862 @Override
7863 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007864 try {
7865 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7866 null);
7867 } catch (Exception e) {
7868 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7869 mApp, subId, "isDataRoamingEnabled");
7870 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007871
Pengquan Menga1bb6272018-09-06 09:59:22 -07007872 boolean isEnabled = false;
7873 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007874 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007875 Phone phone = getPhone(subId);
7876 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007877 } finally {
7878 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007880 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007881 }
7882
7883
7884 /**
7885 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7886 *
7887 * <p> Requires permission:
7888 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7889 * privileges.
7890 *
7891 * @param subId subscription id
7892 * @param isEnabled {@code true} means enable, {@code false} means disable.
7893 */
7894 @Override
7895 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7897 mApp, subId, "setDataRoamingEnabled");
7898
Pengquan Menga1bb6272018-09-06 09:59:22 -07007899 final long identity = Binder.clearCallingIdentity();
7900 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007901 Phone phone = getPhone(subId);
7902 if (phone != null) {
7903 phone.setDataRoamingEnabled(isEnabled);
7904 }
7905 } finally {
7906 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007907 }
7908 }
7909
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007910 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007911 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007912 TelephonyPermissions
7913 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007914 mApp, subId, "isManualNetworkSelectionAllowed");
7915
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007916 boolean isAllowed = true;
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007919 Phone phone = getPhone(subId);
7920 if (phone != null) {
7921 isAllowed = phone.isCspPlmnEnabled();
7922 }
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 return isAllowed;
7927 }
7928
7929 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007930 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007931 // Verify that tha callingPackage belongs to the calling UID
7932 mApp.getSystemService(AppOpsManager.class)
7933 .checkPackage(Binder.getCallingUid(), callingPackage);
7934
Jordan Liu1e142fc2019-04-22 15:10:43 -07007935 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007936 try {
7937 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007938 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007939 } catch (SecurityException e) {
7940 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7941 // has carrier privileges on an active UICC
7942 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7943 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007944 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007945 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007946 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007947
7948 final long identity = Binder.clearCallingIdentity();
7949 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007950 UiccController uiccController = UiccController.getInstance();
7951 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007952 if (hasReadPermission) {
7953 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007954 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007955
7956 // Remove private info if the caller doesn't have access
7957 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7958 for (UiccCardInfo cardInfo : cardInfos) {
7959 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7960 // is available
7961 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7962 if (card == null || card.getUiccProfile() == null) {
7963 // assume no access if the card or profile is unavailable
7964 filteredInfos.add(cardInfo.getUnprivileged());
7965 continue;
7966 }
7967 UiccProfile profile = card.getUiccProfile();
7968 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7969 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7970 filteredInfos.add(cardInfo);
7971 } else {
7972 filteredInfos.add(cardInfo.getUnprivileged());
7973 }
7974 }
7975 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007976 } finally {
7977 Binder.restoreCallingIdentity(identity);
7978 }
7979 }
7980
7981 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007982 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007983 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 final long identity = Binder.clearCallingIdentity();
7986 try {
7987 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7988 if (slots == null) {
7989 Rlog.i(LOG_TAG, "slots is null.");
7990 return null;
7991 }
7992
7993 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7994 for (int i = 0; i < slots.length; i++) {
7995 UiccSlot slot = slots[i];
7996 if (slot == null) {
7997 continue;
7998 }
7999
Jordan Liu7be7e652019-05-06 18:55:02 +00008000 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 UiccCard card = slot.getUiccCard();
8002 if (card != null) {
8003 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008004 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008005 cardId = slot.getEid();
8006 if (TextUtils.isEmpty(cardId)) {
8007 cardId = slot.getIccId();
8008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 }
8010
Jordan Liu857451f2019-05-09 16:35:35 -07008011 if (cardId != null) {
8012 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8013 // if cardId is an EID, it's all digits so this is fine
8014 cardId = IccUtils.stripTrailingFs(cardId);
8015 }
8016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 int cardState = 0;
8018 switch (slot.getCardState()) {
8019 case CARDSTATE_ABSENT:
8020 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8021 break;
8022 case CARDSTATE_PRESENT:
8023 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8024 break;
8025 case CARDSTATE_ERROR:
8026 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8027 break;
8028 case CARDSTATE_RESTRICTED:
8029 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8030 break;
8031 default:
8032 break;
8033
8034 }
8035
8036 infos[i] = new UiccSlotInfo(
8037 slot.isActive(),
8038 slot.isEuicc(),
8039 cardId,
8040 cardState,
8041 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008042 slot.isExtendedApduSupported(),
8043 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 }
8045 return infos;
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008048 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008049 }
8050
8051 @Override
8052 public boolean switchSlots(int[] physicalSlots) {
8053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054
8055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008061 }
Jack Yu4c988042018-02-27 15:30:01 -08008062
8063 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008064 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 return UiccController.getInstance().getCardIdForDefaultEuicc();
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
8070 }
8071 }
8072
Pengquan Meng85728fb2018-03-12 16:31:21 -07008073 /**
goneil47ffb6e2018-04-06 15:40:58 -07008074 * A test API to reload the UICC profile.
8075 *
8076 * <p>Requires that the calling app has permission
8077 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8078 * @hide
8079 */
8080 @Override
8081 public void refreshUiccProfile(int subId) {
8082 enforceModifyPermission();
8083
8084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 Phone phone = getPhone(subId);
8087 if (phone == null) {
8088 return;
8089 }
8090 UiccCard uiccCard = phone.getUiccCard();
8091 if (uiccCard == null) {
8092 return;
8093 }
8094 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8095 if (uiccProfile == null) {
8096 return;
8097 }
8098 uiccProfile.refresh();
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
8102 }
8103
8104 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008105 * Returns false if the mobile data is disabled by default, otherwise return true.
8106 */
8107 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008108 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008109 }
8110
8111 /**
8112 * Returns true if the data roaming is enabled by default, i.e the system property
8113 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8114 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8115 */
8116 private boolean getDefaultDataRoamingEnabled(int subId) {
8117 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008118 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008119 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008120 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8121 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8122 return isDataRoamingEnabled;
8123 }
8124
8125 /**
8126 * Returns the default network type for the given {@code subId}, if the default network type is
8127 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8128 */
8129 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008130 List<Integer> list = TelephonyProperties.default_network();
8131 int phoneId = mSubscriptionController.getPhoneId(subId);
8132 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8133 return list.get(phoneId);
8134 }
8135 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008136 }
fionaxua13278b2018-03-21 00:08:13 -07008137
8138 @Override
8139 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008140 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008141 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
8145 final Phone phone = getPhone(subId);
8146 if (phone == null) {
8147 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8148 return;
8149 }
chen xueaba88a2019-03-15 13:15:10 -07008150 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8151 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008152 if (carrierPrivilegeRules == null) {
8153 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8154 } else {
8155 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 } finally {
8158 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008159 }
fionaxua13278b2018-03-21 00:08:13 -07008160 }
8161
8162 @Override
8163 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008164 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165
8166 final long identity = Binder.clearCallingIdentity();
8167 try {
8168 final Phone phone = getPhone(subId);
8169 if (phone == null) {
8170 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8171 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8172 }
8173 return phone.getCarrierIdListVersion();
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008176 }
fionaxua13278b2018-03-21 00:08:13 -07008177 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008178
8179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008180 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8181 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008183 mApp, subId, callingPackage, callingFeatureId,
8184 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008185 return -1;
8186 }
8187
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
8190 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
8193 }
8194 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008195
8196 @Override
8197 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008198 TelephonyPermissions
8199 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 mApp, subId, "getCdmaRoamingMode");
8201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 }
8209
8210 @Override
8211 public boolean setCdmaRoamingMode(int subId, int mode) {
8212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8213 mApp, subId, "setCdmaRoamingMode");
8214
8215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
8223 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008224 public int getCdmaSubscriptionMode(int subId) {
8225 TelephonyPermissions
8226 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8227 mApp, subId, "getCdmaSubscriptionMode");
8228
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
8231 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
8235 }
8236
8237 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008238 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8240 mApp, subId, "setCdmaSubscriptionMode");
8241
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008249
sqianc5eccab2018-10-19 18:46:41 -07008250 @Override
sqian8c685422019-02-22 15:55:18 -08008251 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008252 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008253 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008254 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8255 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008256 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8257 }
8258 final long identity = Binder.clearCallingIdentity();
8259 try {
sqian854d44b2018-12-12 16:48:18 -08008260 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8261 for (Phone phone: PhoneFactory.getPhones()) {
8262 if (phone.getEmergencyNumberTracker() != null
8263 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8264 emergencyNumberListInternal.put(
8265 phone.getSubId(),
8266 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8267 }
sqian11b7a0e2018-12-05 18:48:28 -08008268 }
sqian854d44b2018-12-12 16:48:18 -08008269 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
sqianc5eccab2018-10-19 18:46:41 -07008273 }
8274
8275 @Override
sqian8c685422019-02-22 15:55:18 -08008276 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008278 if (!exactMatch) {
8279 TelephonyPermissions
8280 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008281 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008282 }
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
sqian854d44b2018-12-12 16:48:18 -08008285 for (Phone phone: PhoneFactory.getPhones()) {
8286 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008287 && phone.getEmergencyNumberTracker()
8288 .isEmergencyNumber(number, exactMatch)) {
8289 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008290 }
sqian11b7a0e2018-12-05 18:48:28 -08008291 }
8292 return false;
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
8297
sqianf4ca7ed2019-01-15 18:32:07 -08008298 /**
8299 * Update emergency number list for test mode.
8300 */
8301 @Override
8302 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8303 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8304 "updateEmergencyNumberListTestMode");
8305
8306 final long identity = Binder.clearCallingIdentity();
8307 try {
8308 for (Phone phone: PhoneFactory.getPhones()) {
8309 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8310 if (tracker != null) {
8311 tracker.executeEmergencyNumberTestModeCommand(action, num);
8312 }
8313 }
8314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
8317 }
8318
8319 /**
8320 * Get the full emergency number list for test mode.
8321 */
8322 @Override
8323 public List<String> getEmergencyNumberListTestMode() {
8324 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8325 "getEmergencyNumberListTestMode");
8326
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Set<String> emergencyNumbers = new HashSet<>();
8330 for (Phone phone: PhoneFactory.getPhones()) {
8331 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8332 if (tracker != null) {
8333 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8334 emergencyNumbers.add(num.getNumber());
8335 }
8336 }
8337 }
8338 return new ArrayList<>(emergencyNumbers);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
chen xud6b45bd2018-10-30 22:27:10 -07008344 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008345 public int getEmergencyNumberDbVersion(int subId) {
8346 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8347
8348 final long identity = Binder.clearCallingIdentity();
8349 try {
8350 final Phone phone = getPhone(subId);
8351 if (phone == null) {
8352 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8353 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8354 }
8355 return phone.getEmergencyNumberDbVersion();
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 }
8360
8361 @Override
8362 public void notifyOtaEmergencyNumberDbInstalled() {
8363 enforceModifyPermission();
8364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 for (Phone phone: PhoneFactory.getPhones()) {
8368 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8369 if (tracker != null) {
8370 tracker.updateOtaEmergencyNumberDatabase();
8371 }
8372 }
8373 } finally {
8374 Binder.restoreCallingIdentity(identity);
8375 }
8376 }
8377
8378 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008379 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008380 enforceActiveEmergencySessionPermission();
8381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 for (Phone phone: PhoneFactory.getPhones()) {
8385 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8386 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008387 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8388 }
8389 }
8390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
8393 }
8394
8395 @Override
8396 public void resetOtaEmergencyNumberDbFilePath() {
8397 enforceActiveEmergencySessionPermission();
8398
8399 final long identity = Binder.clearCallingIdentity();
8400 try {
8401 for (Phone phone: PhoneFactory.getPhones()) {
8402 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8403 if (tracker != null) {
8404 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008405 }
8406 }
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
8411
8412 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008413 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8414 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8415 Phone phone = getPhone(subId);
8416 if (phone == null) {
8417 return null;
8418 }
8419 final long identity = Binder.clearCallingIdentity();
8420 try {
8421 UiccProfile profile = UiccController.getInstance()
8422 .getUiccProfileForPhone(phone.getPhoneId());
8423 if (profile != null) {
8424 return profile.getCertsFromCarrierPrivilegeAccessRules();
8425 }
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 return null;
8430 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008431
8432 /**
8433 * Enable or disable a modem stack.
8434 */
8435 @Override
8436 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8437 enforceModifyPermission();
8438
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 Phone phone = PhoneFactory.getPhone(slotIndex);
8442 if (phone == null) {
8443 return false;
8444 } else {
8445 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8446 }
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
8449 }
8450 }
Michelecea4cf22018-12-21 15:00:11 -08008451
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008452 /**
8453 * Whether a modem stack is enabled or not.
8454 */
8455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8457 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008458 Phone phone = PhoneFactory.getPhone(slotIndex);
8459 if (phone == null) return false;
8460
8461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008462 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8463 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008464 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8465 }
8466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008469 try {
8470 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8471 } catch (NoSuchElementException ex) {
8472 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8473 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008474 } finally {
8475 Binder.restoreCallingIdentity(identity);
8476 }
8477 }
8478
Michelecea4cf22018-12-21 15:00:11 -08008479 @Override
Michele0ea7d782019-03-19 14:58:42 -07008480 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008481 enforceModifyPermission();
8482
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
8485 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008486 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008487 .commit();
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
8492
8493 @Override
Michele0ea7d782019-03-19 14:58:42 -07008494 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008495 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008497 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8498 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008499 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008500 }
Michelecea4cf22018-12-21 15:00:11 -08008501
8502 final long identity = Binder.clearCallingIdentity();
8503 try {
Michele0ea7d782019-03-19 14:58:42 -07008504 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008509
Michele0ea7d782019-03-19 14:58:42 -07008510 @TelephonyManager.IsMultiSimSupportedResult
8511 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008512 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8513 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8514 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008515 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8516 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008517 }
8518 // Check if the hardware supports multisim functionality. If usage of multisim is not
8519 // supported by the modem, indicate that it is restricted.
8520 PhoneCapability staticCapability =
8521 mPhoneConfigurationManager.getStaticPhoneCapability();
8522 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008523 loge("isMultiSimSupportedInternal: no static configuration available");
8524 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008525 }
Sarah Chin7caee492020-02-18 20:49:02 +00008526 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008527 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8528 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008529 }
8530 // Check if support of multiple SIMs is restricted by carrier
8531 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008532 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008533 }
8534
Michele0ea7d782019-03-19 14:58:42 -07008535 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008536 }
8537
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008538 /**
8539 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008540 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8541 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8542 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008543 * @param numOfSims number of active sims we want to switch to
8544 */
8545 @Override
8546 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008547 if (numOfSims == 1) {
8548 enforceModifyPermission();
8549 } else {
8550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8551 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8552 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008553 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008554
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008555 try {
Michele30b57b22019-03-01 12:01:14 -08008556 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008557 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008558 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8559 return;
8560 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008561 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8562 } finally {
8563 Binder.restoreCallingIdentity(identity);
8564 }
8565 }
8566
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008567 @Override
8568 public boolean isApplicationOnUicc(int subId, int appType) {
8569 enforceReadPrivilegedPermission("isApplicationOnUicc");
8570 Phone phone = getPhone(subId);
8571 if (phone == null) {
8572 return false;
8573 }
8574 final long identity = Binder.clearCallingIdentity();
8575 try {
8576 UiccCard uiccCard = phone.getUiccCard();
8577 if (uiccCard == null) {
8578 return false;
8579 }
8580 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8581 if (uiccProfile == null) {
8582 return false;
8583 }
8584 if (TelephonyManager.APPTYPE_SIM <= appType
8585 && appType <= TelephonyManager.APPTYPE_ISIM) {
8586 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8587 }
8588 return false;
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008594 /**
chen xub4baa772019-04-03 10:23:41 -07008595 * Get whether making changes to modem configurations will trigger reboot.
8596 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008597 */
8598 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008599 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8600 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008602 mApp, subId, callingPackage, callingFeatureId,
8603 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008604 return false;
8605 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008606 final long identity = Binder.clearCallingIdentity();
8607 try {
8608 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
8612 }
8613
Nathan Harold29f5f052019-02-15 13:41:57 -08008614 private void updateModemStateMetrics() {
8615 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8616 // TODO: check the state for each modem if the api is ready.
8617 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8618 }
8619
Pengquan Meng3889a572019-01-23 11:16:29 -08008620 @Override
8621 public int[] getSlotsMapping() {
8622 enforceReadPrivilegedPermission("getSlotsMapping");
8623
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8627 // All logical slots should have a mapping to a physical slot.
8628 int[] logicalSlotsMapping = new int[phoneCount];
8629 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8630 for (int i = 0; i < slotInfos.length; i++) {
8631 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8632 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8633 }
8634 }
8635 return logicalSlotsMapping;
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
8639 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008640
8641 /**
8642 * Get the IRadio HAL Version
8643 */
8644 @Override
8645 public int getRadioHalVersion() {
8646 Phone phone = getDefaultPhone();
8647 if (phone == null) return -1;
8648 HalVersion hv = phone.getHalVersion();
8649 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8650 return hv.major * 100 + hv.minor;
8651 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008652
8653 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008654 * Get the current calling package name.
8655 * @return the current calling package name
8656 */
8657 @Override
8658 public String getCurrentPackageName() {
8659 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8660 }
8661
8662 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008663 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8664 * corresponding network requests on a subId.
8665 *
8666 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008667 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008668 * 2) APN is un-metered for this subscription, or
8669 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008670 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008671 *
8672 * @return whether data is allowed for a apn type.
8673 *
8674 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008675 */
8676 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008677 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008678 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8679 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008680
8681 // Now that all security checks passes, perform the operation as ourselves.
8682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 Phone phone = getPhone(subId);
8685 if (phone == null) return false;
8686
Jack Yu41407ee2019-05-13 16:54:09 -07008687 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008688 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8689 } finally {
8690 Binder.restoreCallingIdentity(identity);
8691 }
8692 }
8693
8694 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008695 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008696 enforceReadPrivilegedPermission("isApnMetered");
8697
8698 // Now that all security checks passes, perform the operation as ourselves.
8699 final long identity = Binder.clearCallingIdentity();
8700 try {
8701 Phone phone = getPhone(subId);
8702 if (phone == null) return true; // By default return true.
8703
Jack Yu41407ee2019-05-13 16:54:09 -07008704 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008709
8710 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008711 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8712 int subscriptionId, IBooleanConsumer resultCallback) {
8713 enforceModifyPermission();
8714 long token = Binder.clearCallingIdentity();
8715 try {
8716 Phone phone = getPhone(subscriptionId);
8717 if (phone == null) {
8718 try {
8719 if (resultCallback != null) {
8720 resultCallback.accept(false);
8721 }
8722 } catch (RemoteException e) {
8723 // ignore
8724 }
8725 return;
8726 }
8727 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8728 Pair.create(specifiers, (x) -> {
8729 try {
8730 if (resultCallback != null) {
8731 resultCallback.accept(x);
8732 }
8733 } catch (RemoteException e) {
8734 // ignore
8735 }
8736 });
8737 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8738 } finally {
8739 Binder.restoreCallingIdentity(token);
8740 }
8741 }
8742
8743 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008744 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8745 TelephonyPermissions
8746 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8747 mApp, subId, "getSystemSelectionChannels");
8748 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8749 final long identity = Binder.clearCallingIdentity();
8750 try {
8751 List<RadioAccessSpecifier> specifiers =
8752 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8753 null, subId, workSource);
8754 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8755 return specifiers;
8756 } finally {
8757 Binder.restoreCallingIdentity(identity);
8758 }
8759 }
8760
8761 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008762 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008763 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008764 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8765 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8766 if (iccRecords == null) {
8767 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8768 return false;
8769 }
8770 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8771 }
8772
8773 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008774 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8775 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008776 if (callingPackage == null) {
8777 callingPackage = getCurrentPackageName();
8778 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008779 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8780 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008781 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8782 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008783 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8784 }
8785 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8786 Intent intent = new Intent();
8787 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8788 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8789 // Bring up choose default SMS subscription dialog right now
8790 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8791 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8792 mApp.startActivity(intent);
8793 }
chen xud5ca2d52019-05-28 15:20:57 -07008794
8795 @Override
8796 public String getMmsUAProfUrl(int subId) {
8797 //TODO investigate if this API should require proper permission check in R b/133791609
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008800 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8801 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8802 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8803 return carrierUAProfUrl;
8804 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008805 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8806 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008807 } finally {
8808 Binder.restoreCallingIdentity(identity);
8809 }
8810 }
8811
8812 @Override
8813 public String getMmsUserAgent(int subId) {
8814 //TODO investigate if this API should require proper permission check in R b/133791609
8815 final long identity = Binder.clearCallingIdentity();
8816 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008817 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8818 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8819 if (!TextUtils.isEmpty(carrierUserAgent)) {
8820 return carrierUserAgent;
8821 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008822 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8823 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 }
Jack Yub07d4972019-05-28 16:12:25 -07008828
8829 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008830 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8831 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008832
Jack Yub07d4972019-05-28 16:12:25 -07008833 final long identity = Binder.clearCallingIdentity();
8834 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008835 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008836 if (phone == null) return false;
8837
Hall Liua62f5da2020-09-25 10:42:19 -07008838 switch (policy) {
8839 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8840 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8841 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8842 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8843 default:
8844 throw new IllegalArgumentException(policy + " is not a valid policy");
8845 }
Jack Yub07d4972019-05-28 16:12:25 -07008846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
8849 }
8850
8851 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008852 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8853 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008854 enforceModifyPermission();
8855
changbettyd5c246e2019-12-24 15:40:37 +08008856 final long identity = Binder.clearCallingIdentity();
8857 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008858 Phone phone = getPhone(subscriptionId);
8859 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008860
Hall Liua62f5da2020-09-25 10:42:19 -07008861 switch (policy) {
8862 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8863 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8864 break;
8865 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8866 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8867 break;
8868 default:
8869 throw new IllegalArgumentException(policy + " is not a valid policy");
8870 }
changbettyd5c246e2019-12-24 15:40:37 +08008871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
8875
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008876 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008877 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008878 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8879 * otherwise.
8880 */
8881 @Override
8882 public void setCepEnabled(boolean isCepEnabled) {
8883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8884
8885 final long identity = Binder.clearCallingIdentity();
8886 try {
8887 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8888 for (Phone phone : PhoneFactory.getPhones()) {
8889 Phone defaultPhone = phone.getImsPhone();
8890 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8891 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8892 ImsPhoneCallTracker imsPhoneCallTracker =
8893 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8894 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8895 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8896 + imsPhone.getMsisdn());
8897 }
8898 }
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 }
allenwtsu46dcc572020-01-08 18:24:03 +08008903
8904 /**
8905 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8906 *
8907 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8908 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8909 * before being read.
8910 */
8911 @Override
8912 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8913 isCompressed) {
8914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8915 mApp, subId, "notifyRcsAutoConfigurationReceived");
8916 try {
8917 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8918 if (configBinder == null) {
8919 Rlog.e(LOG_TAG, "null result for getImsConfig");
8920 } else {
8921 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8922 }
8923 } catch (RemoteException e) {
8924 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8925 }
8926 }
zoey chene02881a2019-12-30 16:11:23 +08008927
8928 @Override
8929 public boolean isIccLockEnabled(int subId) {
8930 enforceReadPrivilegedPermission("isIccLockEnabled");
8931
8932 // Now that all security checks passes, perform the operation as ourselves.
8933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 Phone phone = getPhone(subId);
8936 if (phone != null && phone.getIccCard() != null) {
8937 return phone.getIccCard().getIccLockEnabled();
8938 } else {
8939 return false;
8940 }
8941 } finally {
8942 Binder.restoreCallingIdentity(identity);
8943 }
8944 }
8945
8946 /**
8947 * Set the ICC pin lock enabled or disabled.
8948 *
8949 * @return an integer representing the status of IccLock enabled or disabled in the following
8950 * three cases:
8951 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8952 * successfully.
8953 * - Positive number and zero for remaining password attempts.
8954 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8955 *
8956 */
8957 @Override
8958 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8959 enforceModifyPermission();
8960
8961 Phone phone = getPhone(subId);
8962 if (phone == null) {
8963 return 0;
8964 }
8965 // Now that all security checks passes, perform the operation as ourselves.
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8969 new Pair<Boolean, String>(enabled, password), phone, null);
8970 return attemptsRemaining;
8971
8972 } catch (Exception e) {
8973 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 return 0;
8978 }
8979
8980 /**
8981 * Change the ICC password used in ICC pin lock.
8982 *
8983 * @return an integer representing the status of IccLock changed in the following three cases:
8984 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8985 * - Positive number and zero for remaining password attempts.
8986 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8987 *
8988 */
8989 @Override
8990 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8991 enforceModifyPermission();
8992
8993 Phone phone = getPhone(subId);
8994 if (phone == null) {
8995 return 0;
8996 }
8997 // Now that all security checks passes, perform the operation as ourselves.
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9001 new Pair<String, String>(oldPassword, newPassword), phone, null);
9002 return attemptsRemaining;
9003
9004 } catch (Exception e) {
9005 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
9009 return 0;
9010 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009011
9012 /**
9013 * Request for receiving user activity notification
9014 */
9015 @Override
9016 public void requestUserActivityNotification() {
9017 if (!mNotifyUserActivity.get()
9018 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9019 mNotifyUserActivity.set(true);
9020 }
9021 }
9022
9023 /**
9024 * Called when userActivity is signalled in the power manager.
9025 * This is safe to call from any thread, with any window manager locks held or not.
9026 */
9027 @Override
9028 public void userActivity() {
9029 // ***************************************
9030 // * Inherited from PhoneWindowManager *
9031 // ***************************************
9032 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9033 // WITH ITS LOCKS HELD.
9034 //
9035 // This code must be VERY careful about the locks
9036 // it acquires.
9037 // In fact, the current code acquires way too many,
9038 // and probably has lurking deadlocks.
9039
9040 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9041 throw new SecurityException("Only the OS may call notifyUserActivity()");
9042 }
9043
9044 if (mNotifyUserActivity.getAndSet(false)) {
9045 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9046 USER_ACTIVITY_NOTIFICATION_DELAY);
9047 }
9048 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009049
9050 @Override
9051 public boolean canConnectTo5GInDsdsMode() {
9052 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9053 }
Jack Yud10cdd42020-09-28 20:28:01 -07009054
9055 @Override
9056 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9057 String callingFeatureId) {
9058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9059 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9060 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9061 }
9062
9063 Phone phone = getPhone(subId);
9064 if (phone == null) {
9065 throw new RuntimeException("phone is not available");
9066 }
9067 // Now that all security checks passes, perform the operation as ourselves.
9068 final long identity = Binder.clearCallingIdentity();
9069 try {
9070 return phone.getEquivalentHomePlmns();
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009075}