blob: 4473aaaf8cab405a3e81b49a8d020c03d6f96feb [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080092import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700117import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700134import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700175import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800176import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800179import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700180import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700181import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800182import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800183
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700184import java.io.FileDescriptor;
185import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800188import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800190import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100191import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700193import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800195import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800196import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198/**
199 * Implementation of the ITelephony interface.
200 */
Santos Cordon117fee72014-05-16 17:56:12 -0700201public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 private static final String LOG_TAG = "PhoneInterfaceManager";
203 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
204 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
207 // Message codes used with mMainThreadHandler
208 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700209 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
210 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700211 private static final int CMD_OPEN_CHANNEL = 9;
212 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
213 private static final int CMD_CLOSE_CHANNEL = 11;
214 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800215 private static final int CMD_NV_READ_ITEM = 13;
216 private static final int EVENT_NV_READ_ITEM_DONE = 14;
217 private static final int CMD_NV_WRITE_ITEM = 15;
218 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
219 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
220 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700221 private static final int CMD_RESET_MODEM_CONFIG = 19;
222 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800223 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
224 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
225 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
226 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800227 private static final int CMD_SEND_ENVELOPE = 25;
228 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000229 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
230 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700231 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
232 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
233 private static final int CMD_EXCHANGE_SIM_IO = 31;
234 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800235 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
236 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700237 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700239 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
240 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700241 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
242 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
243 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
244 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700245 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
246 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
247 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
248 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700249 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800250 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
251 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000252 private static final int CMD_SWITCH_SLOTS = 50;
253 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700254 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
255 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
256 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
257 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
258 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
259 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
260 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
261 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700262 private static final int CMD_GET_ALL_CELL_INFO = 60;
263 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
264 private static final int CMD_GET_CELL_LOCATION = 62;
265 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_MODEM_REBOOT = 64;
267 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700268 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
269 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800270 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
271 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700272 private static final int CMD_GET_MODEM_STATUS = 70;
273 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700274 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
275 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700276 private static final int CMD_ERASE_MODEM_CONFIG = 74;
277 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800278 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
279 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
280 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
281 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800282 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
283 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800284 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800285 private static final int CMD_GET_CALL_FORWARDING = 83;
286 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
287 private static final int CMD_SET_CALL_FORWARDING = 85;
288 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
289 private static final int CMD_GET_CALL_WAITING = 87;
290 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
291 private static final int CMD_SET_CALL_WAITING = 89;
292 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700293 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
294 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
295 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
296 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-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 Chincc055732020-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 Ebinger05f52c22019-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 Davidson0103e8c2020-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 Nalluri8ff344d2019-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 Sasindranb4a99602020-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 Liua1acea22020-09-18 19:04:59 -0700927 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-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);
sqian80370722020-01-29 15:02:51 -0800935 break;
Hall Liua1acea22020-09-18 19:04:59 -0700936 }
937 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700940 TelephonyManager.CallForwardingInfoCallback callback =
941 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
942 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800943 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700944 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -0700951 callForwardingInfo = new CallForwardingInfo(true,
952 callForwardInfo.reason,
953 callForwardInfo.number,
954 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800955 break;
956 }
957 }
958 // Didn't find a call forward info for voice call.
959 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700960 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
961 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800962 }
Hall Liua1acea22020-09-18 19:04:59 -0700963 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -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 Liuae527aa2020-09-29 17:10:18 -0700971 int errorCode = TelephonyManager
972 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700977 errorCode = TelephonyManager
978 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800979 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700980 errorCode = TelephonyManager
981 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800982 }
983 }
Hall Liua1acea22020-09-18 19:04:59 -0700984 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800985 }
sqian80370722020-01-29 15:02:51 -0800986 break;
Hall Liua1acea22020-09-18 19:04:59 -0700987 }
sqian80370722020-01-29 15:02:51 -0800988
Hall Liua1acea22020-09-18 19:04:59 -0700989 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700992 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800993 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-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,
sqian80370722020-01-29 15:02:51 -08001000 callForwardingInfoToSet.getReason(),
1001 callForwardingInfoToSet.getNumber(),
1002 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1003 break;
Hall Liua1acea22020-09-18 19:04:59 -07001004 }
sqian80370722020-01-29 15:02:51 -08001005
Hall Liua1acea22020-09-18 19:04:59 -07001006 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001009 Consumer<Integer> callback =
1010 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1011 request.argument).second;
1012 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001013 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001014 int errorCode = TelephonyManager.CallForwardingInfoCallback
1015 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-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 Liuae527aa2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager.CallForwardingInfoCallback
1021 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001023 errorCode = TelephonyManager.CallForwardingInfoCallback
1024 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001025 }
1026 }
1027 callback.accept(errorCode);
1028 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001029 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001030 }
sqian80370722020-01-29 15:02:51 -08001031 break;
Hall Liua1acea22020-09-18 19:04:59 -07001032 }
sqian80370722020-01-29 15:02:51 -08001033
Hall Liua1acea22020-09-18 19:04:59 -07001034 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1037 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1038 break;
Hall Liua1acea22020-09-18 19:04:59 -07001039 }
sqian80370722020-01-29 15:02:51 -08001040
Hall Liua1acea22020-09-18 19:04:59 -07001041 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001044 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -07001052 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001053 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001054 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1055 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001056 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001057 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -07001075 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001076 break;
Hall Liua1acea22020-09-18 19:04:59 -07001077 }
sqian80370722020-01-29 15:02:51 -08001078
Hall Liua1acea22020-09-18 19:04:59 -07001079 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001082 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1083 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001084 break;
Hall Liua1acea22020-09-18 19:04:59 -07001085 }
sqian80370722020-01-29 15:02:51 -08001086
Hall Liua1acea22020-09-18 19:04:59 -07001087 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-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) {
sqian80370722020-01-29 15:02:51 -08001094 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-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);
sqian80370722020-01-29 15:02:51 -08001109 }
sqian80370722020-01-29 15:02:51 -08001110 break;
Hall Liua1acea22020-09-18 19:04:59 -07001111 }
sqian80370722020-01-29 15:02:51 -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);
sqian1a1be542020-03-05 11:37:28 -08001172 } else {
1173 ResultReceiver result = (ResultReceiver) request.argument;
1174 Bundle bundle = new Bundle();
1175 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1176 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1177 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001178 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001179 break;
1180
1181 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001184 ResultReceiver result = (ResultReceiver) request.argument;
1185
1186 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001187 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001188 // Update the last modem activity info and the result of the request.
1189 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1190 if (isModemActivityInfoValid(info)) {
1191 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1192 int[] txTimeMs = info.getTransmitTimeMillis();
1193 int[] lastModemTxTimeMs = mLastModemActivityInfo
1194 .getTransmitTimeMillis();
1195 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1196 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1197 }
1198 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1199 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1200 + mLastModemActivityInfo.getSleepTimeMillis());
1201 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1202 + mLastModemActivityInfo.getIdleTimeMillis());
1203 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1204 mLastModemActivityInfo.setReceiveTimeMillis(
1205 info.getReceiveTimeMillis()
1206 + mLastModemActivityInfo.getReceiveTimeMillis());
1207 }
1208 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1209 mLastModemActivityInfo.getSleepTimeMillis(),
1210 mLastModemActivityInfo.getIdleTimeMillis(),
1211 mLastModemActivityInfo.getTransmitTimeMillis(),
1212 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 } else {
1214 if (ar.result == null) {
1215 loge("queryModemActivityInfo: Empty response");
1216 } else if (ar.exception instanceof CommandException) {
1217 loge("queryModemActivityInfo: CommandException: " +
1218 ar.exception);
1219 } else {
1220 loge("queryModemActivityInfo: Unknown exception");
1221 }
1222 }
sqian1a1be542020-03-05 11:37:28 -08001223 Bundle bundle = new Bundle();
1224 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1225 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001226 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 break;
1228
Meng Wang1a7c35a2016-05-05 20:56:15 -07001229 case CMD_SET_ALLOWED_CARRIERS:
1230 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001231 CarrierRestrictionRules argument =
1232 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001233 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001234 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001235 break;
1236
1237 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 if (ar.exception == null && ar.result != null) {
1241 request.result = ar.result;
1242 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001243 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1244 if (ar.exception instanceof CommandException) {
1245 loge("setAllowedCarriers: CommandException: " + ar.exception);
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1249 request.result =
1250 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001252 } else {
1253 loge("setAllowedCarriers: Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001257 break;
1258
1259 case CMD_GET_ALLOWED_CARRIERS:
1260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001262 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 break;
1264
1265 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null && ar.result != null) {
1269 request.result = ar.result;
1270 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001271 request.result = new IllegalStateException(
1272 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 if (ar.result == null) {
1274 loge("getAllowedCarriers: Empty response");
1275 } else if (ar.exception instanceof CommandException) {
1276 loge("getAllowedCarriers: CommandException: " +
1277 ar.exception);
1278 } else {
1279 loge("getAllowedCarriers: Unknown exception");
1280 }
1281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001282 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 break;
1284
Nathan Haroldb3014052017-01-25 15:57:32 -08001285 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1286 ar = (AsyncResult) msg.obj;
1287 request = (MainThreadRequest) ar.userObj;
1288 if (ar.exception == null && ar.result != null) {
1289 request.result = ar.result;
1290 } else {
1291 request.result = new IllegalArgumentException(
1292 "Failed to retrieve Forbidden Plmns");
1293 if (ar.result == null) {
1294 loge("getForbiddenPlmns: Empty response");
1295 } else {
1296 loge("getForbiddenPlmns: Unknown exception");
1297 }
1298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001299 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001300 break;
1301
1302 case CMD_GET_FORBIDDEN_PLMNS:
1303 request = (MainThreadRequest) msg.obj;
1304 uiccCard = getUiccCardFromRequest(request);
1305 if (uiccCard == null) {
1306 loge("getForbiddenPlmns() UiccCard is null");
1307 request.result = new IllegalArgumentException(
1308 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001310 break;
1311 }
1312 Integer appType = (Integer) request.argument;
1313 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1314 if (uiccApp == null) {
1315 loge("getForbiddenPlmns() no app with specified type -- "
1316 + appType);
1317 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001319 break;
1320 } else {
1321 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1322 + " specified type -- " + appType);
1323 }
1324 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1325 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1326 onCompleted);
1327 break;
1328
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001329 case CMD_SWITCH_SLOTS:
1330 request = (MainThreadRequest) msg.obj;
1331 int[] physicalSlots = (int[]) request.argument;
1332 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1333 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1334 break;
1335
1336 case EVENT_SWITCH_SLOTS_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001340 notifyRequester(request);
1341 break;
1342 case CMD_GET_NETWORK_SELECTION_MODE:
1343 request = (MainThreadRequest) msg.obj;
1344 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1345 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1346 break;
1347
1348 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 if (ar.exception != null) {
1352 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1353 } else {
1354 int mode = ((int[]) ar.result)[0];
1355 if (mode == 0) {
1356 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1357 } else {
1358 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1359 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001360 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001361 notifyRequester(request);
1362 break;
1363 case CMD_GET_CDMA_ROAMING_MODE:
1364 request = (MainThreadRequest) msg.obj;
1365 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1366 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1367 break;
1368 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
1371 if (ar.exception != null) {
1372 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1373 } else {
1374 request.result = ((int[]) ar.result)[0];
1375 }
1376 notifyRequester(request);
1377 break;
1378 case CMD_SET_CDMA_ROAMING_MODE:
1379 request = (MainThreadRequest) msg.obj;
1380 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1381 int mode = (int) request.argument;
1382 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1383 break;
1384 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 request.result = ar.exception == null;
1388 notifyRequester(request);
1389 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001390 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1391 request = (MainThreadRequest) msg.obj;
1392 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1393 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1394 break;
1395 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception != null) {
1399 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1400 } else {
1401 request.result = ((int[]) ar.result)[0];
1402 }
1403 notifyRequester(request);
1404 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001405 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1408 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001409 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1410 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 break;
1412 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 request.result = ar.exception == null;
1416 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001417 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001418 case CMD_GET_ALL_CELL_INFO:
1419 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001420 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001421 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001422 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001423 case EVENT_GET_ALL_CELL_INFO_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001426 // If a timeout occurs, the response will be null
1427 request.result = (ar.exception == null && ar.result != null)
1428 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001429 synchronized (request) {
1430 request.notifyAll();
1431 }
1432 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001433 case CMD_REQUEST_CELL_INFO_UPDATE:
1434 request = (MainThreadRequest) msg.obj;
1435 request.phone.requestCellInfoUpdate(request.workSource,
1436 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1437 break;
1438 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1442 try {
1443 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001444 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001445 cb.onError(
1446 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1447 ar.exception.getClass().getName(),
1448 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001449 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001450 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001451 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001452 } else {
1453 // use the result as returned
1454 cb.onCellInfo((List<CellInfo>) ar.result);
1455 }
1456 } catch (RemoteException re) {
1457 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1458 }
1459 break;
Sarah Chincc055732020-11-18 13:39:35 -08001460 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 request = (MainThreadRequest) msg.obj;
1462 WorkSource ws = (WorkSource) request.argument;
1463 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001464 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 break;
Sarah Chincc055732020-11-18 13:39:35 -08001466 }
1467 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception == null) {
1471 request.result = ar.result;
1472 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001473 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001475 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 }
1477
1478 synchronized (request) {
1479 request.notifyAll();
1480 }
1481 break;
Sarah Chincc055732020-11-18 13:39:35 -08001482 }
chen xu6dac5ab2018-10-26 17:39:23 -07001483 case CMD_MODEM_REBOOT:
1484 request = (MainThreadRequest) msg.obj;
1485 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001486 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001487 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001488 case EVENT_CMD_MODEM_REBOOT_DONE:
1489 handleNullReturnEvent(msg, "rebootModem");
1490 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001491 case CMD_REQUEST_ENABLE_MODEM:
1492 request = (MainThreadRequest) msg.obj;
1493 boolean enable = (boolean) request.argument;
1494 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001495 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001496 PhoneConfigurationManager.getInstance()
1497 .enablePhone(request.phone, enable, onCompleted);
1498 break;
1499 case EVENT_ENABLE_MODEM_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001503 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001504 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001505 if ((boolean) request.result) {
1506 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1507 updateModemStateMetrics();
1508 } else {
1509 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1510 + ar.exception);
1511 }
1512 notifyRequester(request);
1513 break;
1514 case CMD_GET_MODEM_STATUS:
1515 request = (MainThreadRequest) msg.obj;
1516 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1517 PhoneConfigurationManager.getInstance()
1518 .getPhoneStatusFromModem(request.phone, onCompleted);
1519 break;
1520 case EVENT_GET_MODEM_STATUS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 int id = request.phone.getPhoneId();
1524 if (ar.exception == null && ar.result != null) {
1525 request.result = ar.result;
1526 //update the cache as modem status has changed
1527 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1528 (boolean) request.result);
1529 } else {
1530 // Return true if modem status cannot be retrieved. For most cases,
1531 // modem status is on. And for older version modems, GET_MODEM_STATUS
1532 // and disable modem are not supported. Modem is always on.
1533 // TODO: this should be fixed in R to support a third
1534 // status UNKNOWN b/131631629
1535 request.result = true;
1536 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1537 + ar.exception);
1538 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001539 notifyRequester(request);
1540 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001541 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1544 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1545 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1546 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1547 break;
1548 }
1549 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1553 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1554 args.second.accept(ar.exception == null);
1555 notifyRequester(request);
1556 break;
1557 }
Sarah Chincc055732020-11-18 13:39:35 -08001558 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1561 Phone phone = getPhoneFromRequest(request);
1562 if (phone != null) {
1563 phone.getSystemSelectionChannels(onCompleted);
1564 } else {
1565 loge("getSystemSelectionChannels: No phone object");
1566 request.result = new ArrayList<RadioAccessSpecifier>();
1567 notifyRequester(request);
1568 }
1569 break;
1570 }
1571 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 if (ar.exception == null && ar.result != null) {
1575 request.result = ar.result;
1576 } else {
1577 request.result = new IllegalArgumentException(
1578 "Failed to retrieve system selection channels");
1579 if (ar.result == null) {
1580 loge("getSystemSelectionChannels: Empty response");
1581 } else {
1582 loge("getSystemSelectionChannels: Unknown exception");
1583 }
1584 }
1585 notifyRequester(request);
1586 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001587 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
1590 if (ar.exception == null && ar.result != null) {
1591 request.result = ar.result;
1592 } else {
1593 request.result = -1;
1594 loge("Failed to set Forbidden Plmns");
1595 if (ar.result == null) {
1596 loge("setForbidenPlmns: Empty response");
1597 } else if (ar.exception != null) {
1598 loge("setForbiddenPlmns: Exception: " + ar.exception);
1599 request.result = -1;
1600 } else {
1601 loge("setForbiddenPlmns: Unknown exception");
1602 }
1603 }
1604 notifyRequester(request);
1605 break;
1606 case CMD_SET_FORBIDDEN_PLMNS:
1607 request = (MainThreadRequest) msg.obj;
1608 uiccCard = getUiccCardFromRequest(request);
1609 if (uiccCard == null) {
1610 loge("setForbiddenPlmns: UiccCard is null");
1611 request.result = -1;
1612 notifyRequester(request);
1613 break;
1614 }
1615 Pair<Integer, List<String>> setFplmnsArgs =
1616 (Pair<Integer, List<String>>) request.argument;
1617 appType = setFplmnsArgs.first;
1618 List<String> fplmns = setFplmnsArgs.second;
1619 uiccApp = uiccCard.getApplicationByType(appType);
1620 if (uiccApp == null) {
1621 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1622 request.result = -1;
1623 loge("Failed to get UICC App");
1624 notifyRequester(request);
1625 } else {
1626 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1627 ((SIMRecords) uiccApp.getIccRecords())
1628 .setForbiddenPlmns(onCompleted, fplmns);
1629 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001630 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001631 case CMD_ERASE_MODEM_CONFIG:
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1634 defaultPhone.eraseModemConfig(onCompleted);
1635 break;
1636 case EVENT_ERASE_MODEM_CONFIG_DONE:
1637 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001638 break;
zoey chenf95ca592019-12-30 16:11:23 +08001639
1640 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1643 Pair<String, String> changed = (Pair<String, String>) request.argument;
1644 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1645 changed.first, changed.second, onCompleted);
1646 break;
1647 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 if (ar.exception == null) {
1651 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1652 } else {
1653 request.result = msg.arg1;
1654 }
1655 notifyRequester(request);
1656 break;
1657
1658 case CMD_SET_ICC_LOCK_ENABLED:
1659 request = (MainThreadRequest) msg.obj;
1660 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1661 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1662 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1663 enabled.first, enabled.second, onCompleted);
1664 break;
1665 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 if (ar.exception == null) {
1669 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1670 } else {
1671 request.result = msg.arg1;
1672 }
1673 notifyRequester(request);
1674 break;
1675
Peter Wangdafb9ac2020-01-15 14:13:38 -08001676 case MSG_NOTIFY_USER_ACTIVITY:
1677 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001678 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001679 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1680 getDefaultPhone().getContext().sendBroadcastAsUser(
1681 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1682 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 default:
1684 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1685 break;
1686 }
1687 }
Jake Hambye994d462014-02-03 13:10:13 -08001688
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 private void notifyRequester(MainThreadRequest request) {
1690 synchronized (request) {
1691 request.notifyAll();
1692 }
1693 }
1694
Jake Hambye994d462014-02-03 13:10:13 -08001695 private void handleNullReturnEvent(Message msg, String command) {
1696 AsyncResult ar = (AsyncResult) msg.obj;
1697 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = true;
1700 } else {
1701 request.result = false;
1702 if (ar.exception instanceof CommandException) {
1703 loge(command + ": CommandException: " + ar.exception);
1704 } else {
1705 loge(command + ": Unknown exception");
1706 }
1707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001708 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
1712 /**
1713 * Posts the specified command to be executed on the main thread,
1714 * waits for the request to complete, and returns the result.
1715 * @see #sendRequestAsync
1716 */
1717 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001718 return sendRequest(
1719 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001720 }
1721
1722 /**
1723 * Posts the specified command to be executed on the main thread,
1724 * waits for the request to complete, and returns the result.
1725 * @see #sendRequestAsync
1726 */
1727 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1728 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001729 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
1732 /**
1733 * Posts the specified command to be executed on the main thread,
1734 * waits for the request to complete, and returns the result.
1735 * @see #sendRequestAsync
1736 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001737 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001738 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001739 }
1740
1741 /**
1742 * Posts the specified command to be executed on the main thread,
1743 * waits for the request to complete, and returns the result.
1744 * @see #sendRequestAsync
1745 */
Nathan Harold92bed182018-10-12 18:16:49 -07001746 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1747 return sendRequest(command, argument, subId, null, workSource);
1748 }
1749
1750 /**
1751 * Posts the specified command to be executed on the main thread,
1752 * waits for the request to complete, and returns the result.
1753 * @see #sendRequestAsync
1754 */
1755 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1756 return sendRequest(
1757 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1758 }
1759
1760 /**
1761 * Posts the specified command to be executed on the main thread,
1762 * waits for the request to complete, and returns the result.
1763 * @see #sendRequestAsync
1764 */
1765 private Object sendRequest(
1766 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1768 throw new RuntimeException("This method will deadlock if called from the main thread.");
1769 }
1770
Nathan Harold92bed182018-10-12 18:16:49 -07001771 MainThreadRequest request = null;
1772 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1773 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1774 } else if (phone != null) {
1775 request = new MainThreadRequest(argument, phone, workSource);
1776 } else {
1777 request = new MainThreadRequest(argument, subId, workSource);
1778 }
1779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 Message msg = mMainThreadHandler.obtainMessage(command, request);
1781 msg.sendToTarget();
1782
1783 // Wait for the request to complete
1784 synchronized (request) {
1785 while (request.result == null) {
1786 try {
1787 request.wait();
1788 } catch (InterruptedException e) {
1789 // Do nothing, go back and wait until the request is complete
1790 }
1791 }
1792 }
1793 return request.result;
1794 }
1795
1796 /**
1797 * Asynchronous ("fire and forget") version of sendRequest():
1798 * Posts the specified command to be executed on the main thread, and
1799 * returns immediately.
1800 * @see #sendRequest
1801 */
1802 private void sendRequestAsync(int command) {
1803 mMainThreadHandler.sendEmptyMessage(command);
1804 }
1805
1806 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001807 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001808 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001809 */
1810 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001811 sendRequestAsync(command, argument, null, null);
1812 }
1813
1814 /**
1815 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1816 * @see {@link #sendRequest(int,Object)}
1817 */
1818 private void sendRequestAsync(
1819 int command, Object argument, Phone phone, WorkSource workSource) {
1820 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001821 Message msg = mMainThreadHandler.obtainMessage(command, request);
1822 msg.sendToTarget();
1823 }
1824
1825 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 * Initialize the singleton PhoneInterfaceManager instance.
1827 * This is only done once, at startup, from PhoneApp.onCreate().
1828 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001829 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 synchronized (PhoneInterfaceManager.class) {
1831 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001832 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 } else {
1834 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1835 }
1836 return sInstance;
1837 }
1838 }
1839
1840 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001841 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001844 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001845 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1847 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001848 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001849 mTelephonySharedPreferences =
1850 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001851 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001852 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001853 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 publish();
1856 }
1857
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001858 private Phone getDefaultPhone() {
1859 Phone thePhone = getPhone(getDefaultSubscription());
1860 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 private void publish() {
1864 if (DBG) log("publish: " + this);
1865
Peter Wangc035ce42020-01-08 21:00:22 -08001866 TelephonyFrameworkInitializer
1867 .getTelephonyServiceManager()
1868 .getTelephonyServiceRegisterer()
1869 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Stuart Scott584921c2015-01-15 17:10:34 -08001872 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001873 if (request.phone != null) {
1874 return request.phone;
1875 } else {
1876 return getPhoneFromSubId(request.subId);
1877 }
1878 }
1879
1880 private Phone getPhoneFromSubId(int subId) {
1881 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1882 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001883 }
1884
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001885 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1886 Phone phone = getPhoneFromRequest(request);
1887 return phone == null ? null :
1888 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1889 }
1890
Wink Saville36469e72014-06-11 15:17:00 -07001891 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001892 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001893 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001896 private void sendEraseModemConfig(Phone phone) {
1897 if (phone != null) {
1898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1899 mApp, phone.getSubId(), "eraseModemConfig");
1900 final long identity = Binder.clearCallingIdentity();
1901 try {
1902 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1903 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
1906 }
1907 }
1908 }
1909
Peter Wang050bb052020-01-13 23:33:09 -08001910 private boolean isImsAvailableOnDevice() {
1911 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1912 if (pm == null) {
1913 // For some reason package manger is not available.. This will fail internally anyway,
1914 // so do not throw error and allow.
1915 return true;
1916 }
1917 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1918 }
1919
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001921 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Wink Savilleb564aae2014-10-23 10:18:09 -07001924 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 if (DBG) log("dial: " + number);
1926 // No permission check needed here: This is just a wrapper around the
1927 // ACTION_DIAL intent, which is available to any app since it puts up
1928 // the UI before it does anything.
1929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 String url = createTelUrl(number);
1933 if (url == null) {
1934 return;
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 // PENDING: should we just silently fail if phone is offhook or ringing?
1938 PhoneConstants.State state = mCM.getState(subId);
1939 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1940 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1942 mApp.startActivity(intent);
1943 }
1944 } finally {
1945 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947 }
1948
1949 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001950 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001951 }
1952
Wink Savilleb564aae2014-10-23 10:18:09 -07001953 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 if (DBG) log("call: " + number);
1955
1956 // This is just a wrapper around the ACTION_CALL intent, but we still
1957 // need to do a permission check since we're calling startActivity()
1958 // from the context of the phone app.
1959 enforceCallPermission();
1960
Jordan Liu1617b712019-07-10 15:06:26 -07001961 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 != AppOpsManager.MODE_ALLOWED) {
1963 return;
1964 }
1965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 String url = createTelUrl(number);
1969 if (url == null) {
1970 return;
1971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973 boolean isValid = false;
1974 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1975 if (slist != null) {
1976 for (SubscriptionInfo subInfoRecord : slist) {
1977 if (subInfoRecord.getSubscriptionId() == subId) {
1978 isValid = true;
1979 break;
1980 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001981 }
Wink Saville08874612014-08-31 19:19:58 -07001982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 if (!isValid) {
1984 return;
1985 }
Wink Saville08874612014-08-31 19:19:58 -07001986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1988 intent.putExtra(SUBSCRIPTION_KEY, subId);
1989 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1990 mApp.startActivity(intent);
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
1993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001997 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001998 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1999 }
2000
Wink Savilleb564aae2014-10-23 10:18:09 -07002001 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002002 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002003 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2004 }
2005
Wink Savilleb564aae2014-10-23 10:18:09 -07002006 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002008
2009 final long identity = Binder.clearCallingIdentity();
2010 try {
2011 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2012 checkSimPin.start();
2013 return checkSimPin.unlockSim(null, pin);
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
2016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public int[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2025 checkSimPuk.start();
2026 return checkSimPuk.unlockSim(puk, pin);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
2029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
2032 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002033 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 * a synchronous one.
2035 */
2036 private static class UnlockSim extends Thread {
2037
2038 private final IccCard mSimCard;
2039
2040 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002041 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2042 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043
2044 // For replies from SimCard interface
2045 private Handler mHandler;
2046
2047 // For async handler to identify request type
2048 private static final int SUPPLY_PIN_COMPLETE = 100;
2049
2050 public UnlockSim(IccCard simCard) {
2051 mSimCard = simCard;
2052 }
2053
2054 @Override
2055 public void run() {
2056 Looper.prepare();
2057 synchronized (UnlockSim.this) {
2058 mHandler = new Handler() {
2059 @Override
2060 public void handleMessage(Message msg) {
2061 AsyncResult ar = (AsyncResult) msg.obj;
2062 switch (msg.what) {
2063 case SUPPLY_PIN_COMPLETE:
2064 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2065 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002066 mRetryCount = msg.arg1;
2067 if (ar.exception != null) {
2068 if (ar.exception instanceof CommandException &&
2069 ((CommandException)(ar.exception)).getCommandError()
2070 == CommandException.Error.PASSWORD_INCORRECT) {
2071 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002072 } //When UiccCardApp dispose,handle message and return exception
2073 else if (ar.exception instanceof CommandException &&
2074 ((CommandException) (ar.exception)).getCommandError()
2075 == CommandException.Error.ABORTED) {
2076 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002077 } else {
2078 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2079 }
2080 } else {
2081 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 mDone = true;
2084 UnlockSim.this.notifyAll();
2085 }
2086 break;
2087 }
2088 }
2089 };
2090 UnlockSim.this.notifyAll();
2091 }
2092 Looper.loop();
2093 }
2094
2095 /*
2096 * Use PIN or PUK to unlock SIM card
2097 *
2098 * If PUK is null, unlock SIM card with PIN
2099 *
2100 * If PUK is not null, unlock SIM card with PUK and set PIN code
2101 */
Wink Saville9de0f752013-10-22 19:04:03 -07002102 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103
2104 while (mHandler == null) {
2105 try {
2106 wait();
2107 } catch (InterruptedException e) {
2108 Thread.currentThread().interrupt();
2109 }
2110 }
2111 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2112
2113 if (puk == null) {
2114 mSimCard.supplyPin(pin, callback);
2115 } else {
2116 mSimCard.supplyPuk(puk, pin, callback);
2117 }
2118
2119 while (!mDone) {
2120 try {
2121 Log.d(LOG_TAG, "wait for done");
2122 wait();
2123 } catch (InterruptedException e) {
2124 // Restore the interrupted status
2125 Thread.currentThread().interrupt();
2126 }
2127 }
2128 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002129 int[] resultArray = new int[2];
2130 resultArray[0] = mResult;
2131 resultArray[1] = mRetryCount;
2132 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134 }
2135
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002136 /**
2137 * This method has been removed due to privacy and stability concerns.
2138 */
2139 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002141 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2142 return;
Wink Saville36469e72014-06-11 15:17:00 -07002143 }
2144
Nathan Harold1f889d82020-06-04 17:05:26 -07002145 @Override
2146 public void updateServiceLocationWithPackageName(String callingPackage) {
2147 mApp.getSystemService(AppOpsManager.class)
2148 .checkPackage(Binder.getCallingUid(), callingPackage);
2149
2150 final int targetSdk = getTargetSdk(callingPackage);
2151 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2152 // Callers targeting S have no business invoking this method.
2153 return;
2154 }
2155
2156 LocationAccessPolicy.LocationPermissionResult locationResult =
2157 LocationAccessPolicy.checkLocationPermission(mApp,
2158 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2159 .setCallingPackage(callingPackage)
2160 .setCallingFeatureId(null)
2161 .setCallingPid(Binder.getCallingPid())
2162 .setCallingUid(Binder.getCallingUid())
2163 .setMethod("updateServiceLocation")
2164 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2165 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2166 .build());
2167 // Apps that lack location permission have no business calling this method;
2168 // however, because no permission was declared in the public API, denials must
2169 // all be "soft".
2170 switch (locationResult) {
2171 case DENIED_HARD: /* fall through */
2172 case DENIED_SOFT:
2173 return;
2174 }
2175
2176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177 final long identity = Binder.clearCallingIdentity();
2178 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002179 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002181 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182 }
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002188 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 @Override
2190 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002191 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002194
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002196 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2197 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2198 callingFeatureId);
2199 }
2200
2201 @Deprecated
2202 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002203 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002204 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2205 }
2206
2207 @Override
2208 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2209 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002211 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002212 return false;
2213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 return isRadioOnForSubscriber(subId);
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
2220 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 }
2222
2223 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 final Phone phone = getPhone(subId);
2227 if (phone != null) {
2228 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2229 } else {
2230 return false;
2231 }
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
2237 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002238 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
Wink Saville36469e72014-06-11 15:17:00 -07002240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 final Phone phone = getPhone(subId);
2247 if (phone != null) {
2248 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002256 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
Wink Savilleb564aae2014-10-23 10:18:09 -07002259 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002260 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = getPhone(subId);
2265 if (phone == null) {
2266 return false;
2267 }
2268 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2269 toggleRadioOnOffForSubscriber(subId);
2270 }
2271 return true;
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
Wink Saville36469e72014-06-11 15:17:00 -07002276
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002277 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002278 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002279 /*
2280 * If any of the Radios are available, it will need to be
2281 * shutdown. So return true if any Radio is available.
2282 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2286 Phone phone = PhoneFactory.getPhone(i);
2287 if (phone != null && phone.isRadioAvailable()) return true;
2288 }
2289 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2290 return false;
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002293 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002294 }
2295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002297 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 enforceModifyPermission();
2299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2303 logv("Shutting down Phone " + i);
2304 shutdownRadioUsingPhoneId(i);
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002308 }
2309 }
2310
2311 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002312 Phone phone = PhoneFactory.getPhone(phoneId);
2313 if (phone != null && phone.isRadioAvailable()) {
2314 phone.shutdownRadio();
2315 }
2316 }
2317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320
2321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2324 if (defaultPhone != null) {
2325 defaultPhone.setRadioPower(turnOn);
2326 return true;
2327 } else {
2328 loge("There's no default phone.");
2329 return false;
2330 }
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002333 }
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 final Phone phone = getPhone(subId);
2342 if (phone != null) {
2343 phone.setRadioPower(turnOn);
2344 return true;
2345 } else {
2346 return false;
2347 }
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
Wink Saville36469e72014-06-11 15:17:00 -07002353 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public boolean enableDataConnectivity() {
2356 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 int subId = mSubscriptionController.getDefaultDataSubId();
2361 final Phone phone = getPhone(subId);
2362 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002363 phone.getDataEnabledSettings().setDataEnabled(
2364 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365 return true;
2366 } else {
2367 return false;
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Wink Saville36469e72014-06-11 15:17:00 -07002374 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002375 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 public boolean disableDataConnectivity() {
2377 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 int subId = mSubscriptionController.getDefaultDataSubId();
2382 final Phone phone = getPhone(subId);
2383 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002384 phone.getDataEnabledSettings().setDataEnabled(
2385 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 return true;
2387 } else {
2388 return false;
2389 }
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 }
2394
Sanket Padawe356d7632015-06-22 14:03:32 -07002395 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002396 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002401 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402 } else {
2403 return false;
2404 }
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
2410 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002412 }
2413
pkanwarae03a6b2016-11-06 20:37:09 -08002414 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 enforceCallPermission();
2416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2420 return;
2421 }
2422 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2423 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
pkanwar32d516d2016-10-14 19:37:38 -07002427 };
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2435 return false;
2436 }
2437 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002444 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002445 }
2446
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002447 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 Phone phone = PhoneFactory.getPhone(slotIndex);
2451 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2452 PhoneConstantConversions.convertCallState(phone.getState());
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
2455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002459 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002460 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2461 }
2462
2463 @Override
2464 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 if (phone != null) {
2469 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2470 } else {
2471 return PhoneConstantConversions.convertDataState(
2472 PhoneConstants.DataState.DISCONNECTED);
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002480 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002481 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2482 }
2483
2484 @Override
2485 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002488 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 if (phone != null) {
2490 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2491 } else {
2492 return TelephonyManager.DATA_ACTIVITY_NONE;
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002500 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002501 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002502 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002503
2504 LocationAccessPolicy.LocationPermissionResult locationResult =
2505 LocationAccessPolicy.checkLocationPermission(mApp,
2506 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2507 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002508 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002509 .setCallingPid(Binder.getCallingPid())
2510 .setCallingUid(Binder.getCallingUid())
2511 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002512 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002513 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2514 .build());
2515 switch (locationResult) {
2516 case DENIED_HARD:
2517 throw new SecurityException("Not allowed to access cell location");
2518 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002519 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2520 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002527 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002528 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Svetoslav64fad262015-04-14 14:35:21 -07002532 }
2533
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 @Override
Jack Yu01425032020-02-22 19:38:58 -08002535 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002536 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2537 // registered cell info, so return a NULL country instead.
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002540 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2541 // Get default phone in this case.
2542 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2543 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002544 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002546 if (phone == null) return "";
2547 ServiceStateTracker sst = phone.getServiceStateTracker();
2548 if (sst == null) return "";
2549 LocaleTracker lt = sst.getLocaleTracker();
2550 if (lt == null) return "";
2551 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2552 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2553 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002554 } finally {
2555 Binder.restoreCallingIdentity(identity);
2556 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002557 }
2558
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002559 /**
2560 * This method was removed due to potential issues caused by performing partial
2561 * updates of service state, and lack of a credible use case.
2562 *
2563 * This has the ability to break the telephony implementation by disabling notification of
2564 * changes in device connectivity. DO NOT USE THIS!
2565 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002566 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 public void enableLocationUpdates() {
2568 mApp.enforceCallingOrSelfPermission(
2569 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 @Override
2580 public void disableLocationUpdates() {
2581 mApp.enforceCallingOrSelfPermission(
2582 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
Nathan Harold31d7ff32018-10-15 20:20:30 -07002585 /**
2586 * Returns the target SDK version number for a given package name.
2587 *
Nathan Haroldec184742019-07-10 17:04:16 -07002588 * This call MUST be invoked before clearing the calling UID.
2589 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002590 * @return target SDK if the package is found or INT_MAX.
2591 */
2592 private int getTargetSdk(String packageName) {
2593 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002594 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002595 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002596 if (ai != null) return ai.targetSdkVersion;
2597 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002598 loge("Failed to get package info for pkg="
2599 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002600 }
2601 return Integer.MAX_VALUE;
2602 }
2603
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 @Override
2605 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002606 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2607 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002608 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002609 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2610 throw new SecurityException(
2611 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2612 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002613
Jordan Liu1617b712019-07-10 15:06:26 -07002614 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2616 return null;
2617 }
Svetoslav64fad262015-04-14 14:35:21 -07002618
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002619 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002621 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002622 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623
Nathan Haroldf180aac2018-06-01 18:43:55 -07002624 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2625 for (CellInfo ci : info) {
2626 if (ci instanceof CellInfoGsm) {
2627 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2628 } else if (ci instanceof CellInfoWcdma) {
2629 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002632 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002635 private List<CellInfo> getCachedCellInfo() {
2636 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2637 for (Phone phone : PhoneFactory.getPhones()) {
2638 List<CellInfo> info = phone.getAllCellInfo();
2639 if (info != null) cellInfos.addAll(info);
2640 }
2641 return cellInfos;
2642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643
2644 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002645 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002646 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002647 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002648
2649 LocationAccessPolicy.LocationPermissionResult locationResult =
2650 LocationAccessPolicy.checkLocationPermission(mApp,
2651 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2652 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002653 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002654 .setCallingPid(Binder.getCallingPid())
2655 .setCallingUid(Binder.getCallingUid())
2656 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002657 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002658 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2659 .build());
2660 switch (locationResult) {
2661 case DENIED_HARD:
2662 throw new SecurityException("Not allowed to access cell info");
2663 case DENIED_SOFT:
2664 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002667 final int targetSdk = getTargetSdk(callingPackage);
2668 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2669 return getCachedCellInfo();
2670 }
2671
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002672 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002673 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2677 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002678 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002679 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 if (info != null) cellInfos.addAll(info);
2681 }
2682 return cellInfos;
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686 }
2687
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002688 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002689 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2690 String callingFeatureId) {
2691 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2692 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002693 }
2694
2695 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002696 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2697 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002698 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002699 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002700 }
2701
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002702 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2703 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002704 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002705 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002706
2707 LocationAccessPolicy.LocationPermissionResult locationResult =
2708 LocationAccessPolicy.checkLocationPermission(mApp,
2709 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2710 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002711 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002712 .setCallingPid(Binder.getCallingPid())
2713 .setCallingUid(Binder.getCallingUid())
2714 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002715 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2716 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002717 .build());
2718 switch (locationResult) {
2719 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002720 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2721 // Safetynet logging for b/154934934
2722 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2723 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002724 throw new SecurityException("Not allowed to access cell info");
2725 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002726 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2727 // Safetynet logging for b/154934934
2728 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2729 }
Nathan Harold5320c422019-05-09 10:26:08 -07002730 try {
2731 cb.onCellInfo(new ArrayList<CellInfo>());
2732 } catch (RemoteException re) {
2733 // Drop without consequences
2734 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002735 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002736 }
2737
Nathan Harolda939a962019-05-09 10:13:47 -07002738
2739 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002740 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2741
2742 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2743 }
2744
2745 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002747 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002748 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
Shishir Agrawala9f32182016-04-12 12:00:16 -07002758 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002759 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002760 Phone phone = PhoneFactory.getPhone(slotIndex);
2761 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 return null;
2763 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002764 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002765 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002766 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002767 return null;
2768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 return phone.getImei();
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002776 }
2777
2778 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002779 public String getTypeAllocationCodeForSlot(int slotIndex) {
2780 Phone phone = PhoneFactory.getPhone(slotIndex);
2781 String tac = null;
2782 if (phone != null) {
2783 String imei = phone.getImei();
2784 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2785 }
2786 return tac;
2787 }
2788
2789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002790 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002791 Phone phone = PhoneFactory.getPhone(slotIndex);
2792 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002793 return null;
2794 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795
Jeff Davidson913390f2018-02-23 17:11:49 -08002796 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002797 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002798 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002799 return null;
2800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 return phone.getMeid();
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
Jack Yu2af8d712017-03-15 17:14:14 -07002808 }
2809
2810 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002811 public String getManufacturerCodeForSlot(int slotIndex) {
2812 Phone phone = PhoneFactory.getPhone(slotIndex);
2813 String manufacturerCode = null;
2814 if (phone != null) {
2815 String meid = phone.getMeid();
2816 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2817 }
2818 return manufacturerCode;
2819 }
2820
2821 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002822 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2823 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002824 Phone phone = PhoneFactory.getPhone(slotIndex);
2825 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002826 return null;
2827 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002828 int subId = phone.getSubId();
2829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002830 mApp, subId, callingPackage, callingFeatureId,
2831 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002832 return null;
2833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 return phone.getDeviceSvn();
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
2840 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002841 }
2842
fionaxu43304da2017-11-27 22:51:16 -08002843 @Override
2844 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 final Phone phone = getPhone(subId);
2848 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
fionaxu43304da2017-11-27 22:51:16 -08002852 }
2853
2854 @Override
2855 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 final Phone phone = getPhone(subId);
2859 return phone == null ? null : phone.getCarrierName();
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
fionaxu43304da2017-11-27 22:51:16 -08002863 }
2864
calvinpanffe225e2018-11-01 19:43:06 +08002865 @Override
chen xu0026ca62019-03-06 15:28:50 -08002866 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 final Phone phone = getPhone(subId);
2870 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002871 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
2875 }
2876
2877 @Override
chen xu0026ca62019-03-06 15:28:50 -08002878 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002882 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
chen xu651eec72018-11-11 19:03:44 -08002888 @Override
chen xu864e11c2018-12-06 22:10:03 -08002889 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2890 if (!isSubscriptionMccMnc) {
2891 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2892 }
chen xu651eec72018-11-11 19:03:44 -08002893 final Phone phone = PhoneFactory.getPhone(slotIndex);
2894 if (phone == null) {
2895 return TelephonyManager.UNKNOWN_CARRIER_ID;
2896 }
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
2903 }
2904
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 //
2906 // Internal helper methods.
2907 //
2908
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002909 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2911 *
2912 * @throws SecurityException if the caller does not have the required permission
2913 */
2914 private void enforceModifyPermission() {
2915 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2916 }
2917
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002918 /**
2919 * Make sure the caller is system.
2920 *
2921 * @throws SecurityException if the caller is not system.
2922 */
2923 private void enforceSystemCaller() {
2924 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2925 throw new SecurityException("Caller must be system");
2926 }
2927 }
2928
Shuo Qianf2b2df42019-11-13 17:43:31 -08002929 private void enforceActiveEmergencySessionPermission() {
2930 mApp.enforceCallingOrSelfPermission(
2931 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2932 }
2933
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 /**
2935 * Make sure the caller has the CALL_PHONE permission.
2936 *
2937 * @throws SecurityException if the caller does not have the required permission
2938 */
2939 private void enforceCallPermission() {
2940 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2941 }
2942
paulhu423b5f22019-08-23 19:17:33 +08002943 private void enforceSettingsPermission() {
2944 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002945 }
2946
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 private String createTelUrl(String number) {
2948 if (TextUtils.isEmpty(number)) {
2949 return null;
2950 }
2951
Jake Hambye994d462014-02-03 13:10:13 -08002952 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
Ihab Awadf9e92732013-12-05 18:02:52 -08002955 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2957 }
2958
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002959 private static void logv(String msg) {
2960 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2961 }
2962
Ihab Awadf9e92732013-12-05 18:02:52 -08002963 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2965 }
2966
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002967 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002969 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002970 }
2971
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002973 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone phone = PhoneFactory.getPhone(slotIndex);
2977 if (phone == null) {
2978 return PhoneConstants.PHONE_TYPE_NONE;
2979 } else {
2980 return phone.getPhoneType();
2981 }
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 }
2986
2987 /**
2988 * Returns the CDMA ERI icon index to display
2989 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2992 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2993 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002994 }
2995
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003000 mApp, subId, callingPackage, callingFeatureId,
3001 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 return -1;
3003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
3005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 final Phone phone = getPhone(subId);
3008 if (phone != null) {
3009 return phone.getCdmaEriIconIndex();
3010 } else {
3011 return -1;
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
3018 /**
3019 * Returns the CDMA ERI icon mode,
3020 * 0 - ON
3021 * 1 - FLASHING
3022 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003023 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003024 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3025 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3026 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003027 }
3028
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003030 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3031 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003033 mApp, subId, callingPackage, callingFeatureId,
3034 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003035 return -1;
3036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 final Phone phone = getPhone(subId);
3041 if (phone != null) {
3042 return phone.getCdmaEriIconMode();
3043 } else {
3044 return -1;
3045 }
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 }
3050
3051 /**
3052 * Returns the CDMA ERI text,
3053 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003054 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003055 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3056 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3057 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003058 }
3059
Sanket Padawe356d7632015-06-22 14:03:32 -07003060 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3062 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003064 mApp, subId, callingPackage, callingFeatureId,
3065 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003066 return null;
3067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
3072 if (phone != null) {
3073 return phone.getCdmaEriText();
3074 } else {
3075 return null;
3076 }
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 }
3081
3082 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003083 * Returns the CDMA MDN.
3084 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003085 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003086 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003093 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 return phone.getLine1Number();
3095 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003096 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 return null;
3098 }
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003101 }
3102 }
3103
3104 /**
3105 * Returns the CDMA MIN.
3106 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003108 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3110 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 final Phone phone = getPhone(subId);
3115 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3116 return phone.getCdmaMin();
3117 } else {
3118 return null;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003122 }
3123 }
3124
Hall Liud892bec2018-11-30 14:51:45 -08003125 @Override
3126 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3127 INumberVerificationCallback callback, String callingPackage) {
3128 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3129 != PERMISSION_GRANTED) {
3130 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3131 }
3132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3133
3134 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3135 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3136 throw new SecurityException("Calling package must be configured in the device config");
3137 }
3138
3139 if (range == null) {
3140 throw new NullPointerException("Range must be non-null");
3141 }
3142
3143 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003144 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003145
3146 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3147 }
3148
Junda Liuca05d5d2014-08-14 22:36:34 -07003149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 * Returns true if CDMA provisioning needs to run.
3151 */
3152 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 final long identity = Binder.clearCallingIdentity();
3154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003155 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
3161 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003162 * Sets the voice mail number of a given subId.
3163 */
3164 @Override
3165 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003166 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3167 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3172 new Pair<String, String>(alphaTag, number), new Integer(subId));
3173 return success;
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003177 }
3178
Ta-wei Yen87c49842016-05-13 21:19:52 -07003179 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003180 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003182 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3183 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003184 if (!TextUtils.equals(callingPackage, systemDialer)) {
3185 throw new SecurityException("caller must be system dialer");
3186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3191 if (phoneAccountHandle == null) {
3192 return null;
3193 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003197 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003198 }
3199
3200 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003201 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3202 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003203 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003205 mApp, subId, callingPackage, callingFeatureId,
3206 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003207 return null;
3208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003210 final long identity = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003216 }
3217
3218 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003219 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3220 VisualVoicemailSmsFilterSettings settings) {
3221 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222
3223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003226 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003230 }
3231
3232 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003233 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 mApp, callingPackage, subId);
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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3247 String callingPackage, int subId) {
3248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003257 }
3258
3259 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003260 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003270 }
3271
3272 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003273 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3274 String callingAttributionTag, int subId, String number, int port, String text,
3275 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003277 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003278 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003279 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003280 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3281 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003282 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003283
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003284 /**
fionaxu0152e512016-11-14 13:36:14 -08003285 * Sets the voice activation state of a given subId.
3286 */
3287 @Override
3288 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3290 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 if (phone != null) {
3296 phone.setVoiceActivationState(activationState);
3297 } else {
3298 loge("setVoiceActivationState fails with invalid subId: " + subId);
3299 }
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003302 }
3303 }
3304
3305 /**
3306 * Sets the data activation state of a given subId.
3307 */
3308 @Override
3309 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3311 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 final Phone phone = getPhone(subId);
3316 if (phone != null) {
3317 phone.setDataActivationState(activationState);
3318 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003319 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320 }
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003323 }
3324 }
3325
3326 /**
3327 * Returns the voice activation state of a given subId.
3328 */
3329 @Override
3330 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
fionaxu0152e512016-11-14 13:36:14 -08003333 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (phone != null) {
3337 return phone.getVoiceActivationState();
3338 } else {
3339 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003343 }
3344 }
3345
3346 /**
3347 * Returns the data activation state of a given subId.
3348 */
3349 @Override
3350 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352
fionaxu0152e512016-11-14 13:36:14 -08003353 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 if (phone != null) {
3357 return phone.getDataActivationState();
3358 } else {
3359 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003363 }
3364 }
3365
3366 /**
Wink Saville36469e72014-06-11 15:17:00 -07003367 * Returns the unread count of voicemails for a subId
3368 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003369 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003370 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3371 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003373 mApp, subId, callingPackage, callingFeatureId,
3374 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003375 return 0;
3376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 final Phone phone = getPhone(subId);
3380 if (phone != null) {
3381 return phone.getVoiceMessageCount();
3382 } else {
3383 return 0;
3384 }
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 }
3389
3390 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003391 * returns true, if the device is in a state where both voice and data
3392 * are supported simultaneously. This can change based on location or network condition.
3393 */
3394 @Override
3395 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 final Phone phone = getPhone(subId);
3399 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003403 }
3404
3405 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003406 * Send the dialer code if called from the current default dialer or the caller has
3407 * carrier privilege.
3408 * @param inputCode The dialer code to send
3409 */
3410 @Override
3411 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003414 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3415 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003416 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003417 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
fionaxu235cc5e2017-03-06 22:25:57 -08003427 }
3428
Pengquan Menga1bb6272018-09-06 09:59:22 -07003429 @Override
3430 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003431 TelephonyPermissions
3432 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3433 mApp, subId, "getNetworkSelectionMode");
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 if (!isActiveSubscription(subId)) {
3437 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3438 }
3439 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003442 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003443 }
3444
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003446 public boolean isInEmergencySmsMode() {
3447 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 for (Phone phone : PhoneFactory.getPhones()) {
3451 if (phone.isInEmergencySmsMode()) {
3452 return true;
3453 }
3454 }
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
3458 return false;
3459 }
3460
shilu366312e2019-12-17 09:28:10 -08003461 /**
3462 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3463 * @param subId The subscription to use to check the configuration.
3464 * @param c The callback that will be used to send the result.
3465 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003466 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003467 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3468 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003469 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3470 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003471
Brad Ebinger77b832e2019-10-17 17:03:22 -07003472 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3473 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3474 "IMS not available on device.");
3475 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 final long token = Binder.clearCallingIdentity();
3477 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003479 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003481 } catch (ImsException e) {
3482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003483 } finally {
3484 Binder.restoreCallingIdentity(token);
3485 }
3486 }
3487
shilu366312e2019-12-17 09:28:10 -08003488 /**
3489 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3490 * @param subId The subscription to use to check the configuration.
3491 * @param c The callback that will be used to send the result.
3492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003494 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003495 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3496 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3498 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3499 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003500 final long token = Binder.clearCallingIdentity();
3501 try {
3502 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3503 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3504 .removeRegistrationCallbackForSubscription(c, subId);
3505 } catch (ImsException e) {
3506 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3507 + "is inactive, ignoring unregister.");
3508 // If the subscription is no longer active, just return, since the callback
3509 // will already have been removed internally.
3510 } finally {
3511 Binder.restoreCallingIdentity(token);
3512 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 }
3514
Brad Ebinger774ba362019-10-22 17:36:18 -07003515 /**
3516 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3517 */
3518 @Override
3519 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3520 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3521 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3523 "IMS not available on device.");
3524 }
3525 final long token = Binder.clearCallingIdentity();
3526 try {
3527 Phone phone = getPhone(subId);
3528 if (phone == null) {
3529 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3530 + subId + "'");
3531 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3532 }
3533 phone.getImsRegistrationState(regState -> {
3534 try {
3535 consumer.accept((regState == null)
3536 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3537 } catch (RemoteException e) {
3538 // Ignore if the remote process is no longer available to call back.
3539 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3540 }
3541 });
3542 } finally {
3543 Binder.restoreCallingIdentity(token);
3544 }
3545 }
3546
3547 /**
3548 * Get the transport type for the IMS service registration state.
3549 */
3550 @Override
3551 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003552 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3553 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003554 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3556 "IMS not available on device.");
3557 }
3558 final long token = Binder.clearCallingIdentity();
3559 try {
3560 Phone phone = getPhone(subId);
3561 if (phone == null) {
3562 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3563 + subId + "'");
3564 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3565 }
3566 phone.getImsRegistrationTech(regTech -> {
3567 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3568 int regTechConverted = (regTech == null)
3569 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3570 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3571 regTechConverted);
3572 try {
3573 consumer.accept(regTechConverted);
3574 } catch (RemoteException e) {
3575 // Ignore if the remote process is no longer available to call back.
3576 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3577 }
3578 });
3579 } finally {
3580 Binder.restoreCallingIdentity(token);
3581 }
3582 }
3583
shilu366312e2019-12-17 09:28:10 -08003584 /**
3585 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3586 * @param subId The subscription to use to check the configuration.
3587 * @param c The callback that will be used to send the result.
3588 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003590 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3591 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003592 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3593 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003594 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3595 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3596 "IMS not available on device.");
3597 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3599 final long token = Binder.clearCallingIdentity();
3600 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(token);
3607 }
3608 }
3609
shilu366312e2019-12-17 09:28:10 -08003610 /**
3611 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3612 * @param subId The subscription to use to check the configuration.
3613 * @param c The callback that will be used to send the result.
3614 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003616 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003617 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3618 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3620 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3621 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003622
3623 final long token = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3626 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003627 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003628 } catch (ImsException e) {
3629 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3630 + "is inactive, ignoring unregister.");
3631 // If the subscription is no longer active, just return, since the callback
3632 // will already have been removed internally.
3633 } finally {
3634 Binder.restoreCallingIdentity(token);
3635 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 }
3637
3638 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003639 public boolean isCapable(int subId, int capability, int regTech) {
3640 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3642 final long token = Binder.clearCallingIdentity();
3643 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003644 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003646 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3648 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003649 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003650 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3651 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 } finally {
3653 Binder.restoreCallingIdentity(token);
3654 }
3655 }
3656
3657 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003658 public boolean isAvailable(int subId, int capability, int regTech) {
3659 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 final long token = Binder.clearCallingIdentity();
3661 try {
3662 Phone phone = getPhone(subId);
3663 if (phone == null) return false;
3664 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003665 } catch (com.android.ims.ImsException e) {
3666 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3667 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 } finally {
3669 Binder.restoreCallingIdentity(token);
3670 }
3671 }
3672
Brad Ebinger77b832e2019-10-17 17:03:22 -07003673 /**
3674 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3675 * subscription.
3676 * @param subId The subscription to use to check the configuration.
3677 * @param callback The callback that will be used to send the result.
3678 * @param capability The MmTelFeature capability that will be used to send the result.
3679 * @param transportType The transport type of the MmTelFeature capability.
3680 */
3681 @Override
3682 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3683 int transportType) {
3684 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3685 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3686 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3687 "IMS not available on device.");
3688 }
3689 final long token = Binder.clearCallingIdentity();
3690 try {
3691 int slotId = getSlotIndex(subId);
3692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3693 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3694 + subId + "'");
3695 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3696 }
3697 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3698 transportType, aBoolean -> {
3699 try {
3700 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3701 } catch (RemoteException e) {
3702 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3703 + "running. Ignore");
3704 }
3705 });
3706 } finally {
3707 Binder.restoreCallingIdentity(token);
3708 }
3709 }
3710
shilu366312e2019-12-17 09:28:10 -08003711 /**
3712 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3713 * @param subId The subscription to use to check the configuration.
3714 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 @Override
3716 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003717 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3718 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003719
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3721 final long token = Binder.clearCallingIdentity();
3722 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(token);
3729 }
3730 }
3731
3732 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003733 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003735 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (ImsException e) {
3742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
3746 }
3747
shilu366312e2019-12-17 09:28:10 -08003748 /**
3749 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3750 * @param subId The subscription to use to check the configuration.
3751 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003753 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003754 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3755 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3760 } catch (ImsException e) {
3761 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
3767 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003768 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003770 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003775 } catch (ImsException e) {
3776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
shilu366312e2019-12-17 09:28:10 -08003782 /**
3783 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3784 * @param subId The subscription to use to check the configuration.
3785 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 @Override
3787 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003788 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3789 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
3796 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
3800 }
3801
3802 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003803 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003805 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003810 } catch (ImsException e) {
3811 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
3815 }
3816
shilu366312e2019-12-17 09:28:10 -08003817 /**
3818 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3819 * @param subId The subscription to use to check the configuration.
3820 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 @Override
3822 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003823 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3824 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003828 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003830 } catch (ImsException e) {
3831 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
3837 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003838 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003840 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003844 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003846 } catch (ImsException e) {
3847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
3851 }
3852
3853 @Override
3854 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3856 "setVoWiFiNonPersistent");
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003860 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003861 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003862 } catch (ImsException e) {
3863 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
shilu366312e2019-12-17 09:28:10 -08003869 /**
3870 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3871 * @param subId The subscription to use to check the configuration.
3872 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 @Override
3874 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003875 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3876 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003880 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003882 } catch (ImsException e) {
3883 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
3887 }
3888
3889 @Override
3890 public void setVoWiFiModeSetting(int subId, int mode) {
3891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3892 "setVoWiFiModeSetting");
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003896 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003898 } catch (ImsException e) {
3899 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
3903 }
3904
3905 @Override
3906 public int getVoWiFiRoamingModeSetting(int subId) {
3907 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003913 } catch (ImsException e) {
3914 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
3918 }
3919
3920 @Override
3921 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3923 "setVoWiFiRoamingModeSetting");
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003927 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003929 } catch (ImsException e) {
3930 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
3934 }
3935
3936 @Override
3937 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3939 "setRttCapabilityEnabled");
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3944 } catch (ImsException e) {
3945 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
3949 }
3950
shilu366312e2019-12-17 09:28:10 -08003951 /**
3952 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3953 * @param subId The subscription to use to check the configuration.
3954 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 @Override
3956 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003957 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3958 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003962 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003964 } catch (ImsException e) {
3965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
3969 }
3970
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003971 @Override
3972 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3973 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003976 if (!isImsAvailableOnDevice()) {
3977 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3978 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003979 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003981 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003982 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003983 } catch (ImsException e) {
3984 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
3988 }
3989
3990 @Override
3991 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3992 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3993 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003994 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3995 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3996 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003997 try {
3998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003999 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004000 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004001 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004002 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4003 + "is inactive, ignoring unregister.");
4004 // If the subscription is no longer active, just return, since the callback will already
4005 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
allenwtsu99c623b2020-01-03 18:24:23 +08004011
4012 private void checkModifyPhoneStatePermission(int subId, String message) {
4013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4014 message);
4015 }
4016
4017 private boolean isImsProvisioningRequired(int subId, int capability,
4018 boolean isMmtelCapability) {
4019 Phone phone = getPhone(subId);
4020 if (phone == null) {
4021 loge("phone instance null for subid " + subId);
4022 return false;
4023 }
4024 if (isMmtelCapability) {
4025 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4026 return false;
4027 }
4028 } else {
4029 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4030 return false;
4031 }
4032 }
4033 return true;
4034 }
4035
4036 @Override
4037 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4038 boolean isProvisioned) {
4039 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4040
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4044 if (!isImsProvisioningRequired(subId, capability, false)) {
4045 return;
4046 }
4047
4048 // this capability requires provisioning, route to the correct API.
4049 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4050 switch (capability) {
4051 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4052 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4053 ims.setEabProvisioned(isProvisioned);
4054 break;
4055 default: {
4056 throw new IllegalArgumentException("Tried to set provisioning for "
4057 + "rcs capability '" + capability + "', which does not require "
4058 + "provisioning.");
4059 }
4060 }
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064
4065 }
4066
4067
4068 @Override
4069 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4070 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4074 if (!isImsProvisioningRequired(subId, capability, false)) {
4075 return true;
4076 }
4077
4078 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4079 switch (capability) {
4080 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4081 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4082 return ims.isEabProvisionedOnDevice();
4083
4084 default: {
4085 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4086 + "capability '" + capability + "', which does not require "
4087 + "provisioning.");
4088 }
4089 }
4090
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004097 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4098 boolean isProvisioned) {
4099 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4100 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4101 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4102 }
allenwtsu99c623b2020-01-03 18:24:23 +08004103 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004107 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004108 return;
4109 }
4110
4111 // this capability requires provisioning, route to the correct API.
4112 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4113 switch (capability) {
4114 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4115 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4116 ims.setVolteProvisioned(isProvisioned);
4117 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4118 ims.setWfcProvisioned(isProvisioned);
4119 }
4120 break;
4121 }
4122 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4123 // There is currently no difference in VT provisioning type.
4124 ims.setVtProvisioned(isProvisioned);
4125 break;
4126 }
4127 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4128 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4129 // change the capability of the feature instead if needed.
4130 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4131 == isProvisioned) {
4132 // No change in provisioning.
4133 return;
4134 }
4135 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4136 try {
4137 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4140 + ", Exception" + e.getMessage());
4141 }
4142 break;
4143 }
4144 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004145 throw new IllegalArgumentException("Tried to set provisioning for "
4146 + "MmTel capability '" + capability + "', which does not require "
4147 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004148 }
4149 }
4150
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
4154 }
4155
4156 @Override
4157 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4158 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4159 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4160 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4161 }
4162 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004166 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 return true;
4168 }
4169
4170 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4171 switch (capability) {
4172 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4173 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4174 return ims.isVolteProvisionedOnDevice();
4175 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4176 return ims.isWfcProvisionedOnDevice();
4177 }
4178 // This should never happen, since we are checking tech above to make sure it
4179 // is either LTE or IWLAN.
4180 throw new IllegalArgumentException("Invalid radio technology for voice "
4181 + "capability.");
4182 }
4183 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4184 // There is currently no difference in VT provisioning type.
4185 return ims.isVtProvisionedOnDevice();
4186 }
4187 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4188 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4189 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4190 }
4191 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004192 throw new IllegalArgumentException(
4193 "Tried to get provisioning for MmTel capability '" + capability
4194 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004195 }
4196 }
4197
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
4201 }
4202
4203 @Override
4204 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4205 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4206 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4207 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4208 }
4209 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4210 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4211 return (provisionedBits & capability) > 0;
4212 }
4213
4214 @Override
4215 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4216 boolean isProvisioned) {
4217 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4218 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4219 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4220 }
4221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4222 "setProvisioningStatusForCapability");
4223 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4224 // If the current provisioning status for capability already matches isProvisioned,
4225 // do nothing.
4226 if (((provisionedBits & capability) > 0) == isProvisioned) {
4227 return;
4228 }
4229 if (isProvisioned) {
4230 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4231 } else {
4232 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4233 }
4234 }
4235
4236 /**
4237 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4238 * technology. The bitfield should mirror the bitfield defined by
4239 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4240 */
4241 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4242 String key = getMmTelProvisioningKey(subId, tech);
4243 // Default is no capabilities are provisioned.
4244 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4245 }
4246
4247 /**
4248 * Sets the MmTel capability provisioning bitfield (defined by
4249 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4250 * technology specified.
4251 *
4252 * Note: This is a synchronous command and should not be called on UI thread.
4253 */
4254 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4255 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4256 String key = getMmTelProvisioningKey(subId, tech);
4257 editor.putInt(key, newField);
4258 editor.commit();
4259 }
4260
4261 private static String getMmTelProvisioningKey(int subId, int tech) {
4262 // resulting key is provision_ims_mmtel_{subId}_{tech}
4263 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4264 }
4265
4266 /**
4267 * Query CarrierConfig to see if the specified capability requires provisioning for the
4268 * carrier associated with the subscription id.
4269 */
4270 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4271 int capability) {
4272 CarrierConfigManager configManager = new CarrierConfigManager(context);
4273 PersistableBundle c = configManager.getConfigForSubId(subId);
4274 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004275 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004276 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4277 false);
4278 boolean requireVoiceVtProvisioning = c.getBoolean(
4279 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4280
4281 // First check to make sure that the capability requires provisioning.
4282 switch (capability) {
4283 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4284 // intentional fallthrough
4285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4286 if (requireVoiceVtProvisioning) {
4287 // Voice and Video requires provisioning
4288 return true;
4289 }
4290 break;
4291 }
4292 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4293 if (requireUtProvisioning) {
4294 // UT requires provisioning
4295 return true;
4296 }
4297 break;
4298 }
4299 }
4300 return false;
4301 }
4302
allenwtsu99c623b2020-01-03 18:24:23 +08004303 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4304 int capability) {
4305 CarrierConfigManager configManager = new CarrierConfigManager(context);
4306 PersistableBundle c = configManager.getConfigForSubId(subId);
4307
4308 boolean requireRcsProvisioning = c.getBoolean(
4309 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4310
4311 // First check to make sure that the capability requires provisioning.
4312 switch (capability) {
4313 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4314 // intentional fallthrough
4315 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4316 if (requireRcsProvisioning) {
4317 // OPTION or PRESENCE requires provisioning
4318 return true;
4319 }
4320 break;
4321 }
4322 }
4323 return false;
4324 }
4325
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004326 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004327 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004328 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4329 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4330 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004331 enforceReadPrivilegedPermission("getImsProvisioningInt");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 int slotId = getSlotIndex(subId);
4336 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4337 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4338 + subId + "' for key:" + key);
4339 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4340 }
4341 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004342 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004343 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4344 + subId + "' for key:" + key);
4345 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
4352 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4354 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4355 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004356 enforceReadPrivilegedPermission("getImsProvisioningString");
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004360 int slotId = getSlotIndex(subId);
4361 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4362 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4363 + subId + "' for key:" + key);
4364 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4365 }
4366 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004368 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4369 + subId + "' for key:" + key);
4370 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
4376 @Override
4377 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004378 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4379 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4380 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4382 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004386 int slotId = getSlotIndex(subId);
4387 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4388 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4389 + subId + "' for key:" + key);
4390 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4391 }
4392 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004394 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4395 + "' for key:" + key);
4396 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 @Override
4403 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004404 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4405 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4406 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4408 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004412 int slotId = getSlotIndex(subId);
4413 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4414 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4415 + subId + "' for key:" + key);
4416 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4417 }
4418 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004419 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004420 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4421 + "' for key:" + key);
4422 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
4426 }
4427
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 int slotId = SubscriptionManager.getSlotIndex(subId);
4430 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004431 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4432 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 }
4434 return slotId;
4435 }
4436
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 private int getSlotIndex(int subId) {
4438 int slotId = SubscriptionManager.getSlotIndex(subId);
4439 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4440 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4441 }
4442 return slotId;
4443 }
4444
Wink Saville36469e72014-06-11 15:17:00 -07004445 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004446 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004447 */
4448 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004449 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4450 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004451 final int targetSdk = getTargetSdk(callingPackage);
4452 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004453 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004454 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004455 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004456 mApp, subId, callingPackage, callingFeatureId,
4457 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004458 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4459 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 final Phone phone = getPhone(subId);
4464 if (phone != null) {
4465 return phone.getServiceState().getDataNetworkType();
4466 } else {
4467 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4468 }
4469 } finally {
4470 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004472 }
4473
4474 /**
4475 * Returns the data network type
4476 */
4477 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004478 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4479 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4480 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004481 }
4482
4483 /**
4484 * Returns the data network type for a subId
4485 */
4486 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004487 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4488 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004490 mApp, subId, callingPackage, callingFeatureId,
4491 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004492 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4493 }
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 final Phone phone = getPhone(subId);
4498 if (phone != null) {
4499 return phone.getServiceState().getDataNetworkType();
4500 } else {
4501 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4502 }
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004506 }
4507
4508 /**
Wink Saville36469e72014-06-11 15:17:00 -07004509 * Returns the Voice network type for a subId
4510 */
4511 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004512 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004515 mApp, subId, callingPackage, callingFeatureId,
4516 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004517 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4518 }
4519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 final Phone phone = getPhone(subId);
4523 if (phone != null) {
4524 return phone.getServiceState().getVoiceNetworkType();
4525 } else {
4526 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4527 }
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004531 }
4532
4533 /**
4534 * @return true if a ICC card is present
4535 */
4536 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004537 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004538 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4539 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004540 }
4541
4542 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004543 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004544 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004545 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004546 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 final long identity = Binder.clearCallingIdentity();
4548 try {
4549 final Phone phone = PhoneFactory.getPhone(slotIndex);
4550 if (phone != null) {
4551 return phone.getIccCard().hasIccCard();
4552 } else {
4553 return false;
4554 }
4555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004558 }
4559
4560 /**
4561 * Return if the current radio is LTE on CDMA. This
4562 * is a tri-state return value as for a period of time
4563 * the mode may be unknown.
4564 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004565 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004566 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004567 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004569 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004570 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4571 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004573 }
4574
Sanket Padawe356d7632015-06-22 14:03:32 -07004575 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004576 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4577 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004578 try {
4579 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4580 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004581 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4582 }
4583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 final Phone phone = getPhone(subId);
4587 if (phone == null) {
4588 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4589 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004590 return TelephonyProperties.lte_on_cdma_device()
4591 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 }
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004595 }
Wink Saville36469e72014-06-11 15:17:00 -07004596 }
4597
Wink Saville36469e72014-06-11 15:17:00 -07004598 /**
4599 * {@hide}
4600 * Returns Default subId, 0 in the case of single standby.
4601 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004602 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004603 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004604 }
4605
Shishir Agrawala9f32182016-04-12 12:00:16 -07004606 private int getSlotForDefaultSubscription() {
4607 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4608 }
4609
Wink Savilleb564aae2014-10-23 10:18:09 -07004610 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004611 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004612 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004613
Pengquan Menge92a50d2018-09-21 15:54:48 -07004614 private boolean isActiveSubscription(int subId) {
4615 return mSubscriptionController.isActiveSubId(subId);
4616 }
4617
Ihab Awadf2177b72013-11-25 13:33:23 -08004618 /**
4619 * @see android.telephony.TelephonyManager.WifiCallingChoices
4620 */
4621 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
4623 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004624 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4626 getWhenToMakeWifiCallsDefaultPreference());
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004630 }
4631
4632 /**
4633 * @see android.telephony.TelephonyManager.WifiCallingChoices
4634 */
4635 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004639 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004644 }
4645
Sailesh Nepald1e68152013-12-12 19:08:02 -08004646 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004647 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004648 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004649 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004650
Jordan Liu4c733742019-02-28 12:03:40 -08004651 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4652 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4653 if (phoneId == -1) {
4654 throw new IllegalArgumentException("Given slot index: " + slotIndex
4655 + " does not correspond to an active phone");
4656 }
4657 return PhoneFactory.getPhone(phoneId);
4658 }
4659
Shishir Agrawal566b7612013-10-28 14:41:00 -07004660 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004661 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4662 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4664 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004666 if (DBG) {
4667 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4668 }
4669 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4670 p2);
4671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004672
Jordan Liu4c733742019-02-28 12:03:40 -08004673
4674 @Override
4675 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4676 int slotIndex, String callingPackage, String aid, int p2) {
4677 enforceModifyPermission();
4678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4679 if (DBG) {
4680 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4681 }
4682 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4683 callingPackage, aid, p2);
4684 }
4685
4686 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4687 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 if (TextUtils.equals(ISDR_AID, aid)) {
4691 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004692 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4693 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 if (bestComponent == null
4695 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4696 loge("The calling package is not allowed to access ISD-R.");
4697 throw new SecurityException(
4698 "The calling package is not allowed to access ISD-R.");
4699 }
Derek Tan740e1672017-06-27 14:56:27 -07004700 }
Derek Tan740e1672017-06-27 14:56:27 -07004701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004703 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4704 null /* workSource */);
4705 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 return response;
4707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004710 }
4711
4712 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004713 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4715 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004716 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4717 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004719
Jordan Liu4c733742019-02-28 12:03:40 -08004720 @Override
4721 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4722 enforceModifyPermission();
4723 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4724 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4725 channel);
4726 }
4727
4728 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 if (channel < 0) {
4732 return false;
4733 }
Jordan Liu4c733742019-02-28 12:03:40 -08004734 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4735 null /* workSource */);
4736 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 return success;
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004740 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004741 }
4742
4743 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004744 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004745 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004748 if (DBG) {
4749 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4750 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4751 + p3 + " data=" + data);
4752 }
4753 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4754 command, p1, p2, p3, data);
4755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004756
Jordan Liu4c733742019-02-28 12:03:40 -08004757 @Override
4758 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4759 int command, int p1, int p2, int p3, String data) {
4760 enforceModifyPermission();
4761 if (DBG) {
4762 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4763 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4764 + p3 + " data=" + data);
4765 }
4766 return iccTransmitApduLogicalChannelWithPermission(
4767 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4768 data);
4769 }
4770
4771 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4772 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004775 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 return "";
4777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004780 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4781 null /* workSource */);
4782 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 // Append the returned status code to the end of the response payload.
4785 String s = Integer.toHexString(
4786 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4787 if (response.payload != null) {
4788 s = IccUtils.bytesToHexString(response.payload) + s;
4789 }
4790 return s;
4791 } finally {
4792 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004794 }
Jake Hambye994d462014-02-03 13:10:13 -08004795
Evan Charltonc66da362014-05-16 14:06:40 -07004796 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004797 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4798 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4800 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004802 if (DBG) {
4803 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4804 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4805 }
4806 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4807 cla, command, p1, p2, p3, data);
4808 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004809
Jordan Liu4c733742019-02-28 12:03:40 -08004810 @Override
4811 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4812 int command, int p1, int p2, int p3, String data) {
4813 enforceModifyPermission();
4814 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4815 if (DBG) {
4816 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4817 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4818 + " data=" + data);
4819 }
4820
4821 return iccTransmitApduBasicChannelWithPermission(
4822 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4823 p2, p3, data);
4824 }
4825
4826 // open APDU basic channel assuming the caller has sufficient permissions
4827 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4828 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4832 && TextUtils.equals(ISDR_AID, data)) {
4833 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4835 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 if (bestComponent == null
4837 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4838 loge("The calling package is not allowed to select ISD-R.");
4839 throw new SecurityException(
4840 "The calling package is not allowed to select ISD-R.");
4841 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004842 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004845 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4846 null /* workSource */);
4847 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 // Append the returned status code to the end of the response payload.
4850 String s = Integer.toHexString(
4851 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4852 if (response.payload != null) {
4853 s = IccUtils.bytesToHexString(response.payload) + s;
4854 }
4855 return s;
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004858 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004859 }
4860
4861 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004862 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004863 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4865 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 if (DBG) {
4870 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4871 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4872 }
4873
4874 IccIoResult response =
4875 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4876 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4877 subId);
4878
4879 if (DBG) {
4880 log("Exchange SIM_IO [R]" + response);
4881 }
4882
4883 byte[] result = null;
4884 int length = 2;
4885 if (response.payload != null) {
4886 length = 2 + response.payload.length;
4887 result = new byte[length];
4888 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4889 } else {
4890 result = new byte[length];
4891 }
4892
4893 result[length - 1] = (byte) response.sw2;
4894 result[length - 2] = (byte) response.sw1;
4895 return result;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004898 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004899 }
4900
Nathan Haroldb3014052017-01-25 15:57:32 -08004901 /**
4902 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4903 * on a particular subscription
4904 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004905 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4906 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004908 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004909 return null;
4910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911
4912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 if (appType != TelephonyManager.APPTYPE_USIM
4915 && appType != TelephonyManager.APPTYPE_SIM) {
4916 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4917 return null;
4918 }
4919 Object response = sendRequest(
4920 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4921 if (response instanceof String[]) {
4922 return (String[]) response;
4923 }
yincheng zhaod698b842019-09-06 17:06:54 -07004924 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004926 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004929 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004930 }
4931
yincheng zhaod698b842019-09-06 17:06:54 -07004932 /**
4933 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4934 * subscription.
4935 *
4936 * @param subId the id of the subscription.
4937 * @param appType the uicc app type, must be USIM or SIM.
4938 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4939 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004940 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004941 * @return number of fplmns that is successfully written to the SIM.
4942 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004943 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4944 String callingFeatureId) {
4945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4946 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004947 if (DBG) logv("no permissions for setForbiddenplmns");
4948 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4949 }
4950 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4951 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4952 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4953 }
4954 if (fplmns == null) {
4955 throw new IllegalArgumentException("Fplmn List provided is null");
4956 }
4957 for (String fplmn : fplmns) {
4958 if (!CellIdentity.isValidPlmn(fplmn)) {
4959 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4960 }
4961 }
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 Object response = sendRequest(
4965 CMD_SET_FORBIDDEN_PLMNS,
4966 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4967 subId);
4968 return (int) response;
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
4972 }
4973
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004975 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4977 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4982 if (response.payload == null) {
4983 return "";
4984 }
Evan Charltonc66da362014-05-16 14:06:40 -07004985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 // Append the returned status code to the end of the response payload.
4987 String s = Integer.toHexString(
4988 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4989 s = IccUtils.bytesToHexString(response.payload) + s;
4990 return s;
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Evan Charltonc66da362014-05-16 14:06:40 -07004994 }
4995
Jake Hambye994d462014-02-03 13:10:13 -08004996 /**
4997 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4998 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4999 *
5000 * @param itemID the ID of the item to read
5001 * @return the NV item as a String, or null on error.
5002 */
5003 @Override
5004 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005005 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5007 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005012 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5014 return value;
5015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
Jake Hambye994d462014-02-03 13:10:13 -08005018 }
5019
5020 /**
5021 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5022 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5023 *
5024 * @param itemID the ID of the item to read
5025 * @param itemValue the value to write, as a String
5026 * @return true on success; false on any failure
5027 */
5028 @Override
5029 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5037 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005038 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5040 return success;
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
Jake Hambye994d462014-02-03 13:10:13 -08005044 }
5045
5046 /**
5047 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5048 * Used for device configuration by some CDMA operators.
5049 *
5050 * @param preferredRoamingList byte array containing the new PRL
5051 * @return true on success; false on any failure
5052 */
5053 @Override
5054 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5056 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5061 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5062 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5063 return success;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Jake Hambye994d462014-02-03 13:10:13 -08005067 }
5068
5069 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005070 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005071 * Used for device configuration by some CDMA operators.
5072 *
chen xu6dac5ab2018-10-26 17:39:23 -07005073 * @param slotIndex - device slot.
5074 *
Jake Hambye994d462014-02-03 13:10:13 -08005075 * @return true on success; false on any failure
5076 */
5077 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005078 public boolean resetModemConfig(int slotIndex) {
5079 Phone phone = PhoneFactory.getPhone(slotIndex);
5080 if (phone != null) {
5081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5082 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083
chen xu6dac5ab2018-10-26 17:39:23 -07005084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5087 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5088 return success;
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 }
chen xu6dac5ab2018-10-26 17:39:23 -07005093 return false;
5094 }
5095
5096 /**
5097 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5098 *
5099 * @param slotIndex - device slot.
5100 *
5101 * @return true on success; false on any failure
5102 */
5103 @Override
5104 public boolean rebootModem(int slotIndex) {
5105 Phone phone = PhoneFactory.getPhone(slotIndex);
5106 if (phone != null) {
5107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5108 mApp, phone.getSubId(), "rebootModem");
5109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5113 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5114 return success;
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
5118 }
5119 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005120 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005121
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005122 public String[] getPcscfAddress(String apnType, String callingPackage,
5123 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005124 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5126 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005127 return new String[0];
5128 }
5129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005132 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
Brad Ebinger51f743a2017-01-23 13:50:20 -08005138 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005139 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5140 * {@link #disableIms(int)}.
5141 * @param slotIndex device slot.
5142 */
5143 public void resetIms(int slotIndex) {
5144 enforceModifyPermission();
5145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 if (mImsResolver == null) {
5149 // may happen if the does not support IMS.
5150 return;
5151 }
5152 mImsResolver.disableIms(slotIndex);
5153 mImsResolver.enableIms(slotIndex);
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005160 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5161 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005162 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005163 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005168 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005169 // may happen if the device does not support IMS.
5170 return;
5171 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005172 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005176 }
5177
5178 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005179 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5180 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005181 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005182 public void disableIms(int slotId) {
5183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005187 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005188 // may happen if the device does not support IMS.
5189 return;
5190 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005191 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005195 }
5196
5197 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005198 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5199 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005200 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005201 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005202 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005207 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005208 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5209 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005210 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005211 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005215 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005216 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005217 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5218 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005219 @Override
5220 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005221 enforceModifyPermission();
5222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005226 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
5230 }
5231
5232 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005233 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005234 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005235 */
5236 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005241 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005242 // may happen if the device does not support IMS.
5243 return null;
5244 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005245 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005249 }
5250
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005251 /**
5252 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005253 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005254 */
5255 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257
5258 final long identity = Binder.clearCallingIdentity();
5259 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005260 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005261 // may happen if the device does not support IMS.
5262 return null;
5263 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005264 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005268 }
5269
Brad Ebinger884c07b2018-02-15 16:17:40 -08005270 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005271 * Sets the ImsService Package Name that Telephony will bind to.
5272 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005273 * @param slotIndex the slot ID that the ImsService should bind for.
5274 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005275 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005276 * @param featureTypes An integer array of feature types associated with a packageName.
5277 * @param packageName The name of the package that the current configuration will be replaced
5278 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005279 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005280 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005281 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5282 int[] featureTypes, String packageName) {
5283 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5286 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005287 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005291 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005292 // may happen if the device does not support IMS.
5293 return false;
5294 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005295 Map<Integer, String> featureConfig = new HashMap<>();
5296 for (int featureType : featureTypes) {
5297 featureConfig.put(featureType, packageName);
5298 }
5299 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5300 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005304 }
5305
5306 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005307 * Clears any carrier ImsService overrides for the slot index specified that were previously
5308 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5309 *
5310 * This should only be used for testing.
5311 *
5312 * @param slotIndex the slot ID that the ImsService should bind for.
5313 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5314 */
5315 @Override
5316 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5317 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5318 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5319 "clearCarrierImsServiceOverride");
5320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5321 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5322 "clearCarrierImsServiceOverride");
5323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 if (mImsResolver == null) {
5327 // may happen if the device does not support IMS.
5328 return false;
5329 }
5330 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
5334 }
5335
5336 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005337 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005338 *
5339 * @param slotId The slot that the ImsService is associated with.
5340 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5341 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005342 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005343 * @return the package name of the ImsService configuration.
5344 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005345 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5346 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005347 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005348 TelephonyPermissions
5349 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5350 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5351 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 final long identity = Binder.clearCallingIdentity();
5354 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005355 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005356 // may happen if the device does not support IMS.
5357 return "";
5358 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005359 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005360 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5361 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005365 }
5366
Brad Ebinger77b832e2019-10-17 17:03:22 -07005367 /**
5368 * Get the MmTelFeature state associated with the requested subscription id.
5369 * @param subId The subscription that the MmTelFeature is associated with.
5370 * @param callback A callback with an integer containing the
5371 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5372 */
5373 @Override
5374 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5375 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5376 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5377 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5378 "IMS not available on device.");
5379 }
5380 final long token = Binder.clearCallingIdentity();
5381 try {
5382 int slotId = getSlotIndex(subId);
5383 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5384 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5385 + subId + "'");
5386 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5387 }
5388 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5389 try {
5390 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5391 } catch (RemoteException e) {
5392 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5393 + "Ignore");
5394 }
5395 });
5396 } finally {
5397 Binder.restoreCallingIdentity(token);
5398 }
5399 }
5400
Wink Saville36469e72014-06-11 15:17:00 -07005401 public void setImsRegistrationState(boolean registered) {
5402 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
5404 final long identity = Binder.clearCallingIdentity();
5405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Wink Saville36469e72014-06-11 15:17:00 -07005410 }
5411
5412 /**
Stuart Scott54788802015-03-30 13:18:01 -07005413 * Set the network selection mode to automatic.
5414 *
5415 */
5416 @Override
5417 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5419 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420
5421 final long identity = Binder.clearCallingIdentity();
5422 try {
shilufc958392020-01-20 11:36:01 -08005423 if (!isActiveSubscription(subId)) {
5424 return;
5425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5427 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
5430 }
Stuart Scott54788802015-03-30 13:18:01 -07005431 }
5432
Jack Yud10cdd42020-09-28 20:28:01 -07005433 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005434 * Ask the radio to connect to the input network and change selection mode to manual.
5435 *
5436 * @param subId the id of the subscription.
5437 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5438 * the operator to attach to.
5439 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5440 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5441 * normal network selection next time.
5442 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005443 */
5444 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005445 public boolean setNetworkSelectionModeManual(
5446 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5448 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005449
5450 if (!isActiveSubscription(subId)) {
5451 return false;
5452 }
5453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 final long identity = Binder.clearCallingIdentity();
5455 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005456 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005458 if (DBG) {
5459 log("setNetworkSelectionModeManual: subId: " + subId
5460 + " operator: " + operatorInfo);
5461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005466 }
shilu84f6e8b2019-12-19 13:58:01 -08005467 /**
5468 * Get the manual network selection
5469 *
5470 * @param subId the id of the subscription.
5471 *
5472 * @return the previously saved user selected PLMN
5473 */
5474 @Override
5475 public String getManualNetworkSelectionPlmn(int subId) {
5476 TelephonyPermissions
5477 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "getManualNetworkSelectionPlmn");
5479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (!isActiveSubscription(subId)) {
5483 return "";
5484 }
5485
5486 final Phone phone = getPhone(subId);
5487 if (phone == null) {
5488 return "";
5489 }
5490 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5491 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5492 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005497
5498 /**
5499 * Scans for available networks.
5500 */
5501 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005502 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5503 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5505 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005506 LocationAccessPolicy.LocationPermissionResult locationResult =
5507 LocationAccessPolicy.checkLocationPermission(mApp,
5508 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5509 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005510 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005511 .setCallingPid(Binder.getCallingPid())
5512 .setCallingUid(Binder.getCallingUid())
5513 .setMethod("getCellNetworkScanResults")
5514 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5515 .build());
5516 switch (locationResult) {
5517 case DENIED_HARD:
5518 throw new SecurityException("Not allowed to access scan results -- location");
5519 case DENIED_SOFT:
5520 return null;
5521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
Pengquan Menga1bb6272018-09-06 09:59:22 -07005523 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 try {
5525 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005526 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005531 }
5532
5533 /**
sqian80370722020-01-29 15:02:51 -08005534 * Get the call forwarding info, given the call forwarding reason.
5535 */
5536 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005537 public void getCallForwarding(int subId, int callForwardingReason,
5538 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005539 enforceReadPrivilegedPermission("getCallForwarding");
5540 long identity = Binder.clearCallingIdentity();
5541 try {
5542 if (DBG) {
5543 log("getCallForwarding: subId " + subId
5544 + " callForwardingReason" + callForwardingReason);
5545 }
Hall Liua1acea22020-09-18 19:04:59 -07005546
5547 Phone phone = getPhone(subId);
5548 if (phone == null) {
5549 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005550 callback.onError(
5551 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005552 } catch (RemoteException e) {
5553 // ignore
5554 }
5555 return;
5556 }
5557
5558 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5559 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5560 @Override
5561 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5562 try {
5563 callback.onCallForwardingInfoAvailable(info);
5564 } catch (RemoteException e) {
5565 // ignore
5566 }
5567 }
5568
5569 @Override
5570 public void onError(int error) {
5571 try {
5572 callback.onError(error);
5573 } catch (RemoteException e) {
5574 // ignore
5575 }
5576 }
5577 });
5578 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
5582 }
5583
5584 /**
5585 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5586 * reason, the number to forward, and the timeout before the forwarding is attempted.
5587 */
5588 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005589 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5590 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005591 enforceModifyPermission();
5592 long identity = Binder.clearCallingIdentity();
5593 try {
5594 if (DBG) {
5595 log("setCallForwarding: subId " + subId
5596 + " callForwardingInfo" + callForwardingInfo);
5597 }
Hall Liua1acea22020-09-18 19:04:59 -07005598
5599 Phone phone = getPhone(subId);
5600 if (phone == null) {
5601 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005602 callback.accept(
5603 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005604 } catch (RemoteException e) {
5605 // ignore
5606 }
5607 return;
5608 }
5609
5610 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5611 FunctionalUtils.ignoreRemoteException(callback::accept));
5612
5613 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
5617 }
5618
5619 /**
Hall Liua1acea22020-09-18 19:04:59 -07005620 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005621 */
5622 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005623 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005624 enforceReadPrivilegedPermission("getCallForwarding");
5625 long identity = Binder.clearCallingIdentity();
5626 try {
Hall Liua1acea22020-09-18 19:04:59 -07005627
5628 Phone phone = getPhone(subId);
5629 if (phone == null) {
5630 try {
5631 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5632 } catch (RemoteException e) {
5633 // ignore
5634 }
5635 return;
5636 }
5637
5638 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5639
sqian80370722020-01-29 15:02:51 -08005640 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005641 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
5645 }
5646
5647 /**
Hall Liua1acea22020-09-18 19:04:59 -07005648 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005649 */
5650 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005651 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005652 enforceModifyPermission();
5653 long identity = Binder.clearCallingIdentity();
5654 try {
Hall Liua1acea22020-09-18 19:04:59 -07005655 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5656
5657 Phone phone = getPhone(subId);
5658 if (phone == null) {
5659 try {
5660 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5661 } catch (RemoteException e) {
5662 // ignore
5663 }
5664 return;
5665 }
5666
5667 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5668 FunctionalUtils.ignoreRemoteException(callback::accept));
5669
5670 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
5674 }
5675
5676 /**
yinxub1bed742017-04-17 11:45:04 -07005677 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005678 *
yinxub1bed742017-04-17 11:45:04 -07005679 * @param subId id of the subscription
5680 * @param request contains the radio access networks with bands/channels to scan
5681 * @param messenger callback messenger for scan results or errors
5682 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005683 * @return the id of the requested scan which can be used to stop the scan.
5684 */
5685 @Override
5686 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005687 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005690 LocationAccessPolicy.LocationPermissionResult locationResult =
5691 LocationAccessPolicy.checkLocationPermission(mApp,
5692 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5693 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005694 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005695 .setCallingPid(Binder.getCallingPid())
5696 .setCallingUid(Binder.getCallingUid())
5697 .setMethod("requestNetworkScan")
5698 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5699 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005700 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005701 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5702 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005703 if (e != null) {
5704 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5705 throw e;
5706 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005707 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005708 return TelephonyScanManager.INVALID_SCAN_ID;
5709 }
5710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 }
Hall Liu912dfd32019-04-25 14:02:26 -07005712 int callingUid = Binder.getCallingUid();
5713 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005714 final long identity = Binder.clearCallingIdentity();
5715 try {
5716 return mNetworkScanRequestTracker.startNetworkScan(
5717 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005718 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
yinxu504e1392017-04-12 16:03:22 -07005722 }
5723
Hall Liub2ac8ef2019-02-28 15:56:23 -08005724 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005725 NetworkScanRequest request, int subId, String callingPackage) {
5726 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005727 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5728 boolean hasNetworkScanPermission =
5729 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5730 == PERMISSION_GRANTED;
5731
5732 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5733 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5734 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005735 }
5736
5737 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5738 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005739 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5740 return new SecurityException("Specific channels must not be"
5741 + " scanned without location access.");
5742 }
5743 }
5744 }
5745
Hall Liub2ac8ef2019-02-28 15:56:23 -08005746 return null;
5747 }
5748
yinxu504e1392017-04-12 16:03:22 -07005749 /**
5750 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005751 *
5752 * @param subId id of the subscription
5753 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005754 */
5755 @Override
5756 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5758 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
Hall Liu912dfd32019-04-25 14:02:26 -07005760 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005763 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
yinxu504e1392017-04-12 16:03:22 -07005767 }
5768
5769 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005770 * Get the calculated preferred network type.
5771 * Used for debugging incorrect network type.
5772 *
5773 * @return the preferred network type, defined in RILConstants.java.
5774 */
5775 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005776 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005777 final Phone defaultPhone = getDefaultPhone();
5778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005779 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005780 return RILConstants.PREFERRED_NETWORK_MODE;
5781 }
5782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 final long identity = Binder.clearCallingIdentity();
5784 try {
5785 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005786 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Junda Liu84d15a22014-07-02 11:21:04 -07005790 }
5791
5792 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005793 * Get the preferred network type.
5794 * Used for device configuration by some CDMA operators.
5795 *
5796 * @return the preferred network type, defined in RILConstants.java.
5797 */
5798 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005799 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005800 TelephonyPermissions
5801 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5802 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 if (DBG) log("getPreferredNetworkType");
5807 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5808 int networkType = (result != null ? result[0] : -1);
5809 if (DBG) log("getPreferredNetworkType: " + networkType);
5810 return networkType;
5811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005814 }
5815
5816 /**
5817 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005818 *
5819 * @param networkType the preferred network type, defined in RILConstants.java.
5820 * @return true on success; false on any failure.
5821 */
5822 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005823 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5825 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826
5827 final long identity = Binder.clearCallingIdentity();
5828 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005829 Settings.Global.putInt(mApp.getContentResolver(),
5830 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005831
5832 Boolean success = (Boolean) sendRequest(
5833 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5834 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5835 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 } finally {
5837 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005838 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005839 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005840
5841 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005842 * Get the allowed network types that store in the telephony provider.
5843 *
5844 * @param subId the id of the subscription.
5845 * @return allowedNetworkTypes the allowed network types.
5846 */
5847 @Override
5848 public long getAllowedNetworkTypes(int subId) {
5849 TelephonyPermissions
5850 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5851 mApp, subId, "getAllowedNetworkTypes");
5852
5853 final long identity = Binder.clearCallingIdentity();
5854 try {
5855 return SubscriptionManager.getLongSubscriptionProperty(
5856 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
5863 * Set the allowed network types.
5864 *
5865 * @param subId the id of the subscription.
5866 * @param allowedNetworkTypes the allowed network types.
5867 * @return true on success; false on any failure.
5868 */
5869 @Override
5870 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5872 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005873
calvinpan089c2a62020-03-12 14:17:55 +08005874 SubscriptionManager.setSubscriptionProperty(subId,
5875 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5876 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005877
calvinpan089c2a62020-03-12 14:17:55 +08005878 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5879 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5880 RILConstants.PREFERRED_NETWORK_MODE);
5881 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005882 }
5883
5884 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005885 * Get the allowed network types for certain reason.
5886 *
5887 * @param subId the id of the subscription.
5888 * @param reason the reason the allowed network type change is taking place
5889 * @return the allowed network types.
5890 */
5891 @Override
5892 public long getAllowedNetworkTypesForReason(int subId,
5893 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5894 TelephonyPermissions
5895 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5896 mApp, subId, "getAllowedNetworkTypesForReason");
5897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
5903 }
5904
5905 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005906 * Enable/Disable E-UTRA-NR Dual Connectivity
5907 * @param subId subscription id of the sim card
5908 * @param nrDualConnectivityState expected NR dual connectivity state
5909 * This can be passed following states
5910 * <ol>
5911 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5912 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5913 * <li>Disable NR dual connectivity and force secondary cell to be released
5914 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5915 * </ol>
5916 * @return operation result.
5917 */
5918 @Override
5919 public int setNrDualConnectivityState(int subId,
5920 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "enableNRDualConnectivity");
5923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5927 nrDualConnectivityState, subId,
5928 workSource);
5929 if (DBG) log("enableNRDualConnectivity result: " + result);
5930 return result;
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
5934 }
5935
5936 /**
5937 * Is E-UTRA-NR Dual Connectivity enabled
5938 * @return true if dual connectivity is enabled else false
5939 */
5940 @Override
5941 public boolean isNrDualConnectivityEnabled(int subId) {
5942 TelephonyPermissions
5943 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5944 mApp, subId, "isNRDualConnectivityEnabled");
5945 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5946 final long identity = Binder.clearCallingIdentity();
5947 try {
5948 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5949 null, subId, workSource);
5950 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5951 return isEnabled;
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
5955 }
5956
5957 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07005958 * get carrier bandwidth per primary and secondary carrier
5959 * @param subId subscription id of the sim card
5960 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
5961 */
5962 @Override
5963 public CarrierBandwidth getCarrierBandwidth(int subId) {
5964 TelephonyPermissions
5965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5966 mApp, subId, "isNRDualConnectivityEnabled");
5967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 CarrierBandwidth carrierBandwidth =
5971 getPhoneFromSubId(subId).getCarrierBandwidth();
5972 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
5973 return carrierBandwidth;
5974 } finally {
5975 Binder.restoreCallingIdentity(identity);
5976 }
5977 }
5978
5979 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005980 * Get the effective allowed network types on the device.
5981 * This API will return an intersection of allowed network types for all reasons,
5982 * including the configuration done through setAllowedNetworkTypes
5983 *
5984 * @param subId the id of the subscription.
5985 * @return the allowed network types
5986 */
5987 @Override
5988 public long getEffectiveAllowedNetworkTypes(int subId) {
5989 TelephonyPermissions
5990 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5991 mApp, subId, "getEffectiveAllowedNetworkTypes");
5992 final long identity = Binder.clearCallingIdentity();
5993 try {
5994 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
5998 }
5999
6000 /**
6001 * Set the allowed network types of the device and
6002 * provide the reason triggering the allowed network change.
6003 *
6004 * @param subId the id of the subscription.
6005 * @param reason the reason the allowed network type change is taking place
6006 * @param allowedNetworkTypes the allowed network types.
6007 * @return true on success; false on any failure.
6008 */
6009 @Override
6010 public boolean setAllowedNetworkTypesForReason(int subId,
6011 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "setAllowedNetworkTypesForReason");
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
6016 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6017 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6018 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6019 RILConstants.PREFERRED_NETWORK_MODE);
6020 return setPreferredNetworkType(subId, preferredNetworkMode);
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 }
6025
6026 /**
Miaoa84611c2019-03-15 09:21:10 +08006027 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006028 *
Miaoa84611c2019-03-15 09:21:10 +08006029 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006030 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006031 * @hide
6032 */
6033 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006034 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 try {
Miaoa84611c2019-03-15 09:21:10 +08006039 if (phone != null) {
6040 return phone.hasMatchedTetherApnSetting();
6041 } else {
6042 return false;
6043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006046 }
Junda Liu475951f2014-11-07 16:45:03 -08006047 }
6048
6049 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006050 * Enable or disable always reporting signal strength changes from radio.
6051 *
6052 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6053 */
6054 @Override
6055 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6056 enforceModifyPermission();
6057 enforceSystemCaller();
6058
6059 final long identity = Binder.clearCallingIdentity();
6060 final Phone phone = getPhone(subId);
6061 try {
6062 if (phone != null) {
6063 if (DBG) {
6064 log("setAlwaysReportSignalStrength: subId=" + subId
6065 + " isEnable=" + isEnable);
6066 }
6067 phone.setAlwaysReportSignalStrength(isEnable);
6068 } else {
6069 loge("setAlwaysReportSignalStrength: no phone found for subId="
6070 + subId);
6071 }
6072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
6075 }
6076
6077 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006078 * Get the user enabled state of Mobile Data.
6079 *
6080 * TODO: remove and use isUserDataEnabled.
6081 * This can't be removed now because some vendor codes
6082 * calls through ITelephony directly while they should
6083 * use TelephonyManager.
6084 *
6085 * @return true on enabled
6086 */
6087 @Override
6088 public boolean getDataEnabled(int subId) {
6089 return isUserDataEnabled(subId);
6090 }
6091
6092 /**
6093 * Get whether mobile data is enabled per user setting.
6094 *
6095 * There are other factors deciding whether mobile data is actually enabled, but they are
6096 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006097 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006098 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006099 *
6100 * @return {@code true} if data is enabled else {@code false}
6101 */
6102 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006103 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006104 try {
6105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6106 null);
6107 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6109 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 int phoneId = mSubscriptionController.getPhoneId(subId);
6115 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6116 Phone phone = PhoneFactory.getPhone(phoneId);
6117 if (phone != null) {
6118 boolean retVal = phone.isUserDataEnabled();
6119 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6120 return retVal;
6121 } else {
6122 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6123 return false;
6124 }
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006127 }
6128 }
6129
6130 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006131 * Checks if the device is capable of mobile data by considering whether whether the
6132 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6133 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006134 *
Shuo Qian985d1232020-01-08 14:30:06 -08006135 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006136 */
6137 @Override
6138 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006139 try {
6140 try {
6141 mApp.enforceCallingOrSelfPermission(
6142 android.Manifest.permission.ACCESS_NETWORK_STATE,
6143 null);
6144 } catch (Exception e) {
6145 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6146 "isDataEnabled");
6147 }
6148 } catch (Exception e) {
6149 enforceReadPrivilegedPermission("isDataEnabled");
6150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151
6152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 int phoneId = mSubscriptionController.getPhoneId(subId);
6155 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6156 Phone phone = PhoneFactory.getPhone(phoneId);
6157 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006158 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6160 return retVal;
6161 } else {
6162 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6163 return false;
6164 }
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006167 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006168 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006169
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006170 /**
6171 * Check if data is enabled for a specific reason
6172 * @param subId Subscription index
6173 * @param reason the reason the data enable change is taking place
6174 * @return {@code true} if the overall data is enabled; {@code false} if not.
6175 */
6176 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006177 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006178 @TelephonyManager.DataEnabledReason int reason) {
6179 try {
6180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6181 null);
6182 } catch (Exception e) {
6183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006184 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006185 }
6186
6187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 int phoneId = mSubscriptionController.getPhoneId(subId);
6191 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006192 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006193 + " reason=" + reason);
6194 }
6195 Phone phone = PhoneFactory.getPhone(phoneId);
6196 if (phone != null) {
6197 boolean retVal;
6198 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6199 retVal = phone.isUserDataEnabled();
6200 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006201 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006202 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006203 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006204 return retVal;
6205 } else {
6206 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006207 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006208 + subId + " retVal=false");
6209 }
6210 return false;
6211 }
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006217 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006218 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006219 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6220 // Skip the check if it's one of these special uids
6221 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6222 }
6223
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006224 //load access rules from carrier configs, and check those as well: b/139133814
6225 SubscriptionController subController = SubscriptionController.getInstance();
6226 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6227 || subController == null) return privilegeFromSim;
6228
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006229 PackageManager pkgMgr = phone.getContext().getPackageManager();
6230 String[] packages = pkgMgr.getPackagesForUid(uid);
6231
6232 final long identity = Binder.clearCallingIdentity();
6233 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006234 int subId = phone.getSubId();
6235 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6236 // A test override is in place for the privileges for this subId, so don't try to
6237 // read the subscription privileges.
6238 return privilegeFromSim;
6239 }
6240 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006241 SubscriptionManager subManager = (SubscriptionManager)
6242 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6243 for (String pkg : packages) {
6244 if (subManager.canManageSubscription(subInfo, pkg)) {
6245 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6246 }
6247 }
6248 return privilegeFromSim;
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253
6254 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6255 String pkgName) {
6256 //load access rules from carrier configs, and check those as well: b/139133814
6257 SubscriptionController subController = SubscriptionController.getInstance();
6258 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6259 || subController == null) return privilegeFromSim;
6260
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006263 int subId = phone.getSubId();
6264 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6265 // A test override is in place for the privileges for this subId, so don't try to
6266 // read the subscription privileges.
6267 return privilegeFromSim;
6268 }
6269 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006270 SubscriptionManager subManager = (SubscriptionManager)
6271 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6272 return subManager.canManageSubscription(subInfo, pkgName)
6273 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
6276 }
6277 }
6278
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006279 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006280 public int getCarrierPrivilegeStatus(int subId) {
6281 final Phone phone = getPhone(subId);
6282 if (phone == null) {
6283 loge("getCarrierPrivilegeStatus: Invalid subId");
6284 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6285 }
6286 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006287 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006288 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006289 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6290 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006291
6292 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6293 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006294 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006295 }
Junda Liu29340342014-07-10 15:23:27 -07006296
6297 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006298 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006299 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006300 final Phone phone = getPhone(subId);
6301 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006302 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6304 }
6305 UiccProfile profile =
6306 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6307 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006308 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006309 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6310 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006311 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006312 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006313 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006314 }
6315
6316 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006317 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6318 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006319 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006320 }
6321
6322 int phoneId = SubscriptionManager.getPhoneId(subId);
6323 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006324 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006325 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006326 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6327 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006328 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6329 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6330 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006331 }
6332
6333 @Override
6334 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006335 if (TextUtils.isEmpty(pkgName))
6336 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006337 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6338 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6339 UiccCard card = UiccController.getInstance().getUiccCard(i);
6340 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006341 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006342 continue;
6343 }
6344
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006345 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6346 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6347 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006348 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6349 break;
6350 }
6351 }
6352
6353 return result;
Junda Liu29340342014-07-10 15:23:27 -07006354 }
Derek Tan89e89d42014-07-08 17:00:10 -07006355
6356 @Override
Junda Liue64de782015-04-16 17:19:16 -07006357 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6358 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6359 loge("phoneId " + phoneId + " is not valid.");
6360 return null;
6361 }
6362 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006363 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006364 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006365 return null ;
6366 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006367 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006368 }
6369
Amith Yamasani6e118872016-02-19 12:53:51 -08006370 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006371 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006372 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006373 List<String> privilegedPackages = new ArrayList<>();
6374 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006375 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6376 // has UICC in that slot.
6377 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006378 if (card.hasCarrierPrivilegeRules()) {
6379 if (packages == null) {
6380 // Only check packages in user 0 for now
6381 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006382 PackageManager.MATCH_DISABLED_COMPONENTS
6383 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006384 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006385 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006386 }
6387 for (int p = packages.size() - 1; p >= 0; p--) {
6388 PackageInfo pkgInfo = packages.get(p);
6389 if (pkgInfo != null && pkgInfo.packageName != null
6390 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006391 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006392 privilegedPackages.add(pkgInfo.packageName);
6393 }
6394 }
6395 }
6396 }
6397 return privilegedPackages;
6398 }
6399
chen xuf7e9fe82019-05-09 19:31:02 -07006400 @Override
6401 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006402 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6403
6404 final long identity = Binder.clearCallingIdentity();
6405
chen xuf7e9fe82019-05-09 19:31:02 -07006406 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006407 try {
6408 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6409 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6410 }
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006413 }
6414 return privilegedPackages;
6415 }
6416
Wink Savilleb564aae2014-10-23 10:18:09 -07006417 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006418 final Phone phone = getPhone(subId);
6419 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006420 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006421 return null;
6422 }
6423 String iccId = card.getIccId();
6424 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006425 return null;
6426 }
6427 return iccId;
6428 }
6429
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006430 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006431 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6432 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006433 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006434 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 final String iccId = getIccId(subId);
6439 final Phone phone = getPhone(subId);
6440 if (phone == null) {
6441 return false;
6442 }
6443 final String subscriberId = phone.getSubscriberId();
6444
6445 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006446 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 + subscriberId + " to " + number);
6448 }
6449
6450 if (TextUtils.isEmpty(iccId)) {
6451 return false;
6452 }
6453
6454 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6455
6456 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6457 if (alphaTag == null) {
6458 editor.remove(alphaTagPrefKey);
6459 } else {
6460 editor.putString(alphaTagPrefKey, alphaTag);
6461 }
6462
6463 // Record both the line number and IMSI for this ICCID, since we need to
6464 // track all merged IMSIs based on line number
6465 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6466 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6467 if (number == null) {
6468 editor.remove(numberPrefKey);
6469 editor.remove(subscriberPrefKey);
6470 } else {
6471 editor.putString(numberPrefKey, number);
6472 editor.putString(subscriberPrefKey, subscriberId);
6473 }
6474
6475 editor.commit();
6476 return true;
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006479 }
Derek Tan7226c842014-07-02 17:42:23 -07006480 }
6481
6482 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006483 public String getLine1NumberForDisplay(int subId, String callingPackage,
6484 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006485 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006487 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006488 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006489 return null;
6490 }
Derek Tan97ebb422014-09-05 16:55:38 -07006491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 String iccId = getIccId(subId);
6495 if (iccId != null) {
6496 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6497 if (DBG_MERGE) {
6498 log("getLine1NumberForDisplay returning "
6499 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6500 }
6501 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6504 return null;
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006507 }
Derek Tan7226c842014-07-02 17:42:23 -07006508 }
6509
6510 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006511 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6512 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006514 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006515 return null;
6516 }
Derek Tan97ebb422014-09-05 16:55:38 -07006517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518 final long identity = Binder.clearCallingIdentity();
6519 try {
6520 String iccId = getIccId(subId);
6521 if (iccId != null) {
6522 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6523 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6524 }
6525 return null;
6526 } finally {
6527 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006528 }
Derek Tan7226c842014-07-02 17:42:23 -07006529 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006530
6531 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006532 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6533 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006534 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6535 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006537 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006538 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006539 return null;
6540 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006541
Jordan Liub49b04b2019-05-06 14:45:15 -07006542 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6543 // the process, where TelephonyManager was instantiated.
6544 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006545 final long identity = Binder.clearCallingIdentity();
6546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006547 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 final TelephonyManager tele = TelephonyManager.from(context);
6549 final SubscriptionManager sub = SubscriptionManager.from(context);
6550
6551 // Figure out what subscribers are currently active
6552 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
Jordan Liub49b04b2019-05-06 14:45:15 -07006554 // Only consider subs which match the current subId
6555 // This logic can be simplified. See b/131189269 for progress.
6556 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006557 activeSubscriberIds.add(tele.getSubscriberId(subId));
6558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559
6560 // First pass, find a number override for an active subscriber
6561 String mergeNumber = null;
6562 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6563 for (String key : prefs.keySet()) {
6564 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6565 final String subscriberId = (String) prefs.get(key);
6566 if (activeSubscriberIds.contains(subscriberId)) {
6567 final String iccId = key.substring(
6568 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6569 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6570 mergeNumber = (String) prefs.get(numberKey);
6571 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006572 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 + " for active subscriber " + subscriberId);
6574 }
6575 if (!TextUtils.isEmpty(mergeNumber)) {
6576 break;
6577 }
6578 }
6579 }
6580 }
6581
6582 // Shortcut when no active merged subscribers
6583 if (TextUtils.isEmpty(mergeNumber)) {
6584 return null;
6585 }
6586
6587 // Second pass, find all subscribers under that line override
6588 final ArraySet<String> result = new ArraySet<>();
6589 for (String key : prefs.keySet()) {
6590 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6591 final String number = (String) prefs.get(key);
6592 if (mergeNumber.equals(number)) {
6593 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6594 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6595 final String subscriberId = (String) prefs.get(subscriberKey);
6596 if (!TextUtils.isEmpty(subscriberId)) {
6597 result.add(subscriberId);
6598 }
6599 }
6600 }
6601 }
6602
6603 final String[] resultArray = result.toArray(new String[result.size()]);
6604 Arrays.sort(resultArray);
6605 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006606 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6608 }
6609 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006612 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006613 }
6614
6615 @Override
zoey chen38003472019-12-13 17:16:31 +08006616 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6617 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006618
6619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 final TelephonyManager telephonyManager = mApp.getSystemService(
6622 TelephonyManager.class);
6623 String subscriberId = telephonyManager.getSubscriberId(subId);
6624 if (subscriberId == null) {
6625 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006626 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006627 + subId);
6628 }
6629 return null;
6630 }
6631
6632 final SubscriptionInfo info = SubscriptionController.getInstance()
6633 .getSubscriptionInfo(subId);
6634 final ParcelUuid groupUuid = info.getGroupUuid();
6635 // If it doesn't belong to any group, return just subscriberId of itself.
6636 if (groupUuid == null) {
6637 return new String[]{subscriberId};
6638 }
6639
6640 // Get all subscriberIds from the group.
6641 final List<String> mergedSubscriberIds = new ArrayList<>();
6642 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006643 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006644 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006645 for (SubscriptionInfo subInfo : groupInfos) {
6646 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6647 if (subscriberId != null) {
6648 mergedSubscriberIds.add(subscriberId);
6649 }
6650 }
6651
6652 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
6655
6656 }
6657 }
6658
6659 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006660 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006661 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006662 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
6666 final Phone phone = getPhone(subId);
6667 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006671 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006672
6673 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006674 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006675 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6676 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006677 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6678 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 final Phone phone = getPhone(subId);
6683 if (phone == null) {
6684 return false;
6685 }
6686 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6687 cdmaNonRoamingList);
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006690 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006691 }
6692
6693 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006694 @Deprecated
6695 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6696 enforceModifyPermission();
6697
6698 int returnValue = 0;
6699 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006700 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006701 if(result.exception == null) {
6702 if (result.result != null) {
6703 byte[] responseData = (byte[])(result.result);
6704 if(responseData.length > oemResp.length) {
6705 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6706 responseData.length + "bytes. Buffer Size is " +
6707 oemResp.length + "bytes.");
6708 }
6709 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6710 returnValue = responseData.length;
6711 }
6712 } else {
6713 CommandException ex = (CommandException) result.exception;
6714 returnValue = ex.getCommandError().ordinal();
6715 if(returnValue > 0) returnValue *= -1;
6716 }
6717 } catch (RuntimeException e) {
6718 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6719 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6720 if(returnValue > 0) returnValue *= -1;
6721 }
6722
6723 return returnValue;
6724 }
6725
6726 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006727 public void setRadioCapability(RadioAccessFamily[] rafs) {
6728 try {
6729 ProxyController.getInstance().setRadioCapability(rafs);
6730 } catch (RuntimeException e) {
6731 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6732 }
6733 }
6734
6735 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006736 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006737 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006738 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006739 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006740 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742 final long identity = Binder.clearCallingIdentity();
6743 try {
chen xub97461a2018-10-26 14:17:57 -07006744 TelephonyPermissions
6745 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6746 mApp, phone.getSubId(), "getRadioAccessFamily");
6747 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
chen xub97461a2018-10-26 14:17:57 -07006751 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006752 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006753
6754 @Override
6755 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006756 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006761 ImsManager.getInstance(defaultPhone.getContext(),
6762 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006766 }
6767
6768 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006769 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006770 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6772 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006773 return false;
6774 }
Svet Ganovb320e182015-04-16 12:30:10 -07006775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
6778 // Check the user preference and the system-level IMS setting. Even if the user has
6779 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6780 // In the long run, we may instead need to check if there exists a connection service
6781 // which can support video calling.
6782 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006783 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 return imsManager.isVtEnabledByPlatform()
6785 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6786 && imsManager.isVtEnabledByUser();
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006790 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006791
Andrew Leea1239f22015-03-02 17:44:07 -08006792 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006793 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6794 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006796 mApp, subId, callingPackage, callingFeatureId,
6797 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 return false;
6799 }
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 CarrierConfigManager configManager =
6804 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
Andrew Leea1239f22015-03-02 17:44:07 -08006810 }
6811
6812 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006813 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006815 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 return false;
6817 }
6818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 CarrierConfigManager configManager =
6822 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006823 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
Andrew Leea1239f22015-03-02 17:44:07 -08006828 }
6829
Andrew Lee9431b832015-03-09 18:46:45 -07006830 @Override
6831 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006832 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006833 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006834 }
6835
6836 @Override
6837 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 final long identity = Binder.clearCallingIdentity();
6839 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006840 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
Andrew Lee9431b832015-03-09 18:46:45 -07006844 }
6845
Hall Liuf6668912018-10-31 17:05:23 -07006846 /**
6847 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6848 * support for the feature and device firmware support.
6849 *
6850 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6851 */
6852 @Override
6853 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006855 final Phone phone = getPhone(subscriptionId);
6856 if (phone == null) {
6857 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6858 return false;
6859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6863 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006864 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 return isCarrierSupported && isDeviceSupported;
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Hall Liu98187582018-01-22 19:15:32 -08006869 }
6870
Hall Liuf6668912018-10-31 17:05:23 -07006871 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006872 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6873 * RTT setting, will return true if the device and carrier both support RTT.
6874 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006875 */
6876 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006877 final long identity = Binder.clearCallingIdentity();
6878 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006879 boolean isRttSupported = isRttSupported(subscriptionId);
6880 boolean isUserRttSettingOn = Settings.Secure.getInt(
6881 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6882 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6883 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6884 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006888 }
6889
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006890 @Deprecated
6891 @Override
6892 public String getDeviceId(String callingPackage) {
6893 return getDeviceIdWithFeature(callingPackage, null);
6894 }
6895
Sanket Padawe7310cc72015-01-14 09:53:20 -08006896 /**
6897 * Returns the unique device ID of phone, for example, the IMEI for
6898 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6899 *
6900 * <p>Requires Permission:
6901 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6902 */
6903 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006904 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006905 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006906 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006907 return null;
6908 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006909 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006910 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006911 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006912 return null;
6913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914
6915 final long identity = Binder.clearCallingIdentity();
6916 try {
6917 return phone.getDeviceId();
6918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006921 }
6922
Ping Sunc67b7c22016-03-02 19:16:45 +08006923 /**
6924 * {@hide}
6925 * Returns the IMS Registration Status on a particular subid
6926 *
6927 * @param subId
6928 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006929 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006930 Phone phone = getPhone(subId);
6931 if (phone != null) {
6932 return phone.isImsRegistered();
6933 } else {
6934 return false;
6935 }
6936 }
6937
Santos Cordon7a1885b2015-02-03 11:15:19 -08006938 @Override
6939 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006946 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006947
Tyler Gunnf70ed162019-04-03 15:28:53 -07006948 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006949 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006950 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006952 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006953 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6954 }
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
6961 }
6962
6963 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006964 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006965 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6966 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 Phone phone = getPhone(subscriptionId);
6970 if (phone == null) {
6971 return null;
6972 }
6973 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
6976 }
6977 }
6978
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006979 /**
6980 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006981 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006982 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 Phone phone = getPhone(subId);
6986 if (phone != null) {
6987 return phone.isWifiCallingEnabled();
6988 } else {
6989 return false;
6990 }
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006993 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006994 }
6995
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006996 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006997 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006998 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006999 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 final long identity = Binder.clearCallingIdentity();
7001 try {
7002 Phone phone = getPhone(subId);
7003 if (phone != null) {
7004 return phone.isVideoEnabled();
7005 } else {
7006 return false;
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007010 }
7011 }
7012
7013 /**
7014 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7015 * defined in {@link ImsRegistrationImplBase}.
7016 */
7017 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 Phone phone = getPhone(subId);
7021 if (phone != null) {
7022 return phone.getImsRegistrationTech();
7023 } else {
7024 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7025 }
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007028 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007029 }
7030
Stuart Scott8eef64f2015-04-08 15:13:54 -07007031 @Override
7032 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007033 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007034 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7035 return;
7036 }
7037
Svet Ganovcc087f82015-05-12 20:35:54 -07007038 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007039
Svet Ganovcc087f82015-05-12 20:35:54 -07007040 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007041 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7042 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007043 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007044 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007045 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007046 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7048 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007049 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007050 // There has been issues when Sms raw table somehow stores orphan
7051 // fragments. They lead to garbled message when new fragments come
7052 // in and combined with those stale ones. In case this happens again,
7053 // user can reset all network settings which will clean up this table.
7054 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007055 // Clean up IMS settings as well here.
7056 int slotId = getSlotIndex(subId);
7057 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7058 ImsManager.getInstance(mApp, slotId).factoryReset();
7059 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007060
7061 // Erase modem config if erase modem on network setting is enabled.
7062 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7063 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7064 if (configValue != null && Boolean.parseBoolean(configValue)) {
7065 sendEraseModemConfig(getDefaultPhone());
7066 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007067 } finally {
7068 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007069 }
7070 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007071
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007072 private void cleanUpSmsRawTable(Context context) {
7073 ContentResolver resolver = context.getContentResolver();
7074 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7075 resolver.delete(uri, null, null);
7076 }
7077
Narayan Kamath1c496c22015-04-16 14:40:19 +01007078 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007079 public String getSimLocaleForSubscriber(int subId) {
7080 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7081 final Phone phone = getPhone(subId);
7082 if (phone == null) {
7083 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007084 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 final long identity = Binder.clearCallingIdentity();
7087 try {
chen xu5d3637b2019-01-21 23:31:38 -08007088 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007089 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007090 if (info == null) {
7091 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7092 return null;
7093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 // Try and fetch the locale from the carrier properties or from the SIM language
7095 // preferences (EF-PL and EF-LI)...
7096 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007098 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7099 if (localeFromDefaultSim != null) {
7100 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7101 if (DBG) log("Using locale from subId: " + subId + " locale: "
7102 + localeFromDefaultSim);
7103 return localeFromDefaultSim.toLanguageTag();
7104 } else {
7105 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 }
7107 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109 // The SIM language preferences only store a language (e.g. fr = French), not an
7110 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7111 // the SIM and carrier preferences does not include a country we add the country
7112 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007113 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007115 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 return mccLocale.toLanguageTag();
7117 }
7118
7119 if (DBG) log("No locale found - returning null");
7120 return null;
7121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007124 }
7125
7126 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007127 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007128 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007129 }
7130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 /**
7132 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7133 */
7134 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007135 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007136 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007137 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007138
Chenjie Yu1ba97252018-01-11 18:16:20 -08007139 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007140 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007141
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007142 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007143 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7144 * representing the state of the modem.
7145 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007146 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7147 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007148 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007149 */
7150 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007151 public void requestModemActivityInfo(ResultReceiver result) {
7152 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007153 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
7156 try {
sqian1a1be542020-03-05 11:37:28 -08007157 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 } finally {
7159 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007160 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007161 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007162
Siddharth Rayb8114062018-06-17 15:02:38 -07007163 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7164 // less than total activity duration.
7165 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7166 if (info == null) {
7167 return false;
7168 }
7169 int activityDurationMs =
7170 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7171 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007172 int[] txTimeMs = info.getTransmitTimeMillis();
7173 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7174 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007175 }
7176 return (info.isValid()
7177 && (info.getSleepTimeMillis() <= activityDurationMs)
7178 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007179 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007180 && (totalTxTimeMs <= activityDurationMs));
7181 }
7182
Jack Yu85bd38a2015-11-09 11:34:32 -08007183 /**
7184 * {@hide}
7185 * Returns the service state information on specified subscription.
7186 */
7187 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007188 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7189 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007191 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007192 return null;
7193 }
7194
Hall Liuf19c44f2018-11-27 14:38:17 -08007195 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7196 LocationAccessPolicy.checkLocationPermission(mApp,
7197 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7198 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007199 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007200 .setCallingPid(Binder.getCallingPid())
7201 .setCallingUid(Binder.getCallingUid())
7202 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007203 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007204 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7205 .build());
7206
7207 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7208 LocationAccessPolicy.checkLocationPermission(mApp,
7209 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7210 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007211 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007212 .setCallingPid(Binder.getCallingPid())
7213 .setCallingUid(Binder.getCallingUid())
7214 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007215 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007216 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7217 .build());
7218 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7219 boolean hasFinePermission =
7220 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7221 boolean hasCoarsePermission =
7222 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 final Phone phone = getPhone(subId);
7227 if (phone == null) {
7228 return null;
7229 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007230
Hall Liuf19c44f2018-11-27 14:38:17 -08007231 ServiceState ss = phone.getServiceState();
7232
7233 // Scrub out the location info in ServiceState depending on what level of access
7234 // the caller has.
7235 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007236 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7237 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007241 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007242
7243 /**
7244 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7245 *
7246 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7247 * voicemail ringtone.
7248 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7249 * PhoneAccount.
7250 */
7251 @Override
7252 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7256 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007257 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007264 }
7265
7266 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007267 * Sets the per-account voicemail ringtone.
7268 *
7269 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7270 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7271 *
7272 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7273 * voicemail ringtone.
7274 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7275 * PhoneAccount.
7276 */
7277 @Override
7278 public void setVoicemailRingtoneUri(String callingPackage,
7279 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007280 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007282 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7283 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7285 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7286 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288
7289 final long identity = Binder.clearCallingIdentity();
7290 try {
7291 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7292 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007293 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 }
7295 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007298 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007299 }
7300
7301 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007302 * Returns whether vibration is set for voicemail notification in Phone settings.
7303 *
7304 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7305 * voicemail vibration setting.
7306 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7307 */
7308 @Override
7309 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7313 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007314 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007321 }
7322
Youhan Wange64578a2016-05-02 15:32:42 -07007323 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007324 * Sets the per-account voicemail vibration.
7325 *
7326 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7327 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7328 *
7329 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7330 * voicemail vibration setting.
7331 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7332 * specific PhoneAccount.
7333 */
7334 @Override
7335 public void setVoicemailVibrationEnabled(String callingPackage,
7336 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007339 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7340 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7342 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7343 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007344 }
7345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7349 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007350 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 }
7352 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007355 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007356 }
7357
7358 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007359 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7360 *
7361 * @throws SecurityException if the caller does not have the required permission
7362 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007363 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007364 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007365 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007366 }
7367
7368 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007369 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7370 * permission.
7371 *
7372 * @throws SecurityException if the caller does not have the required permission
7373 */
7374 private void enforceSendSmsPermission() {
7375 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7376 }
7377
7378 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007379 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007380 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007381 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007382 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007383 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 if (componentName == null) {
7389 throw new SecurityException(
7390 "Caller not current active visual voicemail package[null]");
7391 }
7392 String vvmPackage = componentName.getPackageName();
7393 if (!callingPackage.equals(vvmPackage)) {
7394 throw new SecurityException("Caller not current active visual voicemail package["
7395 + vvmPackage + "]");
7396 }
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007399 }
7400 }
7401
7402 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007403 * Return the application ID for the app type.
7404 *
7405 * @param subId the subscription ID that this request applies to.
7406 * @param appType the uicc app type.
7407 * @return Application ID for specificied app type, or null if no uicc.
7408 */
7409 @Override
7410 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007411 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007412 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413
7414 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007415 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 if (phone == null) {
7417 return null;
7418 }
7419 String aid = null;
7420 try {
7421 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7422 .getApplicationByType(appType).getAid();
7423 } catch (Exception e) {
7424 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7425 }
7426 return aid;
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007429 }
Youhan Wange64578a2016-05-02 15:32:42 -07007430 }
7431
Youhan Wang4001d252016-05-11 10:29:41 -07007432 /**
7433 * Return the Electronic Serial Number.
7434 *
7435 * @param subId the subscription ID that this request applies to.
7436 * @return ESN or null if error.
7437 */
7438 @Override
7439 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007440 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007441 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442
7443 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007444 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 if (phone == null) {
7446 return null;
7447 }
7448 String esn = null;
7449 try {
7450 esn = phone.getEsn();
7451 } catch (Exception e) {
7452 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7453 }
7454 return esn;
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007457 }
Youhan Wang4001d252016-05-11 10:29:41 -07007458 }
7459
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007460 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007461 * Return the Preferred Roaming List Version.
7462 *
7463 * @param subId the subscription ID that this request applies to.
7464 * @return PRLVersion or null if error.
7465 */
7466 @Override
7467 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007468 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007469 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470
7471 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007472 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 if (phone == null) {
7474 return null;
7475 }
7476 String cdmaPrlVersion = null;
7477 try {
7478 cdmaPrlVersion = phone.getCdmaPrlVersion();
7479 } catch (Exception e) {
7480 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7481 }
7482 return cdmaPrlVersion;
7483 } finally {
7484 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007485 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007486 }
7487
7488 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007489 * Get snapshot of Telephony histograms
7490 * @return List of Telephony histograms
7491 * @hide
7492 */
7493 @Override
7494 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7496 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 return RIL.getTelephonyRILTimingHistograms();
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007504 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007505
7506 /**
7507 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007508 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7509 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007510 * Require system privileges. In the future we may add this to carrier APIs.
7511 *
Michele Berionne482f8202018-11-27 18:57:59 -08007512 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007513 */
7514 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007515 @TelephonyManager.SetCarrierRestrictionResult
7516 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007517 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007519
Michele Berionne482f8202018-11-27 18:57:59 -08007520 if (carrierRestrictionRules == null) {
7521 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007522 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 final long identity = Binder.clearCallingIdentity();
7525 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007526 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007527 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007531 }
7532
7533 /**
7534 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007535 * Get the allowed carrier list and the excluded carrier list, including the priority between
7536 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007537 * Require system privileges. In the future we may add this to carrier APIs.
7538 *
Michele Berionne482f8202018-11-27 18:57:59 -08007539 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007540 */
7541 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007542 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007543 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007548 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7549 if (response instanceof CarrierRestrictionRules) {
7550 return (CarrierRestrictionRules) response;
7551 }
7552 // Response is an Exception of some kind,
7553 // which is signalled to the user as a NULL retval
7554 return null;
7555 } catch (Exception e) {
7556 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7557 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007561 }
7562
fionaxu59545b42016-05-25 15:53:37 -07007563 /**
fionaxu59545b42016-05-25 15:53:37 -07007564 * Action set from carrier signalling broadcast receivers to enable/disable radio
7565 * @param subId the subscription ID that this action applies to.
7566 * @param enabled control enable or disable radio.
7567 * {@hide}
7568 */
7569 @Override
7570 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7571 enforceModifyPermission();
7572 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573
7574 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007575 if (phone == null) {
7576 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7577 return;
7578 }
7579 try {
7580 phone.carrierActionSetRadioEnabled(enabled);
7581 } catch (Exception e) {
7582 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 } finally {
7584 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007585 }
7586 }
7587
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007588 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007589 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7590 * network status based on which carrier apps could apply actions accordingly,
7591 * enable/disable default url handler for example.
7592 *
7593 * @param subId the subscription ID that this action applies to.
7594 * @param report control start/stop reporting the default network status.
7595 * {@hide}
7596 */
7597 @Override
7598 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7599 enforceModifyPermission();
7600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601
7602 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007603 if (phone == null) {
7604 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7605 return;
7606 }
7607 try {
7608 phone.carrierActionReportDefaultNetworkStatus(report);
7609 } catch (Exception e) {
7610 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 } finally {
7612 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007613 }
7614 }
7615
7616 /**
fionaxud9622282017-07-17 17:51:30 -07007617 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7618 * @param subId the subscription ID that this action applies to.
7619 * {@hide}
7620 */
7621 @Override
7622 public void carrierActionResetAll(int subId) {
7623 enforceModifyPermission();
7624 final Phone phone = getPhone(subId);
7625 if (phone == null) {
7626 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7627 return;
7628 }
7629 try {
7630 phone.carrierActionResetAll();
7631 } catch (Exception e) {
7632 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7633 }
7634 }
7635
7636 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007637 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7638 * bug report is being generated.
7639 */
7640 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007641 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007642 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7643 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007644 writer.println("Permission Denial: can't dump Phone from pid="
7645 + Binder.getCallingPid()
7646 + ", uid=" + Binder.getCallingUid()
7647 + "without permission "
7648 + android.Manifest.permission.DUMP);
7649 return;
7650 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007651 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007652 }
Jack Yueb89b242016-06-22 13:27:47 -07007653
Brad Ebingerdac2f002018-04-03 15:17:52 -07007654 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007655 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7656 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7657 @NonNull String[] args) {
7658 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7659 this, in.getFileDescriptor(), out.getFileDescriptor(),
7660 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007661 }
7662
Jack Yueb89b242016-06-22 13:27:47 -07007663 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007664 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007665 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007666 * @param reason the reason the data enable change is taking place
7667 * @param enabled True if enabling the data, otherwise disabling.
7668 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007669 */
7670 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007671 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007672 boolean enabled) {
7673 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7674 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7675 try {
7676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007677 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007678 } catch (SecurityException se) {
7679 enforceModifyPermission();
7680 }
7681 } else {
7682 enforceModifyPermission();
7683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684
7685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 Phone phone = getPhone(subId);
7688 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007689 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7690 phone.carrierActionSetMeteredApnsEnabled(enabled);
7691 } else {
7692 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 }
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007697 }
7698 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007699
7700 /**
7701 * Get Client request stats
7702 * @return List of Client Request Stats
7703 * @hide
7704 */
7705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007706 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7707 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007709 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007710 return null;
7711 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007712 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 if (phone != null) {
7717 return phone.getClientRequestStats();
7718 }
7719
7720 return null;
7721 } finally {
7722 Binder.restoreCallingIdentity(identity);
7723 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007724 }
7725
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007726 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007728 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007729 }
Jack Yueb4124c2017-02-16 15:32:43 -08007730
7731 /**
Grace Chen70990072017-03-24 17:21:30 -07007732 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007733 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007734 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007735 * @param state State of SIM (power down, power up, pass through)
7736 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7737 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7738 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007739 *
7740 **/
7741 @Override
Grace Chen70990072017-03-24 17:21:30 -07007742 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007743 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007744 Phone phone = PhoneFactory.getPhone(slotIndex);
7745
vagdeviaf9a5b92018-08-15 16:01:53 -07007746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007751 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007755 }
7756 }
Shuo Qiandd210312017-04-12 22:11:33 +00007757
Tyler Gunn65d45c22017-06-05 11:22:26 -07007758 private boolean isUssdApiAllowed(int subId) {
7759 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007760 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007761 if (configManager == null) {
7762 return false;
7763 }
7764 PersistableBundle pb = configManager.getConfigForSubId(subId);
7765 if (pb == null) {
7766 return false;
7767 }
7768 return pb.getBoolean(
7769 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7770 }
7771
Shuo Qiandd210312017-04-12 22:11:33 +00007772 /**
7773 * Check if phone is in emergency callback mode
7774 * @return true if phone is in emergency callback mode
7775 * @param subId sub id
7776 */
goneil9c5f4872017-12-05 14:07:56 -08007777 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007778 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007779 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007780 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781
7782 final long identity = Binder.clearCallingIdentity();
7783 try {
7784 if (phone != null) {
7785 return phone.isInEcm();
7786 } else {
7787 return false;
7788 }
7789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007791 }
7792 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007793
7794 /**
7795 * Get the current signal strength information for the given subscription.
7796 * Because this information is not updated when the device is in a low power state
7797 * it should not be relied-upon to be current.
7798 * @param subId Subscription index
7799 * @return the most recent cached signal strength info from the modem
7800 */
7801 @Override
7802 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 final long identity = Binder.clearCallingIdentity();
7804 try {
7805 Phone p = getPhone(subId);
7806 if (p == null) {
7807 return null;
7808 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 return p.getSignalStrength();
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007814 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007815
Pengquan Meng77b7f132018-08-22 14:49:57 -07007816 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007817 * Get the current modem radio state for the given slot.
7818 * @param slotIndex slot index.
7819 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007820 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007821 * @return the current radio power state from the modem
7822 */
7823 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007824 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007825 Phone phone = PhoneFactory.getPhone(slotIndex);
7826 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7828 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007829 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7830 }
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 return phone.getRadioPowerState();
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
7839 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7840 }
7841
7842 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007843 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7844 *
7845 * <p>Requires one of the following permissions:
7846 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7847 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7848 * privileges.
7849 *
7850 * @param subId subscription id
7851 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7852 * {@code false}.
7853 */
7854 @Override
7855 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007856 try {
7857 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7858 null);
7859 } catch (Exception e) {
7860 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7861 mApp, subId, "isDataRoamingEnabled");
7862 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007863
Pengquan Menga1bb6272018-09-06 09:59:22 -07007864 boolean isEnabled = false;
7865 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007866 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007867 Phone phone = getPhone(subId);
7868 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007871 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007872 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007873 }
7874
7875
7876 /**
7877 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7878 *
7879 * <p> Requires permission:
7880 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7881 * privileges.
7882 *
7883 * @param subId subscription id
7884 * @param isEnabled {@code true} means enable, {@code false} means disable.
7885 */
7886 @Override
7887 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7889 mApp, subId, "setDataRoamingEnabled");
7890
Pengquan Menga1bb6272018-09-06 09:59:22 -07007891 final long identity = Binder.clearCallingIdentity();
7892 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007893 Phone phone = getPhone(subId);
7894 if (phone != null) {
7895 phone.setDataRoamingEnabled(isEnabled);
7896 }
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007899 }
7900 }
7901
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007902 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007903 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007904 TelephonyPermissions
7905 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007906 mApp, subId, "isManualNetworkSelectionAllowed");
7907
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007908 boolean isAllowed = true;
7909 final long identity = Binder.clearCallingIdentity();
7910 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007911 Phone phone = getPhone(subId);
7912 if (phone != null) {
7913 isAllowed = phone.isCspPlmnEnabled();
7914 }
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
7918 return isAllowed;
7919 }
7920
7921 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007922 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007923 // Verify that tha callingPackage belongs to the calling UID
7924 mApp.getSystemService(AppOpsManager.class)
7925 .checkPackage(Binder.getCallingUid(), callingPackage);
7926
Jordan Liu1e142fc2019-04-22 15:10:43 -07007927 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007928 try {
7929 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007930 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007931 } catch (SecurityException e) {
7932 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7933 // has carrier privileges on an active UICC
7934 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7935 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007936 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007937 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007938 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007942 UiccController uiccController = UiccController.getInstance();
7943 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007944 if (hasReadPermission) {
7945 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007946 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007947
7948 // Remove private info if the caller doesn't have access
7949 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7950 for (UiccCardInfo cardInfo : cardInfos) {
7951 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7952 // is available
7953 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7954 if (card == null || card.getUiccProfile() == null) {
7955 // assume no access if the card or profile is unavailable
7956 filteredInfos.add(cardInfo.getUnprivileged());
7957 continue;
7958 }
7959 UiccProfile profile = card.getUiccProfile();
7960 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7961 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7962 filteredInfos.add(cardInfo);
7963 } else {
7964 filteredInfos.add(cardInfo.getUnprivileged());
7965 }
7966 }
7967 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007968 } finally {
7969 Binder.restoreCallingIdentity(identity);
7970 }
7971 }
7972
7973 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007974 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007975 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7980 if (slots == null) {
7981 Rlog.i(LOG_TAG, "slots is null.");
7982 return null;
7983 }
7984
7985 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7986 for (int i = 0; i < slots.length; i++) {
7987 UiccSlot slot = slots[i];
7988 if (slot == null) {
7989 continue;
7990 }
7991
Jordan Liu7be7e652019-05-06 18:55:02 +00007992 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 UiccCard card = slot.getUiccCard();
7994 if (card != null) {
7995 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007996 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007997 cardId = slot.getEid();
7998 if (TextUtils.isEmpty(cardId)) {
7999 cardId = slot.getIccId();
8000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 }
8002
Jordan Liu857451f2019-05-09 16:35:35 -07008003 if (cardId != null) {
8004 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8005 // if cardId is an EID, it's all digits so this is fine
8006 cardId = IccUtils.stripTrailingFs(cardId);
8007 }
8008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 int cardState = 0;
8010 switch (slot.getCardState()) {
8011 case CARDSTATE_ABSENT:
8012 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8013 break;
8014 case CARDSTATE_PRESENT:
8015 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8016 break;
8017 case CARDSTATE_ERROR:
8018 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8019 break;
8020 case CARDSTATE_RESTRICTED:
8021 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8022 break;
8023 default:
8024 break;
8025
8026 }
8027
8028 infos[i] = new UiccSlotInfo(
8029 slot.isActive(),
8030 slot.isEuicc(),
8031 cardId,
8032 cardState,
8033 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008034 slot.isExtendedApduSupported(),
8035 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 }
8037 return infos;
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008040 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008041 }
8042
8043 @Override
8044 public boolean switchSlots(int[] physicalSlots) {
8045 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046
8047 final long identity = Binder.clearCallingIdentity();
8048 try {
8049 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
8052 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008053 }
Jack Yu4c988042018-02-27 15:30:01 -08008054
8055 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008056 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 return UiccController.getInstance().getCardIdForDefaultEuicc();
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
8062 }
8063 }
8064
Pengquan Meng85728fb2018-03-12 16:31:21 -07008065 /**
goneil47ffb6e2018-04-06 15:40:58 -07008066 * A test API to reload the UICC profile.
8067 *
8068 * <p>Requires that the calling app has permission
8069 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8070 * @hide
8071 */
8072 @Override
8073 public void refreshUiccProfile(int subId) {
8074 enforceModifyPermission();
8075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 Phone phone = getPhone(subId);
8079 if (phone == null) {
8080 return;
8081 }
8082 UiccCard uiccCard = phone.getUiccCard();
8083 if (uiccCard == null) {
8084 return;
8085 }
8086 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8087 if (uiccProfile == null) {
8088 return;
8089 }
8090 uiccProfile.refresh();
8091 } finally {
8092 Binder.restoreCallingIdentity(identity);
8093 }
8094 }
8095
8096 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008097 * Returns false if the mobile data is disabled by default, otherwise return true.
8098 */
8099 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008100 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008101 }
8102
8103 /**
8104 * Returns true if the data roaming is enabled by default, i.e the system property
8105 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8106 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8107 */
8108 private boolean getDefaultDataRoamingEnabled(int subId) {
8109 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008110 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008111 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008112 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8113 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8114 return isDataRoamingEnabled;
8115 }
8116
8117 /**
8118 * Returns the default network type for the given {@code subId}, if the default network type is
8119 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8120 */
8121 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008122 List<Integer> list = TelephonyProperties.default_network();
8123 int phoneId = mSubscriptionController.getPhoneId(subId);
8124 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8125 return list.get(phoneId);
8126 }
8127 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008128 }
fionaxua13278b2018-03-21 00:08:13 -07008129
8130 @Override
8131 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008132 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134
8135 final long identity = Binder.clearCallingIdentity();
8136 try {
8137 final Phone phone = getPhone(subId);
8138 if (phone == null) {
8139 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8140 return;
8141 }
chen xueaba88a2019-03-15 13:15:10 -07008142 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8143 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008144 if (carrierPrivilegeRules == null) {
8145 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8146 } else {
8147 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149 } finally {
8150 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008151 }
fionaxua13278b2018-03-21 00:08:13 -07008152 }
8153
8154 @Override
8155 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008156 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 final Phone phone = getPhone(subId);
8161 if (phone == null) {
8162 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8163 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8164 }
8165 return phone.getCarrierIdListVersion();
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008168 }
fionaxua13278b2018-03-21 00:08:13 -07008169 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008170
8171 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008172 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8173 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008175 mApp, subId, callingPackage, callingFeatureId,
8176 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008177 return -1;
8178 }
8179
8180 final long identity = Binder.clearCallingIdentity();
8181 try {
8182 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
8185 }
8186 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008187
8188 @Override
8189 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008190 TelephonyPermissions
8191 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008192 mApp, subId, "getCdmaRoamingMode");
8193
8194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
8201
8202 @Override
8203 public boolean setCdmaRoamingMode(int subId, int mode) {
8204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8205 mApp, subId, "setCdmaRoamingMode");
8206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
8214
8215 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008216 public int getCdmaSubscriptionMode(int subId) {
8217 TelephonyPermissions
8218 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8219 mApp, subId, "getCdmaSubscriptionMode");
8220
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
8223 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
8227 }
8228
8229 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008230 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8232 mApp, subId, "setCdmaSubscriptionMode");
8233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008241
sqianc5eccab2018-10-19 18:46:41 -07008242 @Override
sqian8c685422019-02-22 15:55:18 -08008243 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008244 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008246 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8247 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008248 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8249 }
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
sqian854d44b2018-12-12 16:48:18 -08008252 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8253 for (Phone phone: PhoneFactory.getPhones()) {
8254 if (phone.getEmergencyNumberTracker() != null
8255 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8256 emergencyNumberListInternal.put(
8257 phone.getSubId(),
8258 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8259 }
sqian11b7a0e2018-12-05 18:48:28 -08008260 }
sqian854d44b2018-12-12 16:48:18 -08008261 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
sqianc5eccab2018-10-19 18:46:41 -07008265 }
8266
8267 @Override
sqian8c685422019-02-22 15:55:18 -08008268 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008270 if (!exactMatch) {
8271 TelephonyPermissions
8272 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008273 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008274 }
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
sqian854d44b2018-12-12 16:48:18 -08008277 for (Phone phone: PhoneFactory.getPhones()) {
8278 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008279 && phone.getEmergencyNumberTracker()
8280 .isEmergencyNumber(number, exactMatch)) {
8281 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008282 }
sqian11b7a0e2018-12-05 18:48:28 -08008283 }
8284 return false;
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
8289
sqianf4ca7ed2019-01-15 18:32:07 -08008290 /**
8291 * Update emergency number list for test mode.
8292 */
8293 @Override
8294 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8296 "updateEmergencyNumberListTestMode");
8297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 for (Phone phone: PhoneFactory.getPhones()) {
8301 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8302 if (tracker != null) {
8303 tracker.executeEmergencyNumberTestModeCommand(action, num);
8304 }
8305 }
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
8310
8311 /**
8312 * Get the full emergency number list for test mode.
8313 */
8314 @Override
8315 public List<String> getEmergencyNumberListTestMode() {
8316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8317 "getEmergencyNumberListTestMode");
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
8321 Set<String> emergencyNumbers = new HashSet<>();
8322 for (Phone phone: PhoneFactory.getPhones()) {
8323 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8324 if (tracker != null) {
8325 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8326 emergencyNumbers.add(num.getNumber());
8327 }
8328 }
8329 }
8330 return new ArrayList<>(emergencyNumbers);
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
chen xud6b45bd2018-10-30 22:27:10 -07008336 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008337 public int getEmergencyNumberDbVersion(int subId) {
8338 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8339
8340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 final Phone phone = getPhone(subId);
8343 if (phone == null) {
8344 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8345 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8346 }
8347 return phone.getEmergencyNumberDbVersion();
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
8351 }
8352
8353 @Override
8354 public void notifyOtaEmergencyNumberDbInstalled() {
8355 enforceModifyPermission();
8356
8357 final long identity = Binder.clearCallingIdentity();
8358 try {
8359 for (Phone phone: PhoneFactory.getPhones()) {
8360 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8361 if (tracker != null) {
8362 tracker.updateOtaEmergencyNumberDatabase();
8363 }
8364 }
8365 } finally {
8366 Binder.restoreCallingIdentity(identity);
8367 }
8368 }
8369
8370 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008371 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008372 enforceActiveEmergencySessionPermission();
8373
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 for (Phone phone: PhoneFactory.getPhones()) {
8377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8378 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008379 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8380 }
8381 }
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 @Override
8388 public void resetOtaEmergencyNumberDbFilePath() {
8389 enforceActiveEmergencySessionPermission();
8390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 for (Phone phone: PhoneFactory.getPhones()) {
8394 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8395 if (tracker != null) {
8396 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008397 }
8398 }
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
8401 }
8402 }
8403
8404 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008405 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8406 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8407 Phone phone = getPhone(subId);
8408 if (phone == null) {
8409 return null;
8410 }
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 UiccProfile profile = UiccController.getInstance()
8414 .getUiccProfileForPhone(phone.getPhoneId());
8415 if (profile != null) {
8416 return profile.getCertsFromCarrierPrivilegeAccessRules();
8417 }
8418 } finally {
8419 Binder.restoreCallingIdentity(identity);
8420 }
8421 return null;
8422 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008423
8424 /**
8425 * Enable or disable a modem stack.
8426 */
8427 @Override
8428 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8429 enforceModifyPermission();
8430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 Phone phone = PhoneFactory.getPhone(slotIndex);
8434 if (phone == null) {
8435 return false;
8436 } else {
8437 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8438 }
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
Michelecea4cf22018-12-21 15:00:11 -08008443
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008444 /**
8445 * Whether a modem stack is enabled or not.
8446 */
8447 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008448 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8449 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008450 Phone phone = PhoneFactory.getPhone(slotIndex);
8451 if (phone == null) return false;
8452
8453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008454 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8455 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008456 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8457 }
8458
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008461 try {
8462 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8463 } catch (NoSuchElementException ex) {
8464 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8465 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
Michelecea4cf22018-12-21 15:00:11 -08008471 @Override
Michele0ea7d782019-03-19 14:58:42 -07008472 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008473 enforceModifyPermission();
8474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008478 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008479 .commit();
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
8484
8485 @Override
Michele0ea7d782019-03-19 14:58:42 -07008486 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008487 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008489 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8490 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008492 }
Michelecea4cf22018-12-21 15:00:11 -08008493
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
Michele0ea7d782019-03-19 14:58:42 -07008496 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008501
Michele0ea7d782019-03-19 14:58:42 -07008502 @TelephonyManager.IsMultiSimSupportedResult
8503 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008504 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8505 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8506 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008507 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8508 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008509 }
8510 // Check if the hardware supports multisim functionality. If usage of multisim is not
8511 // supported by the modem, indicate that it is restricted.
8512 PhoneCapability staticCapability =
8513 mPhoneConfigurationManager.getStaticPhoneCapability();
8514 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008515 loge("isMultiSimSupportedInternal: no static configuration available");
8516 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008517 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008518 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008519 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8520 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008521 }
8522 // Check if support of multiple SIMs is restricted by carrier
8523 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008524 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008525 }
8526
Michele0ea7d782019-03-19 14:58:42 -07008527 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008528 }
8529
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008530 /**
8531 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008532 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8533 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8534 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008535 * @param numOfSims number of active sims we want to switch to
8536 */
8537 @Override
8538 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008539 if (numOfSims == 1) {
8540 enforceModifyPermission();
8541 } else {
8542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8543 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8544 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008545 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008546
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008547 try {
Michele30b57b22019-03-01 12:01:14 -08008548 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008549 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008550 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8551 return;
8552 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008553 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
8557 }
8558
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008559 @Override
8560 public boolean isApplicationOnUicc(int subId, int appType) {
8561 enforceReadPrivilegedPermission("isApplicationOnUicc");
8562 Phone phone = getPhone(subId);
8563 if (phone == null) {
8564 return false;
8565 }
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 UiccCard uiccCard = phone.getUiccCard();
8569 if (uiccCard == null) {
8570 return false;
8571 }
8572 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8573 if (uiccProfile == null) {
8574 return false;
8575 }
8576 if (TelephonyManager.APPTYPE_SIM <= appType
8577 && appType <= TelephonyManager.APPTYPE_ISIM) {
8578 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8579 }
8580 return false;
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
8585
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008586 /**
chen xub4baa772019-04-03 10:23:41 -07008587 * Get whether making changes to modem configurations will trigger reboot.
8588 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008589 */
8590 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008591 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8592 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008594 mApp, subId, callingPackage, callingFeatureId,
8595 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008596 return false;
8597 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
8604 }
8605
Nathan Harold29f5f052019-02-15 13:41:57 -08008606 private void updateModemStateMetrics() {
8607 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8608 // TODO: check the state for each modem if the api is ready.
8609 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8610 }
8611
Pengquan Meng3889a572019-01-23 11:16:29 -08008612 @Override
8613 public int[] getSlotsMapping() {
8614 enforceReadPrivilegedPermission("getSlotsMapping");
8615
8616 final long identity = Binder.clearCallingIdentity();
8617 try {
8618 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8619 // All logical slots should have a mapping to a physical slot.
8620 int[] logicalSlotsMapping = new int[phoneCount];
8621 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8622 for (int i = 0; i < slotInfos.length; i++) {
8623 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8624 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8625 }
8626 }
8627 return logicalSlotsMapping;
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
8631 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008632
8633 /**
8634 * Get the IRadio HAL Version
8635 */
8636 @Override
8637 public int getRadioHalVersion() {
8638 Phone phone = getDefaultPhone();
8639 if (phone == null) return -1;
8640 HalVersion hv = phone.getHalVersion();
8641 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8642 return hv.major * 100 + hv.minor;
8643 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008644
8645 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008646 * Get the current calling package name.
8647 * @return the current calling package name
8648 */
8649 @Override
8650 public String getCurrentPackageName() {
8651 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8652 }
8653
8654 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008655 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8656 * corresponding network requests on a subId.
8657 *
8658 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008659 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008660 * 2) APN is un-metered for this subscription, or
8661 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008662 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008663 *
8664 * @return whether data is allowed for a apn type.
8665 *
8666 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008667 */
8668 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008669 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008670 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8671 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008672
8673 // Now that all security checks passes, perform the operation as ourselves.
8674 final long identity = Binder.clearCallingIdentity();
8675 try {
8676 Phone phone = getPhone(subId);
8677 if (phone == null) return false;
8678
Jack Yu41407ee2019-05-13 16:54:09 -07008679 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008680 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
8684 }
8685
8686 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008687 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008688 enforceReadPrivilegedPermission("isApnMetered");
8689
8690 // Now that all security checks passes, perform the operation as ourselves.
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
8693 Phone phone = getPhone(subId);
8694 if (phone == null) return true; // By default return true.
8695
Jack Yu41407ee2019-05-13 16:54:09 -07008696 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008701
8702 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008703 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8704 int subscriptionId, IBooleanConsumer resultCallback) {
8705 enforceModifyPermission();
8706 long token = Binder.clearCallingIdentity();
8707 try {
8708 Phone phone = getPhone(subscriptionId);
8709 if (phone == null) {
8710 try {
8711 if (resultCallback != null) {
8712 resultCallback.accept(false);
8713 }
8714 } catch (RemoteException e) {
8715 // ignore
8716 }
8717 return;
8718 }
8719 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8720 Pair.create(specifiers, (x) -> {
8721 try {
8722 if (resultCallback != null) {
8723 resultCallback.accept(x);
8724 }
8725 } catch (RemoteException e) {
8726 // ignore
8727 }
8728 });
8729 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8730 } finally {
8731 Binder.restoreCallingIdentity(token);
8732 }
8733 }
8734
8735 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008736 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8737 TelephonyPermissions
8738 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8739 mApp, subId, "getSystemSelectionChannels");
8740 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8741 final long identity = Binder.clearCallingIdentity();
8742 try {
8743 List<RadioAccessSpecifier> specifiers =
8744 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8745 null, subId, workSource);
8746 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8747 return specifiers;
8748 } finally {
8749 Binder.restoreCallingIdentity(identity);
8750 }
8751 }
8752
8753 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008754 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008755 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008756 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8757 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8758 if (iccRecords == null) {
8759 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8760 return false;
8761 }
8762 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8763 }
8764
8765 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008766 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8767 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008768 if (callingPackage == null) {
8769 callingPackage = getCurrentPackageName();
8770 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008771 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8772 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008773 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8774 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008775 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8776 }
8777 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8778 Intent intent = new Intent();
8779 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8780 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8781 // Bring up choose default SMS subscription dialog right now
8782 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8783 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8784 mApp.startActivity(intent);
8785 }
chen xud5ca2d52019-05-28 15:20:57 -07008786
8787 @Override
8788 public String getMmsUAProfUrl(int subId) {
8789 //TODO investigate if this API should require proper permission check in R b/133791609
8790 final long identity = Binder.clearCallingIdentity();
8791 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008792 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8793 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8794 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8795 return carrierUAProfUrl;
8796 }
chen xud5ca2d52019-05-28 15:20:57 -07008797 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8798 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
8804 @Override
8805 public String getMmsUserAgent(int subId) {
8806 //TODO investigate if this API should require proper permission check in R b/133791609
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008809 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8810 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8811 if (!TextUtils.isEmpty(carrierUserAgent)) {
8812 return carrierUserAgent;
8813 }
chen xud5ca2d52019-05-28 15:20:57 -07008814 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8815 .getString(com.android.internal.R.string.config_mms_user_agent);
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
Jack Yub07d4972019-05-28 16:12:25 -07008820
8821 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008822 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8823 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8824
8825 final long identity = Binder.clearCallingIdentity();
8826 try {
8827 Phone phone = getPhone(subscriptionId);
8828 if (phone == null) return false;
8829
8830 switch (policy) {
8831 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8832 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8833 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8834 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8835 default:
8836 throw new IllegalArgumentException(policy + " is not a valid policy");
8837 }
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
8843 @Override
8844 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8845 boolean enabled) {
8846 enforceModifyPermission();
8847
8848 final long identity = Binder.clearCallingIdentity();
8849 try {
8850 Phone phone = getPhone(subscriptionId);
8851 if (phone == null) return;
8852
8853 switch (policy) {
8854 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8855 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8856 break;
8857 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8858 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8859 break;
8860 default:
8861 throw new IllegalArgumentException(policy + " is not a valid policy");
8862 }
8863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
8866 }
8867
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008868 /**
Hall Liub48cf452020-09-25 11:13:49 -07008869 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008870 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8871 * otherwise.
8872 */
8873 @Override
8874 public void setCepEnabled(boolean isCepEnabled) {
8875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8880 for (Phone phone : PhoneFactory.getPhones()) {
8881 Phone defaultPhone = phone.getImsPhone();
8882 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8883 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8884 ImsPhoneCallTracker imsPhoneCallTracker =
8885 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8886 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8887 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8888 + imsPhone.getMsisdn());
8889 }
8890 }
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
8894 }
allenwtsu46dcc572020-01-08 18:24:03 +08008895
8896 /**
8897 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8898 *
8899 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8900 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8901 * before being read.
8902 */
8903 @Override
8904 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8905 isCompressed) {
8906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8907 mApp, subId, "notifyRcsAutoConfigurationReceived");
8908 try {
8909 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8910 if (configBinder == null) {
8911 Rlog.e(LOG_TAG, "null result for getImsConfig");
8912 } else {
8913 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8914 }
8915 } catch (RemoteException e) {
8916 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8917 }
8918 }
zoey chenf95ca592019-12-30 16:11:23 +08008919
8920 @Override
8921 public boolean isIccLockEnabled(int subId) {
8922 enforceReadPrivilegedPermission("isIccLockEnabled");
8923
8924 // Now that all security checks passes, perform the operation as ourselves.
8925 final long identity = Binder.clearCallingIdentity();
8926 try {
8927 Phone phone = getPhone(subId);
8928 if (phone != null && phone.getIccCard() != null) {
8929 return phone.getIccCard().getIccLockEnabled();
8930 } else {
8931 return false;
8932 }
8933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
8937
8938 /**
zoey chene02881a2019-12-30 16:11:23 +08008939 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008940 *
zoey chene02881a2019-12-30 16:11:23 +08008941 * @return an integer representing the status of IccLock enabled or disabled in the following
8942 * three cases:
8943 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8944 * successfully.
8945 * - Positive number and zero for remaining password attempts.
8946 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008947 *
8948 */
8949 @Override
8950 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8951 enforceModifyPermission();
8952
8953 Phone phone = getPhone(subId);
8954 if (phone == null) {
8955 return 0;
8956 }
8957 // Now that all security checks passes, perform the operation as ourselves.
8958 final long identity = Binder.clearCallingIdentity();
8959 try {
8960 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8961 new Pair<Boolean, String>(enabled, password), phone, null);
8962 return attemptsRemaining;
8963
8964 } catch (Exception e) {
8965 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 return 0;
8970 }
8971
8972 /**
8973 * Change the ICC password used in ICC pin lock.
8974 *
zoey chene02881a2019-12-30 16:11:23 +08008975 * @return an integer representing the status of IccLock changed in the following three cases:
8976 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8977 * - Positive number and zero for remaining password attempts.
8978 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008979 *
8980 */
8981 @Override
8982 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8983 enforceModifyPermission();
8984
8985 Phone phone = getPhone(subId);
8986 if (phone == null) {
8987 return 0;
8988 }
8989 // Now that all security checks passes, perform the operation as ourselves.
8990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8993 new Pair<String, String>(oldPassword, newPassword), phone, null);
8994 return attemptsRemaining;
8995
8996 } catch (Exception e) {
8997 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 return 0;
9002 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009003
Peter Wangdafb9ac2020-01-15 14:13:38 -08009004 /**
9005 * Request for receiving user activity notification
9006 */
9007 @Override
9008 public void requestUserActivityNotification() {
9009 if (!mNotifyUserActivity.get()
9010 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9011 mNotifyUserActivity.set(true);
9012 }
9013 }
9014
9015 /**
9016 * Called when userActivity is signalled in the power manager.
9017 * This is safe to call from any thread, with any window manager locks held or not.
9018 */
9019 @Override
9020 public void userActivity() {
9021 // ***************************************
9022 // * Inherited from PhoneWindowManager *
9023 // ***************************************
9024 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9025 // WITH ITS LOCKS HELD.
9026 //
9027 // This code must be VERY careful about the locks
9028 // it acquires.
9029 // In fact, the current code acquires way too many,
9030 // and probably has lurking deadlocks.
9031
9032 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9033 throw new SecurityException("Only the OS may call notifyUserActivity()");
9034 }
9035
9036 if (mNotifyUserActivity.getAndSet(false)) {
9037 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9038 USER_ACTIVITY_NOTIFICATION_DELAY);
9039 }
9040 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009041
Malcolm Chen884180b2020-04-13 11:59:40 -07009042 @Override
9043 public boolean canConnectTo5GInDsdsMode() {
9044 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9045 }
Jack Yud10cdd42020-09-28 20:28:01 -07009046
9047 @Override
9048 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9049 String callingFeatureId) {
9050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9051 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9052 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9053 }
9054
9055 Phone phone = getPhone(subId);
9056 if (phone == null) {
9057 throw new RuntimeException("phone is not available");
9058 }
9059 // Now that all security checks passes, perform the operation as ourselves.
9060 final long identity = Binder.clearCallingIdentity();
9061 try {
9062 return phone.getEquivalentHomePlmns();
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009067}