blob: ed4372ef812a53f8f64d099803a2dd73cfbd73e5 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700133import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700174import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700292 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
293 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
294 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
295 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800297 // Parameters of select command.
298 private static final int SELECT_COMMAND = 0xA4;
299 private static final int SELECT_P1 = 0x04;
300 private static final int SELECT_P2 = 0;
301 private static final int SELECT_P3 = 0x10;
302
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 /** The singleton instance. */
304 private static PhoneInterfaceManager sInstance;
305
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800308 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700309 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private AppOpsManager mAppOps;
311 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800312 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800313 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700314 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Peter Wangdafb9ac2020-01-15 14:13:38 -0800316 /** User Activity */
317 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800318 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
319
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700320 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
321
Derek Tan97ebb422014-09-05 16:55:38 -0700322 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
323 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800324 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800325 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700326
Michelecea4cf22018-12-21 15:00:11 -0800327 // String to store multi SIM allowed
328 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
329
Derek Tan740e1672017-06-27 14:56:27 -0700330 // The AID of ISD-R.
331 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
332
yinxub1bed742017-04-17 11:45:04 -0700333 private NetworkScanRequestTracker mNetworkScanRequestTracker;
334
David Kelly5e06a7f2018-03-12 14:10:59 +0000335 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
336 private static final int MANUFACTURER_CODE_LENGTH = 8;
337
Derek Tan89e89d42014-07-08 17:00:10 -0700338 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700339 * Experiment flag to enable erase modem config on reset network, default value is false
340 */
341 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
342 "reset_network_erase_modem_config_enabled";
343
344 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700345 * A request object to use for transmitting data to an ICC.
346 */
347 private static final class IccAPDUArgument {
348 public int channel, cla, command, p1, p2, p3;
349 public String data;
350
351 public IccAPDUArgument(int channel, int cla, int command,
352 int p1, int p2, int p3, String data) {
353 this.channel = channel;
354 this.cla = cla;
355 this.command = command;
356 this.p1 = p1;
357 this.p2 = p2;
358 this.p3 = p3;
359 this.data = data;
360 }
361 }
362
363 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700364 * A request object to use for transmitting data to an ICC.
365 */
366 private static final class ManualNetworkSelectionArgument {
367 public OperatorInfo operatorInfo;
368 public boolean persistSelection;
369
370 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
371 this.operatorInfo = operatorInfo;
372 this.persistSelection = persistSelection;
373 }
374 }
375
376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
378 * request after sending. The main thread will notify the request when it is complete.
379 */
380 private static final class MainThreadRequest {
381 /** The argument to use for the request */
382 public Object argument;
383 /** The result of the request that is run on the main thread */
384 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800385 // The subscriber id that this request applies to. Defaults to
386 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
387 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Nathan Harold92bed182018-10-12 18:16:49 -0700389 // In cases where subId is unavailable, the caller needs to specify the phone.
390 public Phone phone;
391
vagdeviaf9a5b92018-08-15 16:01:53 -0700392 public WorkSource workSource;
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 public MainThreadRequest(Object argument) {
395 this.argument = argument;
396 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397
Nathan Harold92bed182018-10-12 18:16:49 -0700398 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
399 this.argument = argument;
400 if (phone != null) {
401 this.phone = phone;
402 }
403 this.workSource = workSource;
404 }
405
vagdeviaf9a5b92018-08-15 16:01:53 -0700406 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800407 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800408 if (subId != null) {
409 this.subId = subId;
410 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700411 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 }
414
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800415 private static final class IncomingThirdPartyCallArgs {
416 public final ComponentName component;
417 public final String callId;
418 public final String callerDisplayName;
419
420 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
421 String callerDisplayName) {
422 this.component = component;
423 this.callId = callId;
424 this.callerDisplayName = callerDisplayName;
425 }
426 }
427
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 /**
429 * A handler that processes messages on the main thread in the phone process. Since many
430 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
431 * inbound binder threads to the main thread in the phone process. The Binder thread
432 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
433 * on, which will be notified when the operation completes and will contain the result of the
434 * request.
435 *
436 * <p>If a MainThreadRequest object is provided in the msg.obj field,
437 * note that request.result must be set to something non-null for the calling thread to
438 * unblock.
439 */
440 private final class MainThreadHandler extends Handler {
441 @Override
442 public void handleMessage(Message msg) {
443 MainThreadRequest request;
444 Message onCompleted;
445 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800446 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800448 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
450 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 case CMD_HANDLE_USSD_REQUEST: {
452 request = (MainThreadRequest) msg.obj;
453 final Phone phone = getPhoneFromRequest(request);
454 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
455 String ussdRequest = ussdObject.first;
456 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700457
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 if (!isUssdApiAllowed(request.subId)) {
459 // Carrier does not support use of this API, return failure.
460 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
461 UssdResponse response = new UssdResponse(ussdRequest, null);
462 Bundle returnData = new Bundle();
463 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
464 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700465
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 request.result = true;
467 notifyRequester(request);
468 return;
469 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700470
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 try {
472 request.result = phone != null
473 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
474 } catch (CallStateException cse) {
475 request.result = false;
476 }
477 // Wake up the requesting thread
478 notifyRequester(request);
479 break;
pkanwar32d516d2016-10-14 19:37:38 -0700480 }
481
Yorke Lee716f67e2015-06-17 15:39:16 -0700482 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 final Phone phone = getPhoneFromRequest(request);
485 request.result = phone != null ?
486 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
487 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 if (uiccCard == null) {
498 loge("iccTransmitApduLogicalChannel: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
503 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 iccArgument.channel, iccArgument.cla, iccArgument.command,
506 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 break;
510
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 ar = (AsyncResult) msg.obj;
513 request = (MainThreadRequest) ar.userObj;
514 if (ar.exception == null && ar.result != null) {
515 request.result = ar.result;
516 } else {
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
518 if (ar.result == null) {
519 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800520 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800522 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 } else {
524 loge("iccTransmitApduLogicalChannel: Unknown exception");
525 }
526 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 break;
529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
531 request = (MainThreadRequest) msg.obj;
532 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 if (uiccCard == null) {
535 loge("iccTransmitApduBasicChannel: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 } else {
539 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
540 request);
541 uiccCard.iccTransmitApduBasicChannel(
542 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
543 iccArgument.p3, iccArgument.data, onCompleted);
544 }
545 break;
546
547 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
552 } else {
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("iccTransmitApduBasicChannel: Empty response");
556 } else if (ar.exception instanceof CommandException) {
557 loge("iccTransmitApduBasicChannel: CommandException: " +
558 ar.exception);
559 } else {
560 loge("iccTransmitApduBasicChannel: Unknown exception");
561 }
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 break;
565
566 case CMD_EXCHANGE_SIM_IO:
567 request = (MainThreadRequest) msg.obj;
568 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (uiccCard == null) {
571 loge("iccExchangeSimIO: No UICC");
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
576 request);
577 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
578 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
579 iccArgument.data, onCompleted);
580 }
581 break;
582
583 case EVENT_EXCHANGE_SIM_IO_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result;
588 } else {
589 request.result = new IccIoResult(0x6f, 0, (byte[])null);
590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 break;
593
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 case CMD_SEND_ENVELOPE:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("sendEnvelopeWithStatus: No UICC");
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
603 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
604 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 break;
606
607 case EVENT_SEND_ENVELOPE_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("sendEnvelopeWithStatus: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("sendEnvelopeWithStatus: CommandException: " +
618 ar.exception);
619 } else {
620 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
621 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800624 break;
625
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 case CMD_OPEN_CHANNEL:
627 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800628 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800629 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800632 request.result = new IccOpenLogicalChannelResponse(-1,
633 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800637 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
638 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case EVENT_OPEN_CHANNEL_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 int[] result = (int[]) ar.result;
648 int channelId = result[0];
649 byte[] selectResponse = null;
650 if (result.length > 1) {
651 selectResponse = new byte[result.length - 1];
652 for (int i = 1; i < result.length; ++i) {
653 selectResponse[i - 1] = (byte) result[i];
654 }
655 }
656 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700657 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 if (ar.result == null) {
660 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 if (ar.exception != null) {
663 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
664 }
665
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700667 if (ar.exception instanceof CommandException) {
668 CommandException.Error error =
669 ((CommandException) (ar.exception)).getCommandError();
670 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700671 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700672 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700673 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 }
675 }
676 openChannelResp = new IccOpenLogicalChannelResponse(
677 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700679 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
683 case CMD_CLOSE_CHANNEL:
684 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800685 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900688 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 } else {
691 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
692 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
696 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800697 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
698 break;
699
700 case CMD_NV_READ_ITEM:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800703 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
704 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
707 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 ar = (AsyncResult) msg.obj;
709 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800710 if (ar.exception == null && ar.result != null) {
711 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 request.result = "";
714 if (ar.result == null) {
715 loge("nvReadItem: Empty response");
716 } else if (ar.exception instanceof CommandException) {
717 loge("nvReadItem: CommandException: " +
718 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800720 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
722 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
Jake Hambye994d462014-02-03 13:10:13 -0800726 case CMD_NV_WRITE_ITEM:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
729 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800730 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700731 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800732 break;
733
734 case EVENT_NV_WRITE_ITEM_DONE:
735 handleNullReturnEvent(msg, "nvWriteItem");
736 break;
737
738 case CMD_NV_WRITE_CDMA_PRL:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800741 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
744 case EVENT_NV_WRITE_CDMA_PRL_DONE:
745 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800749 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700750 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
chen xu6dac5ab2018-10-26 17:39:23 -0700754 case EVENT_RESET_MODEM_CONFIG_DONE:
755 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800756 break;
757
Sooraj Sasindran37444802020-08-11 10:40:43 -0700758 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
761 request);
762 Phone phone = getPhoneFromRequest(request);
763 if (phone != null) {
764 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
765 } else {
766 loge("isNRDualConnectivityEnabled: No phone object");
767 request.result = false;
768 notifyRequester(request);
769 }
770 break;
771 }
772
773 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
774 ar = (AsyncResult) msg.obj;
775 request = (MainThreadRequest) ar.userObj;
776 if (ar.exception == null && ar.result != null) {
777 request.result = ar.result;
778 } else {
779 // request.result must be set to something non-null
780 // for the calling thread to unblock
781 if (request.result != null) {
782 request.result = ar.result;
783 } else {
784 request.result = false;
785 }
786 if (ar.result == null) {
787 loge("isNRDualConnectivityEnabled: Empty response");
788 } else if (ar.exception instanceof CommandException) {
789 loge("isNRDualConnectivityEnabled: CommandException: "
790 + ar.exception);
791 } else {
792 loge("isNRDualConnectivityEnabled: Unknown exception");
793 }
794 }
795 notifyRequester(request);
796 break;
797
798 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
801 Phone phone = getPhoneFromRequest(request);
802 if (phone != null) {
803 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
804 request.workSource);
805 } else {
806 loge("enableNrDualConnectivity: No phone object");
807 request.result =
808 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
809 notifyRequester(request);
810 }
811 break;
812 }
813
814 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null) {
818 request.result =
819 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
820 } else {
821 request.result =
822 TelephonyManager
823 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
824 if (ar.exception instanceof CommandException) {
825 CommandException.Error error =
826 ((CommandException) (ar.exception)).getCommandError();
827 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
828 request.result =
829 TelephonyManager
830 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
831 }
832 loge("enableNrDualConnectivity" + ": CommandException: "
833 + ar.exception);
834 } else {
835 loge("enableNrDualConnectivity" + ": Unknown exception");
836 }
837 }
838 notifyRequester(request);
839 break;
840 }
841
Jake Hamby7c27be32014-03-03 13:25:59 -0800842 case CMD_GET_PREFERRED_NETWORK_TYPE:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700845 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800846 break;
847
848 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result; // Integer
853 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530854 // request.result must be set to something non-null
855 // for the calling thread to unblock
856 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800857 if (ar.result == null) {
858 loge("getPreferredNetworkType: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("getPreferredNetworkType: CommandException: " +
861 ar.exception);
862 } else {
863 loge("getPreferredNetworkType: Unknown exception");
864 }
865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800867 break;
868
869 case CMD_SET_PREFERRED_NETWORK_TYPE:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
872 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700873 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800874 break;
875
876 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
877 handleNullReturnEvent(msg, "setPreferredNetworkType");
878 break;
879
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000880 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
881 request = (MainThreadRequest)msg.obj;
882 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800883 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000884 break;
885
886 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
887 ar = (AsyncResult)msg.obj;
888 request = (MainThreadRequest)ar.userObj;
889 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700890 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000891 break;
892
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800893 case CMD_SET_VOICEMAIL_NUMBER:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
896 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800897 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
898 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800899 break;
900
901 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
902 handleNullReturnEvent(msg, "setVoicemailNumber");
903 break;
904
Stuart Scott54788802015-03-30 13:18:01 -0700905 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
908 request);
909 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
910 break;
911
912 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
913 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
914 break;
915
Shishir Agrawal302c8692015-06-19 13:49:39 -0700916 case CMD_PERFORM_NETWORK_SCAN:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
919 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
920 break;
921
Hall Liu27d24262020-09-18 19:04:59 -0700922 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700925 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
926 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
927 request.argument;
928 int callForwardingReason = args.first;
929 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800930 break;
Hall Liu27d24262020-09-18 19:04:59 -0700931 }
932 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700935 TelephonyManager.CallForwardingInfoCallback callback =
936 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
937 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800938 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700939 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800940 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
941 for (CallForwardInfo callForwardInfo : callForwardInfos) {
942 // Service Class is a bit mask per 3gpp 27.007. Search for
943 // any service for voice call.
944 if ((callForwardInfo.serviceClass
945 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700946 callForwardingInfo = new CallForwardingInfo(true,
947 callForwardInfo.reason,
948 callForwardInfo.number,
949 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800950 break;
951 }
952 }
953 // Didn't find a call forward info for voice call.
954 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700955 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
956 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800957 }
Hall Liu27d24262020-09-18 19:04:59 -0700958 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800959 } else {
960 if (ar.result == null) {
961 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
962 }
963 if (ar.exception != null) {
964 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
965 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700966 int errorCode = TelephonyManager
967 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800968 if (ar.exception instanceof CommandException) {
969 CommandException.Error error =
970 ((CommandException) (ar.exception)).getCommandError();
971 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700972 errorCode = TelephonyManager
973 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700975 errorCode = TelephonyManager
976 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800977 }
978 }
Hall Liu27d24262020-09-18 19:04:59 -0700979 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800980 }
Shuo Qian4a594052020-01-23 11:59:30 -0800981 break;
Hall Liu27d24262020-09-18 19:04:59 -0700982 }
Shuo Qian4a594052020-01-23 11:59:30 -0800983
Hall Liu27d24262020-09-18 19:04:59 -0700984 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700987 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800988 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700989 ((Pair<CallForwardingInfo, Consumer<Integer>>)
990 request.argument).first;
991 request.phone.setCallForwardingOption(
992 callForwardingInfoToSet.isEnabled()
993 ? CommandsInterface.CF_ACTION_ENABLE
994 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800995 callForwardingInfoToSet.getReason(),
996 callForwardingInfoToSet.getNumber(),
997 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
998 break;
Hall Liu27d24262020-09-18 19:04:59 -0700999 }
Shuo Qian4a594052020-01-23 11:59:30 -08001000
Hall Liu27d24262020-09-18 19:04:59 -07001001 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001004 Consumer<Integer> callback =
1005 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1006 request.argument).second;
1007 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001008 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001009 int errorCode = TelephonyManager.CallForwardingInfoCallback
1010 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001011 if (ar.exception instanceof CommandException) {
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
1014 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager.CallForwardingInfoCallback
1016 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager.CallForwardingInfoCallback
1019 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001020 }
1021 }
1022 callback.accept(errorCode);
1023 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001024 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 }
Shuo Qian4a594052020-01-23 11:59:30 -08001026 break;
Hall Liu27d24262020-09-18 19:04:59 -07001027 }
Shuo Qian4a594052020-01-23 11:59:30 -08001028
Hall Liu27d24262020-09-18 19:04:59 -07001029 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1032 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1033 break;
Hall Liu27d24262020-09-18 19:04:59 -07001034 }
Shuo Qian4a594052020-01-23 11:59:30 -08001035
Hall Liu27d24262020-09-18 19:04:59 -07001036 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001039 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1041 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001042 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001043 // Service Class is a bit mask per 3gpp 27.007.
1044 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001045 if (callForwardResults.length > 1
1046 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001047 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001048 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001049 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1050 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001051 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001052 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001053 }
1054 } else {
1055 if (ar.result == null) {
1056 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1057 }
1058 if (ar.exception != null) {
1059 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1060 }
1061 if (ar.exception instanceof CommandException) {
1062 CommandException.Error error =
1063 ((CommandException) (ar.exception)).getCommandError();
1064 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1065 callForwardingStatus =
1066 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1067 }
1068 }
1069 }
Hall Liu27d24262020-09-18 19:04:59 -07001070 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001071 break;
Hall Liu27d24262020-09-18 19:04:59 -07001072 }
Shuo Qian4a594052020-01-23 11:59:30 -08001073
Hall Liu27d24262020-09-18 19:04:59 -07001074 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001077 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1078 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001079 break;
Hall Liu27d24262020-09-18 19:04:59 -07001080 }
Shuo Qian4a594052020-01-23 11:59:30 -08001081
Hall Liu27d24262020-09-18 19:04:59 -07001082 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001085 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1086 Consumer<Integer> callback =
1087 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1088 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001089 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001090 if (ar.exception instanceof CommandException) {
1091 CommandException.Error error =
1092 ((CommandException) (ar.exception)).getCommandError();
1093 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1095 } else {
1096 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1097 }
1098 } else {
1099 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1100 }
1101 } else {
1102 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1103 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 }
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
Hall Liu27d24262020-09-18 19:04:59 -07001106 }
Shuo Qian4a594052020-01-23 11:59:30 -08001107
Shishir Agrawal302c8692015-06-19 13:49:39 -07001108 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 CellNetworkScanResult cellScanResult;
1112 if (ar.exception == null && ar.result != null) {
1113 cellScanResult = new CellNetworkScanResult(
1114 CellNetworkScanResult.STATUS_SUCCESS,
1115 (List<OperatorInfo>) ar.result);
1116 } else {
1117 if (ar.result == null) {
1118 loge("getCellNetworkScanResults: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1122 }
1123 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1128 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1129 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1130 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1131 }
1132 }
1133 cellScanResult = new CellNetworkScanResult(errorCode, null);
1134 }
1135 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001136 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001137 break;
1138
1139 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1140 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001141 ManualNetworkSelectionArgument selArg =
1142 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001143 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1144 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001145 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1146 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 break;
1148
1149 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 if (ar.exception == null) {
1153 request.result = true;
1154 } else {
1155 request.result = false;
1156 loge("setNetworkSelectionModeManual " + ar.exception);
1157 }
1158 notifyRequester(request);
1159 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 break;
1161
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001162 case CMD_GET_MODEM_ACTIVITY_INFO:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001165 if (defaultPhone != null) {
1166 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001167 } else {
1168 ResultReceiver result = (ResultReceiver) request.argument;
1169 Bundle bundle = new Bundle();
1170 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001171 new ModemActivityInfo(0, 0, 0,
1172 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001173 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001174 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001175 break;
1176
Hall Liud0f208c2020-10-14 16:54:44 -07001177 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001180 ResultReceiver result = (ResultReceiver) request.argument;
1181
Hall Liud0f208c2020-10-14 16:54:44 -07001182 ModemActivityInfo ret = null;
1183 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001184 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001185 // Update the last modem activity info and the result of the request.
1186 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1187 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001188 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001189 int[] txTimeMs = info.getTransmitTimeMillis();
1190 int[] lastModemTxTimeMs = mLastModemActivityInfo
1191 .getTransmitTimeMillis();
1192 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1193 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1194 }
Hall Liu49656c02020-10-09 19:00:11 -07001195 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001196 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1197 + mLastModemActivityInfo.getSleepTimeMillis());
1198 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1199 + mLastModemActivityInfo.getIdleTimeMillis());
1200 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1201 mLastModemActivityInfo.setReceiveTimeMillis(
1202 info.getReceiveTimeMillis()
1203 + mLastModemActivityInfo.getReceiveTimeMillis());
1204 }
Hall Liu49656c02020-10-09 19:00:11 -07001205 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001206 mLastModemActivityInfo.getSleepTimeMillis(),
1207 mLastModemActivityInfo.getIdleTimeMillis(),
1208 mLastModemActivityInfo.getTransmitTimeMillis(),
1209 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001210 } else {
1211 if (ar.result == null) {
1212 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001213 error = TelephonyManager.ModemActivityInfoException
1214 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 } else if (ar.exception instanceof CommandException) {
1216 loge("queryModemActivityInfo: CommandException: " +
1217 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001218 error = TelephonyManager.ModemActivityInfoException
1219 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 } else {
1221 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001222 error = TelephonyManager.ModemActivityInfoException
1223 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 }
1225 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001226 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001227 if (ret != null) {
1228 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1229 } else {
1230 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1231 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001233 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001235 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236
Meng Wang1a7c35a2016-05-05 20:56:15 -07001237 case CMD_SET_ALLOWED_CARRIERS:
1238 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001239 CarrierRestrictionRules argument =
1240 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001241 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001242 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001243 break;
1244
1245 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1246 ar = (AsyncResult) msg.obj;
1247 request = (MainThreadRequest) ar.userObj;
1248 if (ar.exception == null && ar.result != null) {
1249 request.result = ar.result;
1250 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001251 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1252 if (ar.exception instanceof CommandException) {
1253 loge("setAllowedCarriers: CommandException: " + ar.exception);
1254 CommandException.Error error =
1255 ((CommandException) (ar.exception)).getCommandError();
1256 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1257 request.result =
1258 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001260 } else {
1261 loge("setAllowedCarriers: Unknown exception");
1262 }
1263 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001264 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 break;
1266
1267 case CMD_GET_ALLOWED_CARRIERS:
1268 request = (MainThreadRequest) msg.obj;
1269 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001270 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001271 break;
1272
1273 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1274 ar = (AsyncResult) msg.obj;
1275 request = (MainThreadRequest) ar.userObj;
1276 if (ar.exception == null && ar.result != null) {
1277 request.result = ar.result;
1278 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001279 request.result = new IllegalStateException(
1280 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 if (ar.result == null) {
1282 loge("getAllowedCarriers: Empty response");
1283 } else if (ar.exception instanceof CommandException) {
1284 loge("getAllowedCarriers: CommandException: " +
1285 ar.exception);
1286 } else {
1287 loge("getAllowedCarriers: Unknown exception");
1288 }
1289 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 break;
1292
Nathan Haroldb3014052017-01-25 15:57:32 -08001293 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
1296 if (ar.exception == null && ar.result != null) {
1297 request.result = ar.result;
1298 } else {
1299 request.result = new IllegalArgumentException(
1300 "Failed to retrieve Forbidden Plmns");
1301 if (ar.result == null) {
1302 loge("getForbiddenPlmns: Empty response");
1303 } else {
1304 loge("getForbiddenPlmns: Unknown exception");
1305 }
1306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001307 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001308 break;
1309
1310 case CMD_GET_FORBIDDEN_PLMNS:
1311 request = (MainThreadRequest) msg.obj;
1312 uiccCard = getUiccCardFromRequest(request);
1313 if (uiccCard == null) {
1314 loge("getForbiddenPlmns() UiccCard is null");
1315 request.result = new IllegalArgumentException(
1316 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001317 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001318 break;
1319 }
1320 Integer appType = (Integer) request.argument;
1321 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1322 if (uiccApp == null) {
1323 loge("getForbiddenPlmns() no app with specified type -- "
1324 + appType);
1325 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001327 break;
1328 } else {
1329 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1330 + " specified type -- " + appType);
1331 }
1332 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1333 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1334 onCompleted);
1335 break;
1336
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001337 case CMD_SWITCH_SLOTS:
1338 request = (MainThreadRequest) msg.obj;
1339 int[] physicalSlots = (int[]) request.argument;
1340 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1341 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1342 break;
1343
1344 case EVENT_SWITCH_SLOTS_DONE:
1345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
1347 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
1349 break;
1350 case CMD_GET_NETWORK_SELECTION_MODE:
1351 request = (MainThreadRequest) msg.obj;
1352 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1353 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1354 break;
1355
1356 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1357 ar = (AsyncResult) msg.obj;
1358 request = (MainThreadRequest) ar.userObj;
1359 if (ar.exception != null) {
1360 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1361 } else {
1362 int mode = ((int[]) ar.result)[0];
1363 if (mode == 0) {
1364 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1365 } else {
1366 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1367 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001368 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
1370 break;
1371 case CMD_GET_CDMA_ROAMING_MODE:
1372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1374 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1375 break;
1376 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception != null) {
1380 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1381 } else {
1382 request.result = ((int[]) ar.result)[0];
1383 }
1384 notifyRequester(request);
1385 break;
1386 case CMD_SET_CDMA_ROAMING_MODE:
1387 request = (MainThreadRequest) msg.obj;
1388 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1389 int mode = (int) request.argument;
1390 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1391 break;
1392 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 request.result = ar.exception == null;
1396 notifyRequester(request);
1397 break;
1398 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1399 request = (MainThreadRequest) msg.obj;
1400 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1401 int subscriptionMode = (int) request.argument;
1402 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1403 break;
1404 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 request.result = ar.exception == null;
1408 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001409 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001410 case CMD_GET_ALL_CELL_INFO:
1411 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001412 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001413 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001414 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001415 case EVENT_GET_ALL_CELL_INFO_DONE:
1416 ar = (AsyncResult) msg.obj;
1417 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001418 // If a timeout occurs, the response will be null
1419 request.result = (ar.exception == null && ar.result != null)
1420 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001421 synchronized (request) {
1422 request.notifyAll();
1423 }
1424 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001425 case CMD_REQUEST_CELL_INFO_UPDATE:
1426 request = (MainThreadRequest) msg.obj;
1427 request.phone.requestCellInfoUpdate(request.workSource,
1428 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1429 break;
1430 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1431 ar = (AsyncResult) msg.obj;
1432 request = (MainThreadRequest) ar.userObj;
1433 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1434 try {
1435 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001436 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001437 cb.onError(
1438 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1439 ar.exception.getClass().getName(),
1440 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001441 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001442 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001443 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001444 } else {
1445 // use the result as returned
1446 cb.onCellInfo((List<CellInfo>) ar.result);
1447 }
1448 } catch (RemoteException re) {
1449 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1450 }
1451 break;
1452 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 request = (MainThreadRequest) msg.obj;
1454 WorkSource ws = (WorkSource) request.argument;
1455 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001456 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001458 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 if (ar.exception == null) {
1462 request.result = ar.result;
1463 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001464 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001466 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001467 }
1468
1469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001473 case CMD_MODEM_REBOOT:
1474 request = (MainThreadRequest) msg.obj;
1475 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001476 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001477 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001478 case EVENT_CMD_MODEM_REBOOT_DONE:
1479 handleNullReturnEvent(msg, "rebootModem");
1480 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001481 case CMD_REQUEST_ENABLE_MODEM:
1482 request = (MainThreadRequest) msg.obj;
1483 boolean enable = (boolean) request.argument;
1484 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001485 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001486 PhoneConfigurationManager.getInstance()
1487 .enablePhone(request.phone, enable, onCompleted);
1488 break;
1489 case EVENT_ENABLE_MODEM_DONE:
1490 ar = (AsyncResult) msg.obj;
1491 request = (MainThreadRequest) ar.userObj;
1492 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001493 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001494 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001495 if ((boolean) request.result) {
1496 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1497 updateModemStateMetrics();
1498 } else {
1499 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1500 + ar.exception);
1501 }
1502 notifyRequester(request);
1503 break;
1504 case CMD_GET_MODEM_STATUS:
1505 request = (MainThreadRequest) msg.obj;
1506 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1507 PhoneConfigurationManager.getInstance()
1508 .getPhoneStatusFromModem(request.phone, onCompleted);
1509 break;
1510 case EVENT_GET_MODEM_STATUS_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 int id = request.phone.getPhoneId();
1514 if (ar.exception == null && ar.result != null) {
1515 request.result = ar.result;
1516 //update the cache as modem status has changed
1517 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1518 (boolean) request.result);
1519 } else {
1520 // Return true if modem status cannot be retrieved. For most cases,
1521 // modem status is on. And for older version modems, GET_MODEM_STATUS
1522 // and disable modem are not supported. Modem is always on.
1523 // TODO: this should be fixed in R to support a third
1524 // status UNKNOWN b/131631629
1525 request.result = true;
1526 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1527 + ar.exception);
1528 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001529 notifyRequester(request);
1530 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001531 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1532 request = (MainThreadRequest) msg.obj;
1533 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1534 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1535 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1536 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1537 break;
1538 }
1539 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1543 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1544 args.second.accept(ar.exception == null);
1545 notifyRequester(request);
1546 break;
1547 }
yincheng zhao2737e882019-09-06 17:06:54 -07001548 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
1554 request.result = -1;
1555 loge("Failed to set Forbidden Plmns");
1556 if (ar.result == null) {
1557 loge("setForbidenPlmns: Empty response");
1558 } else if (ar.exception != null) {
1559 loge("setForbiddenPlmns: Exception: " + ar.exception);
1560 request.result = -1;
1561 } else {
1562 loge("setForbiddenPlmns: Unknown exception");
1563 }
1564 }
1565 notifyRequester(request);
1566 break;
1567 case CMD_SET_FORBIDDEN_PLMNS:
1568 request = (MainThreadRequest) msg.obj;
1569 uiccCard = getUiccCardFromRequest(request);
1570 if (uiccCard == null) {
1571 loge("setForbiddenPlmns: UiccCard is null");
1572 request.result = -1;
1573 notifyRequester(request);
1574 break;
1575 }
1576 Pair<Integer, List<String>> setFplmnsArgs =
1577 (Pair<Integer, List<String>>) request.argument;
1578 appType = setFplmnsArgs.first;
1579 List<String> fplmns = setFplmnsArgs.second;
1580 uiccApp = uiccCard.getApplicationByType(appType);
1581 if (uiccApp == null) {
1582 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1583 request.result = -1;
1584 loge("Failed to get UICC App");
1585 notifyRequester(request);
1586 } else {
1587 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1588 ((SIMRecords) uiccApp.getIccRecords())
1589 .setForbiddenPlmns(onCompleted, fplmns);
1590 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001591 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001592 case CMD_ERASE_MODEM_CONFIG:
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1595 defaultPhone.eraseModemConfig(onCompleted);
1596 break;
1597 case EVENT_ERASE_MODEM_CONFIG_DONE:
1598 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001599 break;
zoey chene02881a2019-12-30 16:11:23 +08001600
1601 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1602 request = (MainThreadRequest) msg.obj;
1603 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1604 Pair<String, String> changed = (Pair<String, String>) request.argument;
1605 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1606 changed.first, changed.second, onCompleted);
1607 break;
1608 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception == null) {
1612 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1613 } else {
1614 request.result = msg.arg1;
1615 }
1616 notifyRequester(request);
1617 break;
1618
1619 case CMD_SET_ICC_LOCK_ENABLED:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1622 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1623 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1624 enabled.first, enabled.second, onCompleted);
1625 break;
1626 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception == null) {
1630 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1631 } else {
1632 request.result = msg.arg1;
1633 }
1634 notifyRequester(request);
1635 break;
1636
Peter Wangdafb9ac2020-01-15 14:13:38 -08001637 case MSG_NOTIFY_USER_ACTIVITY:
1638 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001639 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001640 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1641 getDefaultPhone().getContext().sendBroadcastAsUser(
1642 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1643 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 default:
1645 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1646 break;
1647 }
1648 }
Jake Hambye994d462014-02-03 13:10:13 -08001649
Pengquan Menga1bb6272018-09-06 09:59:22 -07001650 private void notifyRequester(MainThreadRequest request) {
1651 synchronized (request) {
1652 request.notifyAll();
1653 }
1654 }
1655
Jake Hambye994d462014-02-03 13:10:13 -08001656 private void handleNullReturnEvent(Message msg, String command) {
1657 AsyncResult ar = (AsyncResult) msg.obj;
1658 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1659 if (ar.exception == null) {
1660 request.result = true;
1661 } else {
1662 request.result = false;
1663 if (ar.exception instanceof CommandException) {
1664 loge(command + ": CommandException: " + ar.exception);
1665 } else {
1666 loge(command + ": Unknown exception");
1667 }
1668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
1673 /**
1674 * Posts the specified command to be executed on the main thread,
1675 * waits for the request to complete, and returns the result.
1676 * @see #sendRequestAsync
1677 */
1678 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001679 return sendRequest(
1680 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001681 }
1682
1683 /**
1684 * Posts the specified command to be executed on the main thread,
1685 * waits for the request to complete, and returns the result.
1686 * @see #sendRequestAsync
1687 */
1688 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1689 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001690 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001691 }
1692
1693 /**
1694 * Posts the specified command to be executed on the main thread,
1695 * waits for the request to complete, and returns the result.
1696 * @see #sendRequestAsync
1697 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001698 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001699 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001700 }
1701
1702 /**
1703 * Posts the specified command to be executed on the main thread,
1704 * waits for the request to complete, and returns the result.
1705 * @see #sendRequestAsync
1706 */
Nathan Harold92bed182018-10-12 18:16:49 -07001707 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1708 return sendRequest(command, argument, subId, null, workSource);
1709 }
1710
1711 /**
1712 * Posts the specified command to be executed on the main thread,
1713 * waits for the request to complete, and returns the result.
1714 * @see #sendRequestAsync
1715 */
1716 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1717 return sendRequest(
1718 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1719 }
1720
1721 /**
1722 * Posts the specified command to be executed on the main thread,
1723 * waits for the request to complete, and returns the result.
1724 * @see #sendRequestAsync
1725 */
1726 private Object sendRequest(
1727 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1729 throw new RuntimeException("This method will deadlock if called from the main thread.");
1730 }
1731
Nathan Harold92bed182018-10-12 18:16:49 -07001732 MainThreadRequest request = null;
1733 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1734 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1735 } else if (phone != null) {
1736 request = new MainThreadRequest(argument, phone, workSource);
1737 } else {
1738 request = new MainThreadRequest(argument, subId, workSource);
1739 }
1740
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 Message msg = mMainThreadHandler.obtainMessage(command, request);
1742 msg.sendToTarget();
1743
1744 // Wait for the request to complete
1745 synchronized (request) {
1746 while (request.result == null) {
1747 try {
1748 request.wait();
1749 } catch (InterruptedException e) {
1750 // Do nothing, go back and wait until the request is complete
1751 }
1752 }
1753 }
1754 return request.result;
1755 }
1756
1757 /**
1758 * Asynchronous ("fire and forget") version of sendRequest():
1759 * Posts the specified command to be executed on the main thread, and
1760 * returns immediately.
1761 * @see #sendRequest
1762 */
1763 private void sendRequestAsync(int command) {
1764 mMainThreadHandler.sendEmptyMessage(command);
1765 }
1766
1767 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001768 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001769 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001770 */
1771 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001772 sendRequestAsync(command, argument, null, null);
1773 }
1774
1775 /**
1776 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1777 * @see {@link #sendRequest(int,Object)}
1778 */
1779 private void sendRequestAsync(
1780 int command, Object argument, Phone phone, WorkSource workSource) {
1781 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001782 Message msg = mMainThreadHandler.obtainMessage(command, request);
1783 msg.sendToTarget();
1784 }
1785
1786 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 * Initialize the singleton PhoneInterfaceManager instance.
1788 * This is only done once, at startup, from PhoneApp.onCreate().
1789 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001790 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 synchronized (PhoneInterfaceManager.class) {
1792 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001793 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 } else {
1795 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1796 }
1797 return sInstance;
1798 }
1799 }
1800
1801 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001802 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001805 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001806 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1808 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001809 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001810 mTelephonySharedPreferences =
1811 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001812 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001813 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001814 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 publish();
1817 }
1818
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001819 private Phone getDefaultPhone() {
1820 Phone thePhone = getPhone(getDefaultSubscription());
1821 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1822 }
1823
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 private void publish() {
1825 if (DBG) log("publish: " + this);
1826
Peter Wangc035ce42020-01-08 21:00:22 -08001827 TelephonyFrameworkInitializer
1828 .getTelephonyServiceManager()
1829 .getTelephonyServiceRegisterer()
1830 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Stuart Scott584921c2015-01-15 17:10:34 -08001833 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001834 if (request.phone != null) {
1835 return request.phone;
1836 } else {
1837 return getPhoneFromSubId(request.subId);
1838 }
1839 }
1840
1841 private Phone getPhoneFromSubId(int subId) {
1842 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1843 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001844 }
1845
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001846 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1847 Phone phone = getPhoneFromRequest(request);
1848 return phone == null ? null :
1849 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001853 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001854 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856
Naina Nallurid63128d2019-09-17 14:10:30 -07001857 private void sendEraseModemConfig(Phone phone) {
1858 if (phone != null) {
1859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1860 mApp, phone.getSubId(), "eraseModemConfig");
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1864 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
1868 }
1869 }
1870
Peter Wang44b186e2020-01-13 23:33:09 -08001871 private boolean isImsAvailableOnDevice() {
1872 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1873 if (pm == null) {
1874 // For some reason package manger is not available.. This will fail internally anyway,
1875 // so do not throw error and allow.
1876 return true;
1877 }
1878 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1879 }
1880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001882 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001883 }
1884
Wink Savilleb564aae2014-10-23 10:18:09 -07001885 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 if (DBG) log("dial: " + number);
1887 // No permission check needed here: This is just a wrapper around the
1888 // ACTION_DIAL intent, which is available to any app since it puts up
1889 // the UI before it does anything.
1890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 String url = createTelUrl(number);
1894 if (url == null) {
1895 return;
1896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 // PENDING: should we just silently fail if phone is offhook or ringing?
1899 PhoneConstants.State state = mCM.getState(subId);
1900 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1901 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1902 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1903 mApp.startActivity(intent);
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908 }
1909
1910 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Wink Savilleb564aae2014-10-23 10:18:09 -07001914 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 if (DBG) log("call: " + number);
1916
1917 // This is just a wrapper around the ACTION_CALL intent, but we still
1918 // need to do a permission check since we're calling startActivity()
1919 // from the context of the phone app.
1920 enforceCallPermission();
1921
Jordan Liu1617b712019-07-10 15:06:26 -07001922 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 != AppOpsManager.MODE_ALLOWED) {
1924 return;
1925 }
1926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 String url = createTelUrl(number);
1930 if (url == null) {
1931 return;
1932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 boolean isValid = false;
1935 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1936 if (slist != null) {
1937 for (SubscriptionInfo subInfoRecord : slist) {
1938 if (subInfoRecord.getSubscriptionId() == subId) {
1939 isValid = true;
1940 break;
1941 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001942 }
Wink Saville08874612014-08-31 19:19:58 -07001943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944 if (!isValid) {
1945 return;
1946 }
Wink Saville08874612014-08-31 19:19:58 -07001947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1949 intent.putExtra(SUBSCRIPTION_KEY, subId);
1950 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1951 mApp.startActivity(intent);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Wink Savilleb564aae2014-10-23 10:18:09 -07001957 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001958 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001959 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1960 }
1961
Wink Savilleb564aae2014-10-23 10:18:09 -07001962 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001963 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001964 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1965 }
1966
Wink Savilleb564aae2014-10-23 10:18:09 -07001967 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1973 checkSimPin.start();
1974 return checkSimPin.unlockSim(null, pin);
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
1977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982
1983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1986 checkSimPuk.start();
1987 return checkSimPuk.unlockSim(puk, pin);
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001994 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 * a synchronous one.
1996 */
1997 private static class UnlockSim extends Thread {
1998
1999 private final IccCard mSimCard;
2000
2001 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002002 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2003 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004
2005 // For replies from SimCard interface
2006 private Handler mHandler;
2007
2008 // For async handler to identify request type
2009 private static final int SUPPLY_PIN_COMPLETE = 100;
2010
2011 public UnlockSim(IccCard simCard) {
2012 mSimCard = simCard;
2013 }
2014
2015 @Override
2016 public void run() {
2017 Looper.prepare();
2018 synchronized (UnlockSim.this) {
2019 mHandler = new Handler() {
2020 @Override
2021 public void handleMessage(Message msg) {
2022 AsyncResult ar = (AsyncResult) msg.obj;
2023 switch (msg.what) {
2024 case SUPPLY_PIN_COMPLETE:
2025 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2026 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002027 mRetryCount = msg.arg1;
2028 if (ar.exception != null) {
2029 if (ar.exception instanceof CommandException &&
2030 ((CommandException)(ar.exception)).getCommandError()
2031 == CommandException.Error.PASSWORD_INCORRECT) {
2032 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002033 } //When UiccCardApp dispose,handle message and return exception
2034 else if (ar.exception instanceof CommandException &&
2035 ((CommandException) (ar.exception)).getCommandError()
2036 == CommandException.Error.ABORTED) {
2037 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002038 } else {
2039 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2040 }
2041 } else {
2042 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 mDone = true;
2045 UnlockSim.this.notifyAll();
2046 }
2047 break;
2048 }
2049 }
2050 };
2051 UnlockSim.this.notifyAll();
2052 }
2053 Looper.loop();
2054 }
2055
2056 /*
2057 * Use PIN or PUK to unlock SIM card
2058 *
2059 * If PUK is null, unlock SIM card with PIN
2060 *
2061 * If PUK is not null, unlock SIM card with PUK and set PIN code
2062 */
Wink Saville9de0f752013-10-22 19:04:03 -07002063 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064
2065 while (mHandler == null) {
2066 try {
2067 wait();
2068 } catch (InterruptedException e) {
2069 Thread.currentThread().interrupt();
2070 }
2071 }
2072 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2073
2074 if (puk == null) {
2075 mSimCard.supplyPin(pin, callback);
2076 } else {
2077 mSimCard.supplyPuk(puk, pin, callback);
2078 }
2079
2080 while (!mDone) {
2081 try {
2082 Log.d(LOG_TAG, "wait for done");
2083 wait();
2084 } catch (InterruptedException e) {
2085 // Restore the interrupted status
2086 Thread.currentThread().interrupt();
2087 }
2088 }
2089 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002090 int[] resultArray = new int[2];
2091 resultArray[0] = mResult;
2092 resultArray[1] = mRetryCount;
2093 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095 }
2096
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002097 /**
2098 * This method has been removed due to privacy and stability concerns.
2099 */
2100 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002102 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2103 return;
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
2105
Nathan Harold1f889d82020-06-04 17:05:26 -07002106 @Override
2107 public void updateServiceLocationWithPackageName(String callingPackage) {
2108 mApp.getSystemService(AppOpsManager.class)
2109 .checkPackage(Binder.getCallingUid(), callingPackage);
2110
2111 final int targetSdk = getTargetSdk(callingPackage);
2112 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2113 // Callers targeting S have no business invoking this method.
2114 return;
2115 }
2116
2117 LocationAccessPolicy.LocationPermissionResult locationResult =
2118 LocationAccessPolicy.checkLocationPermission(mApp,
2119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2120 .setCallingPackage(callingPackage)
2121 .setCallingFeatureId(null)
2122 .setCallingPid(Binder.getCallingPid())
2123 .setCallingUid(Binder.getCallingUid())
2124 .setMethod("updateServiceLocation")
2125 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2126 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2127 .build());
2128 // Apps that lack location permission have no business calling this method;
2129 // however, because no permission was declared in the public API, denials must
2130 // all be "soft".
2131 switch (locationResult) {
2132 case DENIED_HARD: /* fall through */
2133 case DENIED_SOFT:
2134 return;
2135 }
2136
2137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 final long identity = Binder.clearCallingIdentity();
2139 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002140 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002142 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002149 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002150 @Override
2151 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002152 return isRadioOnWithFeature(callingPackage, null);
2153 }
2154
2155
2156 @Override
2157 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2158 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2159 callingFeatureId);
2160 }
2161
2162 @Deprecated
2163 @Override
2164 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2165 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002168 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002169 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2170 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002172 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002173 return false;
2174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 return isRadioOnForSubscriber(subId);
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002182 }
2183
2184 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185 final long identity = Binder.clearCallingIdentity();
2186 try {
2187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2190 } else {
2191 return false;
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
2198 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002199 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
Wink Saville36469e72014-06-11 15:17:00 -07002201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 if (phone != null) {
2209 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
2216 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002217 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (phone == null) {
2227 return false;
2228 }
2229 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2230 toggleRadioOnOffForSubscriber(subId);
2231 }
2232 return true;
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
Wink Saville36469e72014-06-11 15:17:00 -07002237
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002238 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002239 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002240 /*
2241 * If any of the Radios are available, it will need to be
2242 * shutdown. So return true if any Radio is available.
2243 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2247 Phone phone = PhoneFactory.getPhone(i);
2248 if (phone != null && phone.isRadioAvailable()) return true;
2249 }
2250 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2251 return false;
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002254 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002255 }
2256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002258 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 enforceModifyPermission();
2260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2264 logv("Shutting down Phone " + i);
2265 shutdownRadioUsingPhoneId(i);
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002269 }
2270 }
2271
2272 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002273 Phone phone = PhoneFactory.getPhone(phoneId);
2274 if (phone != null && phone.isRadioAvailable()) {
2275 phone.shutdownRadio();
2276 }
2277 }
2278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281
2282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2285 if (defaultPhone != null) {
2286 defaultPhone.setRadioPower(turnOn);
2287 return true;
2288 } else {
2289 loge("There's no default phone.");
2290 return false;
2291 }
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002294 }
Wink Saville36469e72014-06-11 15:17:00 -07002295 }
2296
Wink Savilleb564aae2014-10-23 10:18:09 -07002297 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
2303 if (phone != null) {
2304 phone.setRadioPower(turnOn);
2305 return true;
2306 } else {
2307 return false;
2308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Wink Saville36469e72014-06-11 15:17:00 -07002314 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 public boolean enableDataConnectivity() {
2317 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318
2319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 int subId = mSubscriptionController.getDefaultDataSubId();
2322 final Phone phone = getPhone(subId);
2323 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002324 phone.getDataEnabledSettings().setDataEnabled(
2325 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 return true;
2327 } else {
2328 return false;
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
Wink Saville36469e72014-06-11 15:17:00 -07002335 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 public boolean disableDataConnectivity() {
2338 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339
2340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 int subId = mSubscriptionController.getDefaultDataSubId();
2343 final Phone phone = getPhone(subId);
2344 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002345 phone.getDataEnabledSettings().setDataEnabled(
2346 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 return true;
2348 } else {
2349 return false;
2350 }
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002357 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 final Phone phone = getPhone(subId);
2361 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002362 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 } else {
2364 return false;
2365 }
2366 } finally {
2367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
2370
2371 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002372 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002373 }
2374
pkanwarae03a6b2016-11-06 20:37:09 -08002375 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 enforceCallPermission();
2377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2381 return;
2382 }
2383 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2384 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
pkanwar32d516d2016-10-14 19:37:38 -07002388 };
2389
Wink Savilleb564aae2014-10-23 10:18:09 -07002390 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392
2393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2396 return false;
2397 }
2398 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
2403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002405 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002406 }
2407
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002408 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 Phone phone = PhoneFactory.getPhone(slotIndex);
2412 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2413 PhoneConstantConversions.convertCallState(phone.getState());
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418
Sanket Padawe356d7632015-06-22 14:03:32 -07002419 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002420 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002421 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2422 }
2423
2424 @Override
2425 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002428 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 if (phone != null) {
2430 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2431 } else {
2432 return PhoneConstantConversions.convertDataState(
2433 PhoneConstants.DataState.DISCONNECTED);
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002441 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002442 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2443 }
2444
2445 @Override
2446 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 final long identity = Binder.clearCallingIdentity();
2448 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 if (phone != null) {
2451 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2452 } else {
2453 return TelephonyManager.DATA_ACTIVITY_NONE;
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
2460 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002461 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002462 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002463 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002464
2465 LocationAccessPolicy.LocationPermissionResult locationResult =
2466 LocationAccessPolicy.checkLocationPermission(mApp,
2467 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2468 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002469 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002470 .setCallingPid(Binder.getCallingPid())
2471 .setCallingUid(Binder.getCallingUid())
2472 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002473 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002474 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2475 .build());
2476 switch (locationResult) {
2477 case DENIED_HARD:
2478 throw new SecurityException("Not allowed to access cell location");
2479 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002480 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2481 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002488 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002489 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
Svetoslav64fad262015-04-14 14:35:21 -07002493 }
2494
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002496 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002497 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2498 // registered cell info, so return a NULL country instead.
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002501 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2502 // Get default phone in this case.
2503 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2504 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002505 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002507 if (phone == null) return "";
2508 ServiceStateTracker sst = phone.getServiceStateTracker();
2509 if (sst == null) return "";
2510 LocaleTracker lt = sst.getLocaleTracker();
2511 if (lt == null) return "";
2512 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2513 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2514 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002518 }
2519
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002520 /**
2521 * This method was removed due to potential issues caused by performing partial
2522 * updates of service state, and lack of a credible use case.
2523 *
2524 * This has the ability to break the telephony implementation by disabling notification of
2525 * changes in device connectivity. DO NOT USE THIS!
2526 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 public void enableLocationUpdates() {
2529 mApp.enforceCallingOrSelfPermission(
2530 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002533 /**
2534 * This method was removed due to potential issues caused by performing partial
2535 * updates of service state, and lack of a credible use case.
2536 *
2537 * This has the ability to break the telephony implementation by disabling notification of
2538 * changes in device connectivity. DO NOT USE THIS!
2539 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 @Override
2541 public void disableLocationUpdates() {
2542 mApp.enforceCallingOrSelfPermission(
2543 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 }
2545
Nathan Harold31d7ff32018-10-15 20:20:30 -07002546 /**
2547 * Returns the target SDK version number for a given package name.
2548 *
Nathan Haroldec184742019-07-10 17:04:16 -07002549 * This call MUST be invoked before clearing the calling UID.
2550 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002551 * @return target SDK if the package is found or INT_MAX.
2552 */
2553 private int getTargetSdk(String packageName) {
2554 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002555 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002556 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002557 if (ai != null) return ai.targetSdkVersion;
2558 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002559 loge("Failed to get package info for pkg="
2560 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002561 }
2562 return Integer.MAX_VALUE;
2563 }
2564
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 @Override
2566 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002567 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2568 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002569 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002570 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2571 throw new SecurityException(
2572 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2573 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002574
Jordan Liu1617b712019-07-10 15:06:26 -07002575 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2577 return null;
2578 }
Svetoslav64fad262015-04-14 14:35:21 -07002579
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002580 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002582 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002583 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584
Nathan Haroldf180aac2018-06-01 18:43:55 -07002585 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2586 for (CellInfo ci : info) {
2587 if (ci instanceof CellInfoGsm) {
2588 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2589 } else if (ci instanceof CellInfoWcdma) {
2590 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002593 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 }
2595
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002596 private List<CellInfo> getCachedCellInfo() {
2597 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2598 for (Phone phone : PhoneFactory.getPhones()) {
2599 List<CellInfo> info = phone.getAllCellInfo();
2600 if (info != null) cellInfos.addAll(info);
2601 }
2602 return cellInfos;
2603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
2605 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002606 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002607 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002608 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002609
2610 LocationAccessPolicy.LocationPermissionResult locationResult =
2611 LocationAccessPolicy.checkLocationPermission(mApp,
2612 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2613 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002614 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002615 .setCallingPid(Binder.getCallingPid())
2616 .setCallingUid(Binder.getCallingUid())
2617 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002618 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002619 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2620 .build());
2621 switch (locationResult) {
2622 case DENIED_HARD:
2623 throw new SecurityException("Not allowed to access cell info");
2624 case DENIED_SOFT:
2625 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 }
2627
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002628 final int targetSdk = getTargetSdk(callingPackage);
2629 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2630 return getCachedCellInfo();
2631 }
2632
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002633 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2638 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002639 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002640 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 if (info != null) cellInfos.addAll(info);
2642 }
2643 return cellInfos;
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647 }
2648
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002649 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002650 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2651 String callingFeatureId) {
2652 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2653 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002654 }
2655
2656 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002657 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2658 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002659 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002660 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002661 }
2662
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002663 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2664 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002665 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002666 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002667
2668 LocationAccessPolicy.LocationPermissionResult locationResult =
2669 LocationAccessPolicy.checkLocationPermission(mApp,
2670 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2671 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002672 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002673 .setCallingPid(Binder.getCallingPid())
2674 .setCallingUid(Binder.getCallingUid())
2675 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002676 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2677 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002678 .build());
2679 switch (locationResult) {
2680 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002681 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2682 // Safetynet logging for b/154934934
2683 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2684 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002685 throw new SecurityException("Not allowed to access cell info");
2686 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002687 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2688 // Safetynet logging for b/154934934
2689 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2690 }
Nathan Harold5320c422019-05-09 10:26:08 -07002691 try {
2692 cb.onCellInfo(new ArrayList<CellInfo>());
2693 } catch (RemoteException re) {
2694 // Drop without consequences
2695 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002696 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002697 }
2698
Nathan Harolda939a962019-05-09 10:13:47 -07002699
2700 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002701 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2702
2703 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2704 }
2705
2706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002708 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002709 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710
2711 final long identity = Binder.clearCallingIdentity();
2712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002713 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 } finally {
2715 Binder.restoreCallingIdentity(identity);
2716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718
Shishir Agrawala9f32182016-04-12 12:00:16 -07002719 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002720 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002721 Phone phone = PhoneFactory.getPhone(slotIndex);
2722 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002723 return null;
2724 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002725 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002726 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002727 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002728 return null;
2729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 return phone.getImei();
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002737 }
2738
2739 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002740 public String getTypeAllocationCodeForSlot(int slotIndex) {
2741 Phone phone = PhoneFactory.getPhone(slotIndex);
2742 String tac = null;
2743 if (phone != null) {
2744 String imei = phone.getImei();
2745 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2746 }
2747 return tac;
2748 }
2749
2750 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002751 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002752 Phone phone = PhoneFactory.getPhone(slotIndex);
2753 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002754 return null;
2755 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002756
Jeff Davidson913390f2018-02-23 17:11:49 -08002757 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002758 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002759 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002760 return null;
2761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 return phone.getMeid();
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
Jack Yu2af8d712017-03-15 17:14:14 -07002769 }
2770
2771 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002772 public String getManufacturerCodeForSlot(int slotIndex) {
2773 Phone phone = PhoneFactory.getPhone(slotIndex);
2774 String manufacturerCode = null;
2775 if (phone != null) {
2776 String meid = phone.getMeid();
2777 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2778 }
2779 return manufacturerCode;
2780 }
2781
2782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002783 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2784 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002785 Phone phone = PhoneFactory.getPhone(slotIndex);
2786 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 return null;
2788 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002789 int subId = phone.getSubId();
2790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002791 mApp, subId, callingPackage, callingFeatureId,
2792 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002793 return null;
2794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795
2796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 return phone.getDeviceSvn();
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002802 }
2803
fionaxu43304da2017-11-27 22:51:16 -08002804 @Override
2805 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
fionaxu43304da2017-11-27 22:51:16 -08002813 }
2814
2815 @Override
2816 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 return phone == null ? null : phone.getCarrierName();
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
2823 }
fionaxu43304da2017-11-27 22:51:16 -08002824 }
2825
calvinpanffe225e2018-11-01 19:43:06 +08002826 @Override
chen xu0026ca62019-03-06 15:28:50 -08002827 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
2831 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002832 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
2836 }
2837
2838 @Override
chen xu0026ca62019-03-06 15:28:50 -08002839 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002843 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
2847 }
2848
chen xu651eec72018-11-11 19:03:44 -08002849 @Override
chen xu864e11c2018-12-06 22:10:03 -08002850 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2851 if (!isSubscriptionMccMnc) {
2852 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2853 }
chen xu651eec72018-11-11 19:03:44 -08002854 final Phone phone = PhoneFactory.getPhone(slotIndex);
2855 if (phone == null) {
2856 return TelephonyManager.UNKNOWN_CARRIER_ID;
2857 }
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
2863 }
2864 }
2865
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 //
2867 // Internal helper methods.
2868 //
2869
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002870 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2872 *
2873 * @throws SecurityException if the caller does not have the required permission
2874 */
2875 private void enforceModifyPermission() {
2876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2877 }
2878
Shuo Qiancd19c462020-01-16 20:51:11 -08002879 /**
2880 * Make sure the caller is system.
2881 *
2882 * @throws SecurityException if the caller is not system.
2883 */
2884 private void enforceSystemCaller() {
2885 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2886 throw new SecurityException("Caller must be system");
2887 }
2888 }
2889
Shuo Qian3b6ee772019-11-13 17:43:31 -08002890 private void enforceActiveEmergencySessionPermission() {
2891 mApp.enforceCallingOrSelfPermission(
2892 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2893 }
2894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 /**
2896 * Make sure the caller has the CALL_PHONE permission.
2897 *
2898 * @throws SecurityException if the caller does not have the required permission
2899 */
2900 private void enforceCallPermission() {
2901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2902 }
2903
paulhu5a773602019-08-23 19:17:33 +08002904 private void enforceSettingsPermission() {
2905 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002906 }
2907
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 private String createTelUrl(String number) {
2909 if (TextUtils.isEmpty(number)) {
2910 return null;
2911 }
2912
Jake Hambye994d462014-02-03 13:10:13 -08002913 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915
Ihab Awadf9e92732013-12-05 18:02:52 -08002916 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2918 }
2919
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002920 private static void logv(String msg) {
2921 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2922 }
2923
Ihab Awadf9e92732013-12-05 18:02:52 -08002924 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2926 }
2927
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002930 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002934 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 final Phone phone = PhoneFactory.getPhone(slotIndex);
2938 if (phone == null) {
2939 return PhoneConstants.PHONE_TYPE_NONE;
2940 } else {
2941 return phone.getPhoneType();
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947
2948 /**
2949 * Returns the CDMA ERI icon index to display
2950 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002952 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2953 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2954 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002955 }
2956
Sanket Padawe356d7632015-06-22 14:03:32 -07002957 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002958 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2959 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002961 mApp, subId, callingPackage, callingFeatureId,
2962 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002963 return -1;
2964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965
2966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 final Phone phone = getPhone(subId);
2969 if (phone != null) {
2970 return phone.getCdmaEriIconIndex();
2971 } else {
2972 return -1;
2973 }
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
2979 /**
2980 * Returns the CDMA ERI icon mode,
2981 * 0 - ON
2982 * 1 - FLASHING
2983 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002985 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2986 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2987 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002988 }
2989
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002991 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2992 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002994 mApp, subId, callingPackage, callingFeatureId,
2995 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002996 return -1;
2997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 final Phone phone = getPhone(subId);
3002 if (phone != null) {
3003 return phone.getCdmaEriIconMode();
3004 } else {
3005 return -1;
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
3012 /**
3013 * Returns the CDMA ERI text,
3014 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003016 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3017 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3018 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003019 }
3020
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003022 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3023 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003025 mApp, subId, callingPackage, callingFeatureId,
3026 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003027 return null;
3028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 final Phone phone = getPhone(subId);
3033 if (phone != null) {
3034 return phone.getCdmaEriText();
3035 } else {
3036 return null;
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
3043 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003044 * Returns the CDMA MDN.
3045 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003047 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3049 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003054 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 return phone.getLine1Number();
3056 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003057 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 return null;
3059 }
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003062 }
3063 }
3064
3065 /**
3066 * Returns the CDMA MIN.
3067 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003068 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003069 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 final Phone phone = getPhone(subId);
3076 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3077 return phone.getCdmaMin();
3078 } else {
3079 return null;
3080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003083 }
3084 }
3085
Hall Liud892bec2018-11-30 14:51:45 -08003086 @Override
3087 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3088 INumberVerificationCallback callback, String callingPackage) {
3089 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3090 != PERMISSION_GRANTED) {
3091 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3092 }
3093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3094
3095 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3096 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3097 throw new SecurityException("Calling package must be configured in the device config");
3098 }
3099
3100 if (range == null) {
3101 throw new NullPointerException("Range must be non-null");
3102 }
3103
3104 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003105 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003106
3107 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3108 }
3109
Junda Liuca05d5d2014-08-14 22:36:34 -07003110 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 * Returns true if CDMA provisioning needs to run.
3112 */
3113 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003116 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
3122 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003123 * Sets the voice mail number of a given subId.
3124 */
3125 @Override
3126 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3128 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3133 new Pair<String, String>(alphaTag, number), new Integer(subId));
3134 return success;
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003138 }
3139
Ta-wei Yen87c49842016-05-13 21:19:52 -07003140 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003141 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003143 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3144 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003145 if (!TextUtils.equals(callingPackage, systemDialer)) {
3146 throw new SecurityException("caller must be system dialer");
3147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3152 if (phoneAccountHandle == null) {
3153 return null;
3154 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003155 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003158 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003159 }
3160
3161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003162 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3163 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003164 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003166 mApp, subId, callingPackage, callingFeatureId,
3167 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003168 return null;
3169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003171 final long identity = Binder.clearCallingIdentity();
3172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003177 }
3178
3179 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003180 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3181 VisualVoicemailSmsFilterSettings settings) {
3182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003191 }
3192
3193 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003194 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3195 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003200 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003204 }
3205
3206 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003207 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3208 String callingPackage, int subId) {
3209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003218 }
3219
3220 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003221 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003231 }
3232
3233 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003234 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3235 String callingAttributionTag, int subId, String number, int port, String text,
3236 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003237 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003238 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003239 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003240 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003241 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3242 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003243 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003244
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003245 /**
fionaxu0152e512016-11-14 13:36:14 -08003246 * Sets the voice activation state of a given subId.
3247 */
3248 @Override
3249 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3251 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 final Phone phone = getPhone(subId);
3256 if (phone != null) {
3257 phone.setVoiceActivationState(activationState);
3258 } else {
3259 loge("setVoiceActivationState fails with invalid subId: " + subId);
3260 }
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003263 }
3264 }
3265
3266 /**
3267 * Sets the data activation state of a given subId.
3268 */
3269 @Override
3270 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3272 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 final Phone phone = getPhone(subId);
3277 if (phone != null) {
3278 phone.setDataActivationState(activationState);
3279 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003280 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 }
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003284 }
3285 }
3286
3287 /**
3288 * Returns the voice activation state of a given subId.
3289 */
3290 @Override
3291 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
fionaxu0152e512016-11-14 13:36:14 -08003294 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 if (phone != null) {
3298 return phone.getVoiceActivationState();
3299 } else {
3300 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3301 }
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003304 }
3305 }
3306
3307 /**
3308 * Returns the data activation state of a given subId.
3309 */
3310 @Override
3311 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
fionaxu0152e512016-11-14 13:36:14 -08003314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 if (phone != null) {
3318 return phone.getDataActivationState();
3319 } else {
3320 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3321 }
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003324 }
3325 }
3326
3327 /**
Wink Saville36469e72014-06-11 15:17:00 -07003328 * Returns the unread count of voicemails for a subId
3329 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003331 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3332 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003334 mApp, subId, callingPackage, callingFeatureId,
3335 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003336 return 0;
3337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 final Phone phone = getPhone(subId);
3341 if (phone != null) {
3342 return phone.getVoiceMessageCount();
3343 } else {
3344 return 0;
3345 }
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349 }
3350
3351 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003352 * returns true, if the device is in a state where both voice and data
3353 * are supported simultaneously. This can change based on location or network condition.
3354 */
3355 @Override
3356 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone phone = getPhone(subId);
3360 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
3363 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003364 }
3365
3366 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003367 * Send the dialer code if called from the current default dialer or the caller has
3368 * carrier privilege.
3369 * @param inputCode The dialer code to send
3370 */
3371 @Override
3372 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003373 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003375 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3376 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003377 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003378 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003379 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003384 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
fionaxu235cc5e2017-03-06 22:25:57 -08003388 }
3389
Pengquan Menga1bb6272018-09-06 09:59:22 -07003390 @Override
3391 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003392 TelephonyPermissions
3393 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3394 mApp, subId, "getNetworkSelectionMode");
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 if (!isActiveSubscription(subId)) {
3398 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3399 }
3400 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003403 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003404 }
3405
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003407 public boolean isInEmergencySmsMode() {
3408 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 for (Phone phone : PhoneFactory.getPhones()) {
3412 if (phone.isInEmergencySmsMode()) {
3413 return true;
3414 }
3415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 return false;
3420 }
3421
shilu366312e2019-12-17 09:28:10 -08003422 /**
3423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3424 * @param subId The subscription to use to check the configuration.
3425 * @param c The callback that will be used to send the result.
3426 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003427 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003428 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3429 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003430 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3431 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003432
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003433 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3434 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3435 "IMS not available on device.");
3436 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003437 final long token = Binder.clearCallingIdentity();
3438 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (ImsException e) {
3443 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 } finally {
3445 Binder.restoreCallingIdentity(token);
3446 }
3447 }
3448
shilu366312e2019-12-17 09:28:10 -08003449 /**
3450 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3451 * @param subId The subscription to use to check the configuration.
3452 * @param c The callback that will be used to send the result.
3453 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003455 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003456 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3457 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003458 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3459 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3460 }
Meng Wangafbc5852019-09-19 17:37:13 -07003461 final long token = Binder.clearCallingIdentity();
3462 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003463 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003464 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3465 .removeRegistrationCallbackForSubscription(c, subId);
3466 } catch (ImsException e) {
3467 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3468 + "is inactive, ignoring unregister.");
3469 // If the subscription is no longer active, just return, since the callback
3470 // will already have been removed internally.
3471 } finally {
3472 Binder.restoreCallingIdentity(token);
3473 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 }
3475
Brad Ebingera34a6c22019-10-22 17:36:18 -07003476 /**
3477 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3478 */
3479 @Override
3480 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3481 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3482 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3483 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3484 "IMS not available on device.");
3485 }
3486 final long token = Binder.clearCallingIdentity();
3487 try {
3488 Phone phone = getPhone(subId);
3489 if (phone == null) {
3490 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3491 + subId + "'");
3492 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3493 }
3494 phone.getImsRegistrationState(regState -> {
3495 try {
3496 consumer.accept((regState == null)
3497 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3498 } catch (RemoteException e) {
3499 // Ignore if the remote process is no longer available to call back.
3500 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3501 }
3502 });
3503 } finally {
3504 Binder.restoreCallingIdentity(token);
3505 }
3506 }
3507
3508 /**
3509 * Get the transport type for the IMS service registration state.
3510 */
3511 @Override
3512 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003513 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3514 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003515 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3516 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3517 "IMS not available on device.");
3518 }
3519 final long token = Binder.clearCallingIdentity();
3520 try {
3521 Phone phone = getPhone(subId);
3522 if (phone == null) {
3523 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3524 + subId + "'");
3525 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3526 }
3527 phone.getImsRegistrationTech(regTech -> {
3528 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3529 int regTechConverted = (regTech == null)
3530 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3531 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3532 regTechConverted);
3533 try {
3534 consumer.accept(regTechConverted);
3535 } catch (RemoteException e) {
3536 // Ignore if the remote process is no longer available to call back.
3537 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3538 }
3539 });
3540 } finally {
3541 Binder.restoreCallingIdentity(token);
3542 }
3543 }
3544
shilu366312e2019-12-17 09:28:10 -08003545 /**
3546 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3547 * @param subId The subscription to use to check the configuration.
3548 * @param c The callback that will be used to send the result.
3549 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003551 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3552 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003553 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3554 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003555 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3557 "IMS not available on device.");
3558 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3560 final long token = Binder.clearCallingIdentity();
3561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003562 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003564 } catch (ImsException e) {
3565 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 } finally {
3567 Binder.restoreCallingIdentity(token);
3568 }
3569 }
3570
shilu366312e2019-12-17 09:28:10 -08003571 /**
3572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3573 * @param subId The subscription to use to check the configuration.
3574 * @param c The callback that will be used to send the result.
3575 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003577 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003578 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3579 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3581 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3582 }
Meng Wangafbc5852019-09-19 17:37:13 -07003583
3584 final long token = Binder.clearCallingIdentity();
3585 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003586 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003587 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003588 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003589 } catch (ImsException e) {
3590 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3591 + "is inactive, ignoring unregister.");
3592 // If the subscription is no longer active, just return, since the callback
3593 // will already have been removed internally.
3594 } finally {
3595 Binder.restoreCallingIdentity(token);
3596 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 }
3598
3599 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003600 public boolean isCapable(int subId, int capability, int regTech) {
3601 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3603 final long token = Binder.clearCallingIdentity();
3604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3609 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003610 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003611 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3612 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(token);
3615 }
3616 }
3617
3618 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003619 public boolean isAvailable(int subId, int capability, int regTech) {
3620 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 final long token = Binder.clearCallingIdentity();
3622 try {
3623 Phone phone = getPhone(subId);
3624 if (phone == null) return false;
3625 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003626 } catch (com.android.ims.ImsException e) {
3627 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3628 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(token);
3631 }
3632 }
3633
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003634 /**
3635 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3636 * subscription.
3637 * @param subId The subscription to use to check the configuration.
3638 * @param callback The callback that will be used to send the result.
3639 * @param capability The MmTelFeature capability that will be used to send the result.
3640 * @param transportType The transport type of the MmTelFeature capability.
3641 */
3642 @Override
3643 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3644 int transportType) {
3645 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3646 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3648 "IMS not available on device.");
3649 }
3650 final long token = Binder.clearCallingIdentity();
3651 try {
3652 int slotId = getSlotIndex(subId);
3653 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3654 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3655 + subId + "'");
3656 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3657 }
3658 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3659 transportType, aBoolean -> {
3660 try {
3661 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3662 } catch (RemoteException e) {
3663 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3664 + "running. Ignore");
3665 }
3666 });
3667 } finally {
3668 Binder.restoreCallingIdentity(token);
3669 }
3670 }
3671
shilu366312e2019-12-17 09:28:10 -08003672 /**
3673 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3674 * @param subId The subscription to use to check the configuration.
3675 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 @Override
3677 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003678 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3679 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003680
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3682 final long token = Binder.clearCallingIdentity();
3683 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003684 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003686 } catch (ImsException e) {
3687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 } finally {
3689 Binder.restoreCallingIdentity(token);
3690 }
3691 }
3692
3693 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003694 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003696 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003702 } catch (ImsException e) {
3703 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 }
3708
shilu366312e2019-12-17 09:28:10 -08003709 /**
3710 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3711 * @param subId The subscription to use to check the configuration.
3712 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003714 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003715 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3716 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3721 } catch (ImsException e) {
3722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
3728 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003729 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003731 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003736 } catch (ImsException e) {
3737 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
3741 }
3742
shilu366312e2019-12-17 09:28:10 -08003743 /**
3744 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3745 * @param subId The subscription to use to check the configuration.
3746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 @Override
3748 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003749 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3750 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
3763 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003764 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003766 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003771 } catch (ImsException e) {
3772 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
3776 }
3777
shilu366312e2019-12-17 09:28:10 -08003778 /**
3779 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3780 * @param subId The subscription to use to check the configuration.
3781 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 @Override
3783 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003784 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3785 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003791 } catch (ImsException e) {
3792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
3796 }
3797
3798 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003799 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003801 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003807 } catch (ImsException e) {
3808 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
3812 }
3813
3814 @Override
3815 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3817 "setVoWiFiNonPersistent");
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003821 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003822 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003823 } catch (ImsException e) {
3824 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 }
3829
shilu366312e2019-12-17 09:28:10 -08003830 /**
3831 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3832 * @param subId The subscription to use to check the configuration.
3833 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 @Override
3835 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003836 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3837 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003841 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003843 } catch (ImsException e) {
3844 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 @Override
3851 public void setVoWiFiModeSetting(int subId, int mode) {
3852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3853 "setVoWiFiModeSetting");
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003857 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003859 } catch (ImsException e) {
3860 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
3866 @Override
3867 public int getVoWiFiRoamingModeSetting(int subId) {
3868 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003872 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003874 } catch (ImsException e) {
3875 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
3879 }
3880
3881 @Override
3882 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3884 "setVoWiFiRoamingModeSetting");
3885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 } catch (ImsException e) {
3891 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
3898 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3900 "setRttCapabilityEnabled");
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3905 } catch (ImsException e) {
3906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
shilu366312e2019-12-17 09:28:10 -08003912 /**
3913 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3914 * @param subId The subscription to use to check the configuration.
3915 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 @Override
3917 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003918 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3919 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003925 } catch (ImsException e) {
3926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
3930 }
3931
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003932 @Override
3933 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3934 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003937 if (!isImsAvailableOnDevice()) {
3938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3939 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003940 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003943 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003944 } catch (ImsException e) {
3945 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
3949 }
3950
3951 @Override
3952 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3953 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3954 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003955 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3956 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3957 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003958 try {
3959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003961 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003962 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003963 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3964 + "is inactive, ignoring unregister.");
3965 // If the subscription is no longer active, just return, since the callback will already
3966 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
3970 }
3971
allenwtsu99c623b2020-01-03 18:24:23 +08003972
3973 private void checkModifyPhoneStatePermission(int subId, String message) {
3974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3975 message);
3976 }
3977
3978 private boolean isImsProvisioningRequired(int subId, int capability,
3979 boolean isMmtelCapability) {
3980 Phone phone = getPhone(subId);
3981 if (phone == null) {
3982 loge("phone instance null for subid " + subId);
3983 return false;
3984 }
3985 if (isMmtelCapability) {
3986 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3987 return false;
3988 }
3989 } else {
3990 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3991 return false;
3992 }
3993 }
3994 return true;
3995 }
3996
3997 @Override
3998 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3999 boolean isProvisioned) {
4000 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4001
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4005 if (!isImsProvisioningRequired(subId, capability, false)) {
4006 return;
4007 }
4008
4009 // this capability requires provisioning, route to the correct API.
4010 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4011 switch (capability) {
4012 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4013 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4014 ims.setEabProvisioned(isProvisioned);
4015 break;
4016 default: {
4017 throw new IllegalArgumentException("Tried to set provisioning for "
4018 + "rcs capability '" + capability + "', which does not require "
4019 + "provisioning.");
4020 }
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025
4026 }
4027
4028
4029 @Override
4030 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4031 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4035 if (!isImsProvisioningRequired(subId, capability, false)) {
4036 return true;
4037 }
4038
4039 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4040 switch (capability) {
4041 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4042 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4043 return ims.isEabProvisionedOnDevice();
4044
4045 default: {
4046 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4047 + "capability '" + capability + "', which does not require "
4048 + "provisioning.");
4049 }
4050 }
4051
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004057 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004058 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4059 boolean isProvisioned) {
4060 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4061 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4062 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4063 }
allenwtsu99c623b2020-01-03 18:24:23 +08004064 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004065 final long identity = Binder.clearCallingIdentity();
4066 try {
4067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004068 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004069 return;
4070 }
4071
4072 // this capability requires provisioning, route to the correct API.
4073 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4074 switch (capability) {
4075 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4076 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4077 ims.setVolteProvisioned(isProvisioned);
4078 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4079 ims.setWfcProvisioned(isProvisioned);
4080 }
4081 break;
4082 }
4083 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4084 // There is currently no difference in VT provisioning type.
4085 ims.setVtProvisioned(isProvisioned);
4086 break;
4087 }
4088 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4089 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4090 // change the capability of the feature instead if needed.
4091 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4092 == isProvisioned) {
4093 // No change in provisioning.
4094 return;
4095 }
4096 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4097 try {
4098 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004100 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4101 + ", Exception" + e.getMessage());
4102 }
4103 break;
4104 }
4105 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004106 throw new IllegalArgumentException("Tried to set provisioning for "
4107 + "MmTel capability '" + capability + "', which does not require "
4108 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 }
4110 }
4111
4112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
4117 @Override
4118 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4119 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4120 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4121 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4122 }
4123 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004127 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 return true;
4129 }
4130
4131 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4132 switch (capability) {
4133 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4134 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4135 return ims.isVolteProvisionedOnDevice();
4136 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4137 return ims.isWfcProvisionedOnDevice();
4138 }
4139 // This should never happen, since we are checking tech above to make sure it
4140 // is either LTE or IWLAN.
4141 throw new IllegalArgumentException("Invalid radio technology for voice "
4142 + "capability.");
4143 }
4144 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4145 // There is currently no difference in VT provisioning type.
4146 return ims.isVtProvisionedOnDevice();
4147 }
4148 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4149 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4150 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4151 }
4152 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004153 throw new IllegalArgumentException(
4154 "Tried to get provisioning for MmTel capability '" + capability
4155 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004156 }
4157 }
4158
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
4164 @Override
4165 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4166 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4167 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4168 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4169 }
4170 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4171 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4172 return (provisionedBits & capability) > 0;
4173 }
4174
4175 @Override
4176 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4177 boolean isProvisioned) {
4178 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4179 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4180 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4181 }
4182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4183 "setProvisioningStatusForCapability");
4184 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4185 // If the current provisioning status for capability already matches isProvisioned,
4186 // do nothing.
4187 if (((provisionedBits & capability) > 0) == isProvisioned) {
4188 return;
4189 }
4190 if (isProvisioned) {
4191 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4192 } else {
4193 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4194 }
4195 }
4196
4197 /**
4198 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4199 * technology. The bitfield should mirror the bitfield defined by
4200 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4201 */
4202 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4203 String key = getMmTelProvisioningKey(subId, tech);
4204 // Default is no capabilities are provisioned.
4205 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4206 }
4207
4208 /**
4209 * Sets the MmTel capability provisioning bitfield (defined by
4210 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4211 * technology specified.
4212 *
4213 * Note: This is a synchronous command and should not be called on UI thread.
4214 */
4215 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4216 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4217 String key = getMmTelProvisioningKey(subId, tech);
4218 editor.putInt(key, newField);
4219 editor.commit();
4220 }
4221
4222 private static String getMmTelProvisioningKey(int subId, int tech) {
4223 // resulting key is provision_ims_mmtel_{subId}_{tech}
4224 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4225 }
4226
4227 /**
4228 * Query CarrierConfig to see if the specified capability requires provisioning for the
4229 * carrier associated with the subscription id.
4230 */
4231 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4232 int capability) {
4233 CarrierConfigManager configManager = new CarrierConfigManager(context);
4234 PersistableBundle c = configManager.getConfigForSubId(subId);
4235 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004236 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004237 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4238 false);
4239 boolean requireVoiceVtProvisioning = c.getBoolean(
4240 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4241
4242 // First check to make sure that the capability requires provisioning.
4243 switch (capability) {
4244 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4245 // intentional fallthrough
4246 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4247 if (requireVoiceVtProvisioning) {
4248 // Voice and Video requires provisioning
4249 return true;
4250 }
4251 break;
4252 }
4253 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4254 if (requireUtProvisioning) {
4255 // UT requires provisioning
4256 return true;
4257 }
4258 break;
4259 }
4260 }
4261 return false;
4262 }
4263
allenwtsu99c623b2020-01-03 18:24:23 +08004264 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4265 int capability) {
4266 CarrierConfigManager configManager = new CarrierConfigManager(context);
4267 PersistableBundle c = configManager.getConfigForSubId(subId);
4268
4269 boolean requireRcsProvisioning = c.getBoolean(
4270 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4271
4272 // First check to make sure that the capability requires provisioning.
4273 switch (capability) {
4274 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4275 // intentional fallthrough
4276 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4277 if (requireRcsProvisioning) {
4278 // OPTION or PRESENCE requires provisioning
4279 return true;
4280 }
4281 break;
4282 }
4283 }
4284 return false;
4285 }
4286
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004287 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004288 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004289 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4290 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4291 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004292 enforceReadPrivilegedPermission("getImsProvisioningInt");
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004296 int slotId = getSlotIndex(subId);
4297 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4298 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4299 + subId + "' for key:" + key);
4300 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4301 }
4302 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004304 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4305 + subId + "' for key:" + key);
4306 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
4312 @Override
4313 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4315 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4316 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004317 enforceReadPrivilegedPermission("getImsProvisioningString");
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004321 int slotId = getSlotIndex(subId);
4322 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4323 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4324 + subId + "' for key:" + key);
4325 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4326 }
4327 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004328 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004329 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4330 + subId + "' for key:" + key);
4331 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
4335 }
4336
4337 @Override
4338 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4340 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4341 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4343 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004344 final long identity = Binder.clearCallingIdentity();
4345 try {
4346 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004347 int slotId = getSlotIndex(subId);
4348 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4349 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4350 + subId + "' for key:" + key);
4351 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4352 }
4353 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004355 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4356 + "' for key:" + key);
4357 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
4364 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004365 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4366 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4367 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4369 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 int slotId = getSlotIndex(subId);
4374 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4375 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4376 + subId + "' for key:" + key);
4377 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4378 }
4379 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004381 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4382 + "' for key:" + key);
4383 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004389 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 int slotId = SubscriptionManager.getSlotIndex(subId);
4391 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004392 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4393 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 }
4395 return slotId;
4396 }
4397
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004398 private int getSlotIndex(int subId) {
4399 int slotId = SubscriptionManager.getSlotIndex(subId);
4400 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4401 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4402 }
4403 return slotId;
4404 }
4405
Wink Saville36469e72014-06-11 15:17:00 -07004406 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004407 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004408 */
4409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004410 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4411 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004412 final int targetSdk = getTargetSdk(callingPackage);
4413 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004414 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004415 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004416 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004417 mApp, subId, callingPackage, callingFeatureId,
4418 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004419 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4420 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 final Phone phone = getPhone(subId);
4425 if (phone != null) {
4426 return phone.getServiceState().getDataNetworkType();
4427 } else {
4428 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4429 }
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004433 }
4434
4435 /**
4436 * Returns the data network type
4437 */
4438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004439 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4440 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4441 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004442 }
4443
4444 /**
4445 * Returns the data network type for a subId
4446 */
4447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004448 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4449 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004451 mApp, subId, callingPackage, callingFeatureId,
4452 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004453 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4454 }
4455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 final Phone phone = getPhone(subId);
4459 if (phone != null) {
4460 return phone.getServiceState().getDataNetworkType();
4461 } else {
4462 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4463 }
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004467 }
4468
4469 /**
Wink Saville36469e72014-06-11 15:17:00 -07004470 * Returns the Voice network type for a subId
4471 */
4472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4474 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004476 mApp, subId, callingPackage, callingFeatureId,
4477 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004478 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4479 }
4480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 final Phone phone = getPhone(subId);
4484 if (phone != null) {
4485 return phone.getServiceState().getVoiceNetworkType();
4486 } else {
4487 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4488 }
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004492 }
4493
4494 /**
4495 * @return true if a ICC card is present
4496 */
4497 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004498 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004499 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4500 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004501 }
4502
4503 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004504 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004505 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004506 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004507 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 final Phone phone = PhoneFactory.getPhone(slotIndex);
4511 if (phone != null) {
4512 return phone.getIccCard().hasIccCard();
4513 } else {
4514 return false;
4515 }
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004519 }
4520
4521 /**
4522 * Return if the current radio is LTE on CDMA. This
4523 * is a tri-state return value as for a period of time
4524 * the mode may be unknown.
4525 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004526 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004527 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004528 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004531 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4532 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4533 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004534 }
4535
Sanket Padawe356d7632015-06-22 14:03:32 -07004536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004537 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4538 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004539 try {
4540 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4541 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004542 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4543 }
4544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 final long identity = Binder.clearCallingIdentity();
4546 try {
4547 final Phone phone = getPhone(subId);
4548 if (phone == null) {
4549 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4550 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004551 return TelephonyProperties.lte_on_cdma_device()
4552 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 }
4554 } finally {
4555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004556 }
Wink Saville36469e72014-06-11 15:17:00 -07004557 }
4558
Wink Saville36469e72014-06-11 15:17:00 -07004559 /**
4560 * {@hide}
4561 * Returns Default subId, 0 in the case of single standby.
4562 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004563 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004564 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004565 }
4566
Shishir Agrawala9f32182016-04-12 12:00:16 -07004567 private int getSlotForDefaultSubscription() {
4568 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4569 }
4570
Wink Savilleb564aae2014-10-23 10:18:09 -07004571 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004572 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004573 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004574
Pengquan Menge92a50d2018-09-21 15:54:48 -07004575 private boolean isActiveSubscription(int subId) {
4576 return mSubscriptionController.isActiveSubId(subId);
4577 }
4578
Ihab Awadf2177b72013-11-25 13:33:23 -08004579 /**
4580 * @see android.telephony.TelephonyManager.WifiCallingChoices
4581 */
4582 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 final long identity = Binder.clearCallingIdentity();
4584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004585 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4587 getWhenToMakeWifiCallsDefaultPreference());
4588 } finally {
4589 Binder.restoreCallingIdentity(identity);
4590 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004591 }
4592
4593 /**
4594 * @see android.telephony.TelephonyManager.WifiCallingChoices
4595 */
4596 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 final long identity = Binder.clearCallingIdentity();
4598 try {
4599 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004600 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4602 } finally {
4603 Binder.restoreCallingIdentity(identity);
4604 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004605 }
4606
Sailesh Nepald1e68152013-12-12 19:08:02 -08004607 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004608 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004609 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004610 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004611
Jordan Liu4c733742019-02-28 12:03:40 -08004612 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4613 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4614 if (phoneId == -1) {
4615 throw new IllegalArgumentException("Given slot index: " + slotIndex
4616 + " does not correspond to an active phone");
4617 }
4618 return PhoneFactory.getPhone(phoneId);
4619 }
4620
Shishir Agrawal566b7612013-10-28 14:41:00 -07004621 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004622 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4623 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4625 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004627 if (DBG) {
4628 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4629 }
4630 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4631 p2);
4632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004633
Jordan Liu4c733742019-02-28 12:03:40 -08004634
4635 @Override
4636 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4637 int slotIndex, String callingPackage, String aid, int p2) {
4638 enforceModifyPermission();
4639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4640 if (DBG) {
4641 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4642 }
4643 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4644 callingPackage, aid, p2);
4645 }
4646
4647 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4648 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 if (TextUtils.equals(ISDR_AID, aid)) {
4652 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004653 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4654 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 if (bestComponent == null
4656 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4657 loge("The calling package is not allowed to access ISD-R.");
4658 throw new SecurityException(
4659 "The calling package is not allowed to access ISD-R.");
4660 }
Derek Tan740e1672017-06-27 14:56:27 -07004661 }
Derek Tan740e1672017-06-27 14:56:27 -07004662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004664 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4665 null /* workSource */);
4666 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 return response;
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004671 }
4672
4673 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004674 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4676 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004677 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4678 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004680
Jordan Liu4c733742019-02-28 12:03:40 -08004681 @Override
4682 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4683 enforceModifyPermission();
4684 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4685 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4686 channel);
4687 }
4688
4689 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 if (channel < 0) {
4693 return false;
4694 }
Jordan Liu4c733742019-02-28 12:03:40 -08004695 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4696 null /* workSource */);
4697 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 return success;
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004702 }
4703
4704 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004705 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004706 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4708 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004709 if (DBG) {
4710 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4711 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4712 + p3 + " data=" + data);
4713 }
4714 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4715 command, p1, p2, p3, data);
4716 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004717
Jordan Liu4c733742019-02-28 12:03:40 -08004718 @Override
4719 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4720 int command, int p1, int p2, int p3, String data) {
4721 enforceModifyPermission();
4722 if (DBG) {
4723 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4724 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4725 + p3 + " data=" + data);
4726 }
4727 return iccTransmitApduLogicalChannelWithPermission(
4728 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4729 data);
4730 }
4731
4732 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4733 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 final long identity = Binder.clearCallingIdentity();
4735 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004736 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 return "";
4738 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004741 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4742 null /* workSource */);
4743 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 // Append the returned status code to the end of the response payload.
4746 String s = Integer.toHexString(
4747 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4748 if (response.payload != null) {
4749 s = IccUtils.bytesToHexString(response.payload) + s;
4750 }
4751 return s;
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004755 }
Jake Hambye994d462014-02-03 13:10:13 -08004756
Evan Charltonc66da362014-05-16 14:06:40 -07004757 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004758 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4759 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4761 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004763 if (DBG) {
4764 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4765 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4766 }
4767 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4768 cla, command, p1, p2, p3, data);
4769 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004770
Jordan Liu4c733742019-02-28 12:03:40 -08004771 @Override
4772 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4773 int command, int p1, int p2, int p3, String data) {
4774 enforceModifyPermission();
4775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4776 if (DBG) {
4777 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4778 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4779 + " data=" + data);
4780 }
4781
4782 return iccTransmitApduBasicChannelWithPermission(
4783 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4784 p2, p3, data);
4785 }
4786
4787 // open APDU basic channel assuming the caller has sufficient permissions
4788 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4789 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4793 && TextUtils.equals(ISDR_AID, data)) {
4794 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004795 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4796 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 if (bestComponent == null
4798 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4799 loge("The calling package is not allowed to select ISD-R.");
4800 throw new SecurityException(
4801 "The calling package is not allowed to select ISD-R.");
4802 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004803 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004806 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4807 null /* workSource */);
4808 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 // Append the returned status code to the end of the response payload.
4811 String s = Integer.toHexString(
4812 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4813 if (response.payload != null) {
4814 s = IccUtils.bytesToHexString(response.payload) + s;
4815 }
4816 return s;
4817 } finally {
4818 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004819 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004820 }
4821
4822 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004823 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004824 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4826 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 if (DBG) {
4831 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4832 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4833 }
4834
4835 IccIoResult response =
4836 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4837 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4838 subId);
4839
4840 if (DBG) {
4841 log("Exchange SIM_IO [R]" + response);
4842 }
4843
4844 byte[] result = null;
4845 int length = 2;
4846 if (response.payload != null) {
4847 length = 2 + response.payload.length;
4848 result = new byte[length];
4849 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4850 } else {
4851 result = new byte[length];
4852 }
4853
4854 result[length - 1] = (byte) response.sw2;
4855 result[length - 2] = (byte) response.sw1;
4856 return result;
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004859 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004860 }
4861
Nathan Haroldb3014052017-01-25 15:57:32 -08004862 /**
4863 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4864 * on a particular subscription
4865 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004866 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4867 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004869 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004870 return null;
4871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872
4873 final long identity = Binder.clearCallingIdentity();
4874 try {
4875 if (appType != TelephonyManager.APPTYPE_USIM
4876 && appType != TelephonyManager.APPTYPE_SIM) {
4877 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4878 return null;
4879 }
4880 Object response = sendRequest(
4881 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4882 if (response instanceof String[]) {
4883 return (String[]) response;
4884 }
yincheng zhao2737e882019-09-06 17:06:54 -07004885 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004887 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 } finally {
4889 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004890 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004891 }
4892
yincheng zhao2737e882019-09-06 17:06:54 -07004893 /**
4894 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4895 * subscription.
4896 *
4897 * @param subId the id of the subscription.
4898 * @param appType the uicc app type, must be USIM or SIM.
4899 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4900 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004901 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004902 * @return number of fplmns that is successfully written to the SIM.
4903 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004904 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4905 String callingFeatureId) {
4906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4907 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004908 if (DBG) logv("no permissions for setForbiddenplmns");
4909 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4910 }
4911 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4912 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4913 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4914 }
4915 if (fplmns == null) {
4916 throw new IllegalArgumentException("Fplmn List provided is null");
4917 }
4918 for (String fplmn : fplmns) {
4919 if (!CellIdentity.isValidPlmn(fplmn)) {
4920 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4921 }
4922 }
4923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 Object response = sendRequest(
4926 CMD_SET_FORBIDDEN_PLMNS,
4927 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4928 subId);
4929 return (int) response;
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
4933 }
4934
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004935 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004936 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4938 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4943 if (response.payload == null) {
4944 return "";
4945 }
Evan Charltonc66da362014-05-16 14:06:40 -07004946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 // Append the returned status code to the end of the response payload.
4948 String s = Integer.toHexString(
4949 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4950 s = IccUtils.bytesToHexString(response.payload) + s;
4951 return s;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Evan Charltonc66da362014-05-16 14:06:40 -07004955 }
4956
Jake Hambye994d462014-02-03 13:10:13 -08004957 /**
4958 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4959 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4960 *
4961 * @param itemID the ID of the item to read
4962 * @return the NV item as a String, or null on error.
4963 */
4964 @Override
4965 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004966 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4968 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004973 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4975 return value;
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Jake Hambye994d462014-02-03 13:10:13 -08004979 }
4980
4981 /**
4982 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4983 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4984 *
4985 * @param itemID the ID of the item to read
4986 * @param itemValue the value to write, as a String
4987 * @return true on success; false on any failure
4988 */
4989 @Override
4990 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4993 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4998 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004999 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5001 return success;
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
Jake Hambye994d462014-02-03 13:10:13 -08005005 }
5006
5007 /**
5008 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5009 * Used for device configuration by some CDMA operators.
5010 *
5011 * @param preferredRoamingList byte array containing the new PRL
5012 * @return true on success; false on any failure
5013 */
5014 @Override
5015 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5017 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5022 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5023 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5024 return success;
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Jake Hambye994d462014-02-03 13:10:13 -08005028 }
5029
5030 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005031 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005032 * Used for device configuration by some CDMA operators.
5033 *
chen xu6dac5ab2018-10-26 17:39:23 -07005034 * @param slotIndex - device slot.
5035 *
Jake Hambye994d462014-02-03 13:10:13 -08005036 * @return true on success; false on any failure
5037 */
5038 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005039 public boolean resetModemConfig(int slotIndex) {
5040 Phone phone = PhoneFactory.getPhone(slotIndex);
5041 if (phone != null) {
5042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044
chen xu6dac5ab2018-10-26 17:39:23 -07005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5048 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5049 return success;
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 }
chen xu6dac5ab2018-10-26 17:39:23 -07005054 return false;
5055 }
5056
5057 /**
5058 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5059 *
5060 * @param slotIndex - device slot.
5061 *
5062 * @return true on success; false on any failure
5063 */
5064 @Override
5065 public boolean rebootModem(int slotIndex) {
5066 Phone phone = PhoneFactory.getPhone(slotIndex);
5067 if (phone != null) {
5068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, phone.getSubId(), "rebootModem");
5070
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5074 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5075 return success;
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
5079 }
5080 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005081 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005082
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public String[] getPcscfAddress(String apnType, String callingPackage,
5084 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005085 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5087 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005088 return new String[0];
5089 }
5090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005093 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
Wink Saville36469e72014-06-11 15:17:00 -07005097 }
5098
Brad Ebinger51f743a2017-01-23 13:50:20 -08005099 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005100 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5101 * {@link #disableIms(int)}.
5102 * @param slotIndex device slot.
5103 */
5104 public void resetIms(int slotIndex) {
5105 enforceModifyPermission();
5106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 if (mImsResolver == null) {
5110 // may happen if the does not support IMS.
5111 return;
5112 }
5113 mImsResolver.disableIms(slotIndex);
5114 mImsResolver.enableIms(slotIndex);
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
5118 }
5119
5120 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005121 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5122 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005123 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005124 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005125 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005129 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005130 // may happen if the device does not support IMS.
5131 return;
5132 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005133 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005137 }
5138
5139 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005140 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5141 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005142 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005143 public void disableIms(int slotId) {
5144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005148 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005149 // may happen if the device does not support IMS.
5150 return;
5151 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005152 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005156 }
5157
5158 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005159 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5160 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005161 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005162 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005163 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005164 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005168 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005169 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5170 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005171 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005172 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005176 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005177 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005178 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5179 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005180 @Override
5181 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005182 enforceModifyPermission();
5183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005187 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
5191 }
5192
5193 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005194 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005195 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005196 */
5197 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5198 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005202 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005203 // may happen if the device does not support IMS.
5204 return null;
5205 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005206 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005210 }
5211
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005212 /**
5213 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005214 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005215 */
5216 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005221 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005222 // may happen if the device does not support IMS.
5223 return null;
5224 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005225 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005229 }
5230
Brad Ebinger884c07b2018-02-15 16:17:40 -08005231 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005232 * Sets the ImsService Package Name that Telephony will bind to.
5233 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005234 * @param slotIndex the slot ID that the ImsService should bind for.
5235 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005236 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005237 * @param featureTypes An integer array of feature types associated with a packageName.
5238 * @param packageName The name of the package that the current configuration will be replaced
5239 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005240 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005241 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005242 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5243 int[] featureTypes, String packageName) {
5244 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5247 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005248 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 final long identity = Binder.clearCallingIdentity();
5251 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005252 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005253 // may happen if the device does not support IMS.
5254 return false;
5255 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005256 Map<Integer, String> featureConfig = new HashMap<>();
5257 for (int featureType : featureTypes) {
5258 featureConfig.put(featureType, packageName);
5259 }
5260 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5261 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005265 }
5266
5267 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005268 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005269 *
5270 * @param slotId The slot that the ImsService is associated with.
5271 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5272 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005273 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005274 * @return the package name of the ImsService configuration.
5275 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005276 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5277 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005278 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005279 TelephonyPermissions
5280 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5281 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5282 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005286 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005287 // may happen if the device does not support IMS.
5288 return "";
5289 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005290 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005291 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5292 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005296 }
5297
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005298 /**
5299 * Get the MmTelFeature state associated with the requested subscription id.
5300 * @param subId The subscription that the MmTelFeature is associated with.
5301 * @param callback A callback with an integer containing the
5302 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5303 */
5304 @Override
5305 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5306 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5307 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5308 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5309 "IMS not available on device.");
5310 }
5311 final long token = Binder.clearCallingIdentity();
5312 try {
5313 int slotId = getSlotIndex(subId);
5314 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5315 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5316 + subId + "'");
5317 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5318 }
5319 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5320 try {
5321 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5322 } catch (RemoteException e) {
5323 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5324 + "Ignore");
5325 }
5326 });
5327 } finally {
5328 Binder.restoreCallingIdentity(token);
5329 }
5330 }
5331
Wink Saville36469e72014-06-11 15:17:00 -07005332 public void setImsRegistrationState(boolean registered) {
5333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334
5335 final long identity = Binder.clearCallingIdentity();
5336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005337 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
Wink Saville36469e72014-06-11 15:17:00 -07005341 }
5342
5343 /**
Stuart Scott54788802015-03-30 13:18:01 -07005344 * Set the network selection mode to automatic.
5345 *
5346 */
5347 @Override
5348 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
shilufc958392020-01-20 11:36:01 -08005354 if (!isActiveSubscription(subId)) {
5355 return;
5356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5358 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
Stuart Scott54788802015-03-30 13:18:01 -07005362 }
5363
Jack Yud10cdd42020-09-28 20:28:01 -07005364 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005365 * Ask the radio to connect to the input network and change selection mode to manual.
5366 *
5367 * @param subId the id of the subscription.
5368 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5369 * the operator to attach to.
5370 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5371 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5372 * normal network selection next time.
5373 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005374 */
5375 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005376 public boolean setNetworkSelectionModeManual(
5377 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5379 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005380
5381 if (!isActiveSubscription(subId)) {
5382 return false;
5383 }
5384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005387 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005389 if (DBG) {
5390 log("setNetworkSelectionModeManual: subId: " + subId
5391 + " operator: " + operatorInfo);
5392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
5396 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005397 }
shilu84f6e8b2019-12-19 13:58:01 -08005398 /**
5399 * Get the manual network selection
5400 *
5401 * @param subId the id of the subscription.
5402 *
5403 * @return the previously saved user selected PLMN
5404 */
5405 @Override
5406 public String getManualNetworkSelectionPlmn(int subId) {
5407 TelephonyPermissions
5408 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5409 mApp, subId, "getManualNetworkSelectionPlmn");
5410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005414 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005415 }
5416
5417 final Phone phone = getPhone(subId);
5418 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005419 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005420 }
5421 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5422 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5423 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
5427 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005428
5429 /**
5430 * Scans for available networks.
5431 */
5432 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005433 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5434 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5436 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005437 LocationAccessPolicy.LocationPermissionResult locationResult =
5438 LocationAccessPolicy.checkLocationPermission(mApp,
5439 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5440 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005441 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005442 .setCallingPid(Binder.getCallingPid())
5443 .setCallingUid(Binder.getCallingUid())
5444 .setMethod("getCellNetworkScanResults")
5445 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005446 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5447 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005448 .build());
5449 switch (locationResult) {
5450 case DENIED_HARD:
5451 throw new SecurityException("Not allowed to access scan results -- location");
5452 case DENIED_SOFT:
5453 return null;
5454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
Pengquan Menga1bb6272018-09-06 09:59:22 -07005456 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 try {
5458 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005459 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005464 }
5465
5466 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005467 * Get the call forwarding info, given the call forwarding reason.
5468 */
5469 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005470 public void getCallForwarding(int subId, int callForwardingReason,
5471 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005472 enforceReadPrivilegedPermission("getCallForwarding");
5473 long identity = Binder.clearCallingIdentity();
5474 try {
5475 if (DBG) {
5476 log("getCallForwarding: subId " + subId
5477 + " callForwardingReason" + callForwardingReason);
5478 }
Hall Liu27d24262020-09-18 19:04:59 -07005479
5480 Phone phone = getPhone(subId);
5481 if (phone == null) {
5482 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005483 callback.onError(
5484 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005485 } catch (RemoteException e) {
5486 // ignore
5487 }
5488 return;
5489 }
5490
5491 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5492 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5493 @Override
5494 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5495 try {
5496 callback.onCallForwardingInfoAvailable(info);
5497 } catch (RemoteException e) {
5498 // ignore
5499 }
5500 }
5501
5502 @Override
5503 public void onError(int error) {
5504 try {
5505 callback.onError(error);
5506 } catch (RemoteException e) {
5507 // ignore
5508 }
5509 }
5510 });
5511 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
5515 }
5516
5517 /**
5518 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5519 * reason, the number to forward, and the timeout before the forwarding is attempted.
5520 */
5521 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005522 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5523 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005524 enforceModifyPermission();
5525 long identity = Binder.clearCallingIdentity();
5526 try {
5527 if (DBG) {
5528 log("setCallForwarding: subId " + subId
5529 + " callForwardingInfo" + callForwardingInfo);
5530 }
Hall Liu27d24262020-09-18 19:04:59 -07005531
5532 Phone phone = getPhone(subId);
5533 if (phone == null) {
5534 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005535 callback.accept(
5536 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005537 } catch (RemoteException e) {
5538 // ignore
5539 }
5540 return;
5541 }
5542
5543 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5544 FunctionalUtils.ignoreRemoteException(callback::accept));
5545
5546 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
5550 }
5551
5552 /**
Hall Liu27d24262020-09-18 19:04:59 -07005553 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005554 */
5555 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005556 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005557 enforceReadPrivilegedPermission("getCallForwarding");
5558 long identity = Binder.clearCallingIdentity();
5559 try {
Hall Liu27d24262020-09-18 19:04:59 -07005560
5561 Phone phone = getPhone(subId);
5562 if (phone == null) {
5563 try {
5564 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5565 } catch (RemoteException e) {
5566 // ignore
5567 }
5568 return;
5569 }
5570
5571 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5572
Shuo Qian4a594052020-01-23 11:59:30 -08005573 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005574 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
5578 }
5579
5580 /**
Hall Liu27d24262020-09-18 19:04:59 -07005581 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005582 */
5583 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005584 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005585 enforceModifyPermission();
5586 long identity = Binder.clearCallingIdentity();
5587 try {
Hall Liu27d24262020-09-18 19:04:59 -07005588 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5589
5590 Phone phone = getPhone(subId);
5591 if (phone == null) {
5592 try {
5593 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5594 } catch (RemoteException e) {
5595 // ignore
5596 }
5597 return;
5598 }
5599
5600 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5601 FunctionalUtils.ignoreRemoteException(callback::accept));
5602
5603 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
5607 }
5608
5609 /**
yinxub1bed742017-04-17 11:45:04 -07005610 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005611 *
yinxub1bed742017-04-17 11:45:04 -07005612 * @param subId id of the subscription
5613 * @param request contains the radio access networks with bands/channels to scan
5614 * @param messenger callback messenger for scan results or errors
5615 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005616 * @return the id of the requested scan which can be used to stop the scan.
5617 */
5618 @Override
5619 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005620 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5622 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005623 LocationAccessPolicy.LocationPermissionResult locationResult =
5624 LocationAccessPolicy.checkLocationPermission(mApp,
5625 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5626 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005627 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005628 .setCallingPid(Binder.getCallingPid())
5629 .setCallingUid(Binder.getCallingUid())
5630 .setMethod("requestNetworkScan")
5631 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005632 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5633 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005634 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005635 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005636 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5637 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005638 if (e != null) {
5639 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5640 throw e;
5641 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005642 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005643 return TelephonyScanManager.INVALID_SCAN_ID;
5644 }
5645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 }
Hall Liu912dfd32019-04-25 14:02:26 -07005647 int callingUid = Binder.getCallingUid();
5648 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 return mNetworkScanRequestTracker.startNetworkScan(
5652 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005653 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
yinxu504e1392017-04-12 16:03:22 -07005657 }
5658
Hall Liub2ac8ef2019-02-28 15:56:23 -08005659 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005660 NetworkScanRequest request, int subId, String callingPackage) {
5661 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005662 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5663 boolean hasNetworkScanPermission =
5664 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5665 == PERMISSION_GRANTED;
5666
5667 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5668 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5669 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005670 }
5671
5672 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5673 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005674 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5675 return new SecurityException("Specific channels must not be"
5676 + " scanned without location access.");
5677 }
5678 }
5679 }
5680
Hall Liub2ac8ef2019-02-28 15:56:23 -08005681 return null;
5682 }
5683
yinxu504e1392017-04-12 16:03:22 -07005684 /**
5685 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005686 *
5687 * @param subId id of the subscription
5688 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005689 */
5690 @Override
5691 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
Hall Liu912dfd32019-04-25 14:02:26 -07005695 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005698 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
yinxu504e1392017-04-12 16:03:22 -07005702 }
5703
5704 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005705 * Get the calculated preferred network type.
5706 * Used for debugging incorrect network type.
5707 *
5708 * @return the preferred network type, defined in RILConstants.java.
5709 */
5710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005711 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005712 final Phone defaultPhone = getDefaultPhone();
5713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005715 return RILConstants.PREFERRED_NETWORK_MODE;
5716 }
5717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Junda Liu84d15a22014-07-02 11:21:04 -07005725 }
5726
5727 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005728 * Get the preferred network type.
5729 * Used for device configuration by some CDMA operators.
5730 *
5731 * @return the preferred network type, defined in RILConstants.java.
5732 */
5733 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005734 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005735 TelephonyPermissions
5736 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5737 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 if (DBG) log("getPreferredNetworkType");
5742 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5743 int networkType = (result != null ? result[0] : -1);
5744 if (DBG) log("getPreferredNetworkType: " + networkType);
5745 return networkType;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005749 }
5750
5751 /**
5752 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005753 *
5754 * @param networkType the preferred network type, defined in RILConstants.java.
5755 * @return true on success; false on any failure.
5756 */
5757 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005758 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5760 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
5763 try {
calvinpan8ed33732020-03-12 14:17:55 +08005764 Boolean success = (Boolean) sendRequest(
5765 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005766
5767 if (success) {
5768 Settings.Global.putInt(mApp.getContentResolver(),
5769 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5770 }
calvinpan8ed33732020-03-12 14:17:55 +08005771 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5772 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005775 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005776 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005777
5778 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005779 * Get the allowed network types that store in the telephony provider.
5780 *
5781 * @param subId the id of the subscription.
5782 * @return allowedNetworkTypes the allowed network types.
5783 */
5784 @Override
5785 public long getAllowedNetworkTypes(int subId) {
5786 TelephonyPermissions
5787 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5788 mApp, subId, "getAllowedNetworkTypes");
5789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 return SubscriptionManager.getLongSubscriptionProperty(
5793 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
5797 }
5798
5799 /**
5800 * Set the allowed network types.
5801 *
5802 * @param subId the id of the subscription.
5803 * @param allowedNetworkTypes the allowed network types.
5804 * @return true on success; false on any failure.
5805 */
5806 @Override
5807 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5809 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005810
calvinpan8ed33732020-03-12 14:17:55 +08005811 SubscriptionManager.setSubscriptionProperty(subId,
5812 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5813 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005814
calvinpan8ed33732020-03-12 14:17:55 +08005815 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5816 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5817 RILConstants.PREFERRED_NETWORK_MODE);
5818 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005819 }
5820
5821 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005822 * Get the allowed network types for certain reason.
5823 *
5824 * @param subId the id of the subscription.
5825 * @param reason the reason the allowed network type change is taking place
5826 * @return the allowed network types.
5827 */
5828 @Override
5829 public long getAllowedNetworkTypesForReason(int subId,
5830 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5831 TelephonyPermissions
5832 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5833 mApp, subId, "getAllowedNetworkTypesForReason");
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
5840 }
5841
5842 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005843 * Enable/Disable E-UTRA-NR Dual Connectivity
5844 * @param subId subscription id of the sim card
5845 * @param nrDualConnectivityState expected NR dual connectivity state
5846 * This can be passed following states
5847 * <ol>
5848 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5849 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5850 * <li>Disable NR dual connectivity and force secondary cell to be released
5851 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5852 * </ol>
5853 * @return operation result.
5854 */
5855 @Override
5856 public int setNrDualConnectivityState(int subId,
5857 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5859 mApp, subId, "enableNRDualConnectivity");
5860 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
5863 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5864 nrDualConnectivityState, subId,
5865 workSource);
5866 if (DBG) log("enableNRDualConnectivity result: " + result);
5867 return result;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 /**
5874 * Is E-UTRA-NR Dual Connectivity enabled
5875 * @return true if dual connectivity is enabled else false
5876 */
5877 @Override
5878 public boolean isNrDualConnectivityEnabled(int subId) {
5879 TelephonyPermissions
5880 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5881 mApp, subId, "isNRDualConnectivityEnabled");
5882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5886 null, subId, workSource);
5887 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5888 return isEnabled;
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
5892 }
5893
5894 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005895 * Get the effective allowed network types on the device.
5896 * This API will return an intersection of allowed network types for all reasons,
5897 * including the configuration done through setAllowedNetworkTypes
5898 *
5899 * @param subId the id of the subscription.
5900 * @return the allowed network types
5901 */
5902 @Override
5903 public long getEffectiveAllowedNetworkTypes(int subId) {
5904 TelephonyPermissions
5905 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5906 mApp, subId, "getEffectiveAllowedNetworkTypes");
5907 final long identity = Binder.clearCallingIdentity();
5908 try {
5909 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
5916 * Set the allowed network types of the device and
5917 * provide the reason triggering the allowed network change.
5918 *
5919 * @param subId the id of the subscription.
5920 * @param reason the reason the allowed network type change is taking place
5921 * @param allowedNetworkTypes the allowed network types.
5922 * @return true on success; false on any failure.
5923 */
5924 @Override
5925 public boolean setAllowedNetworkTypesForReason(int subId,
5926 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5928 mApp, subId, "setAllowedNetworkTypesForReason");
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5932 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5933 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5934 RILConstants.PREFERRED_NETWORK_MODE);
5935 return setPreferredNetworkType(subId, preferredNetworkMode);
5936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
5939 }
5940
5941 /**
Miaoa84611c2019-03-15 09:21:10 +08005942 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005943 *
Miaoa84611c2019-03-15 09:21:10 +08005944 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005945 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005946 * @hide
5947 */
5948 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005949 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005952 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 try {
Miaoa84611c2019-03-15 09:21:10 +08005954 if (phone != null) {
5955 return phone.hasMatchedTetherApnSetting();
5956 } else {
5957 return false;
5958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 } finally {
5960 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005961 }
Junda Liu475951f2014-11-07 16:45:03 -08005962 }
5963
5964 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005965 * Enable or disable always reporting signal strength changes from radio.
5966 *
5967 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5968 */
5969 @Override
5970 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5971 enforceModifyPermission();
5972 enforceSystemCaller();
5973
5974 final long identity = Binder.clearCallingIdentity();
5975 final Phone phone = getPhone(subId);
5976 try {
5977 if (phone != null) {
5978 if (DBG) {
5979 log("setAlwaysReportSignalStrength: subId=" + subId
5980 + " isEnable=" + isEnable);
5981 }
5982 phone.setAlwaysReportSignalStrength(isEnable);
5983 } else {
5984 loge("setAlwaysReportSignalStrength: no phone found for subId="
5985 + subId);
5986 }
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
5990 }
5991
5992 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005993 * Get the user enabled state of Mobile Data.
5994 *
5995 * TODO: remove and use isUserDataEnabled.
5996 * This can't be removed now because some vendor codes
5997 * calls through ITelephony directly while they should
5998 * use TelephonyManager.
5999 *
6000 * @return true on enabled
6001 */
6002 @Override
6003 public boolean getDataEnabled(int subId) {
6004 return isUserDataEnabled(subId);
6005 }
6006
6007 /**
6008 * Get whether mobile data is enabled per user setting.
6009 *
6010 * There are other factors deciding whether mobile data is actually enabled, but they are
6011 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006012 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006013 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006014 *
6015 * @return {@code true} if data is enabled else {@code false}
6016 */
6017 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006018 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006019 try {
6020 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6021 null);
6022 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026
6027 final long identity = Binder.clearCallingIdentity();
6028 try {
6029 int phoneId = mSubscriptionController.getPhoneId(subId);
6030 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6031 Phone phone = PhoneFactory.getPhone(phoneId);
6032 if (phone != null) {
6033 boolean retVal = phone.isUserDataEnabled();
6034 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6035 return retVal;
6036 } else {
6037 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6038 return false;
6039 }
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006042 }
6043 }
6044
6045 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006046 * Checks if the device is capable of mobile data by considering whether whether the
6047 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6048 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006049 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006050 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006051 */
6052 @Override
6053 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006054 try {
6055 try {
6056 mApp.enforceCallingOrSelfPermission(
6057 android.Manifest.permission.ACCESS_NETWORK_STATE,
6058 null);
6059 } catch (Exception e) {
6060 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6061 "isDataEnabled");
6062 }
6063 } catch (Exception e) {
6064 enforceReadPrivilegedPermission("isDataEnabled");
6065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 int phoneId = mSubscriptionController.getPhoneId(subId);
6070 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6071 Phone phone = PhoneFactory.getPhone(phoneId);
6072 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006073 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6075 return retVal;
6076 } else {
6077 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6078 return false;
6079 }
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006082 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006083 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006084
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006085 /**
6086 * Check if data is enabled for a specific reason
6087 * @param subId Subscription index
6088 * @param reason the reason the data enable change is taking place
6089 * @return {@code true} if the overall data is enabled; {@code false} if not.
6090 */
6091 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006092 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006093 @TelephonyManager.DataEnabledReason int reason) {
6094 try {
6095 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6096 null);
6097 } catch (Exception e) {
6098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006099 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006100 }
6101
6102
6103 final long identity = Binder.clearCallingIdentity();
6104 try {
6105 int phoneId = mSubscriptionController.getPhoneId(subId);
6106 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006107 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006108 + " reason=" + reason);
6109 }
6110 Phone phone = PhoneFactory.getPhone(phoneId);
6111 if (phone != null) {
6112 boolean retVal;
6113 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6114 retVal = phone.isUserDataEnabled();
6115 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006116 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006117 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006118 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006119 return retVal;
6120 } else {
6121 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006122 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006123 + subId + " retVal=false");
6124 }
6125 return false;
6126 }
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
6130 }
6131
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006132 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006133 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006134 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6135 // Skip the check if it's one of these special uids
6136 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6137 }
6138
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006139 //load access rules from carrier configs, and check those as well: b/139133814
6140 SubscriptionController subController = SubscriptionController.getInstance();
6141 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6142 || subController == null) return privilegeFromSim;
6143
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006144 PackageManager pkgMgr = phone.getContext().getPackageManager();
6145 String[] packages = pkgMgr.getPackagesForUid(uid);
6146
6147 final long identity = Binder.clearCallingIdentity();
6148 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006149 int subId = phone.getSubId();
6150 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6151 // A test override is in place for the privileges for this subId, so don't try to
6152 // read the subscription privileges.
6153 return privilegeFromSim;
6154 }
6155 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006156 SubscriptionManager subManager = (SubscriptionManager)
6157 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6158 for (String pkg : packages) {
6159 if (subManager.canManageSubscription(subInfo, pkg)) {
6160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6161 }
6162 }
6163 return privilegeFromSim;
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
6167 }
6168
6169 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6170 String pkgName) {
6171 //load access rules from carrier configs, and check those as well: b/139133814
6172 SubscriptionController subController = SubscriptionController.getInstance();
6173 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6174 || subController == null) return privilegeFromSim;
6175
6176 final long identity = Binder.clearCallingIdentity();
6177 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006178 int subId = phone.getSubId();
6179 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6180 // A test override is in place for the privileges for this subId, so don't try to
6181 // read the subscription privileges.
6182 return privilegeFromSim;
6183 }
6184 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006185 SubscriptionManager subManager = (SubscriptionManager)
6186 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6187 return subManager.canManageSubscription(subInfo, pkgName)
6188 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006195 public int getCarrierPrivilegeStatus(int subId) {
6196 final Phone phone = getPhone(subId);
6197 if (phone == null) {
6198 loge("getCarrierPrivilegeStatus: Invalid subId");
6199 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6200 }
6201 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006202 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006203 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006204 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6205 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006206
6207 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6208 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006209 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006210 }
Junda Liu29340342014-07-10 15:23:27 -07006211
6212 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006213 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006214 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006215 final Phone phone = getPhone(subId);
6216 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006217 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006218 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6219 }
6220 UiccProfile profile =
6221 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6222 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006223 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006224 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6225 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006226 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006227 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006228 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006229 }
6230
6231 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006232 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6233 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006234 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006235 }
6236
6237 int phoneId = SubscriptionManager.getPhoneId(subId);
6238 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006239 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006240 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006241 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6242 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006243 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6244 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6245 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006246 }
6247
6248 @Override
6249 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006250 if (TextUtils.isEmpty(pkgName))
6251 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006252 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6253 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6254 UiccCard card = UiccController.getInstance().getUiccCard(i);
6255 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006256 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006257 continue;
6258 }
6259
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006260 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6261 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6262 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006263 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6264 break;
6265 }
6266 }
6267
6268 return result;
Junda Liu29340342014-07-10 15:23:27 -07006269 }
Derek Tan89e89d42014-07-08 17:00:10 -07006270
6271 @Override
Junda Liue64de782015-04-16 17:19:16 -07006272 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6273 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6274 loge("phoneId " + phoneId + " is not valid.");
6275 return null;
6276 }
6277 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006278 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006279 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006280 return null ;
6281 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006282 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006283 }
6284
Amith Yamasani6e118872016-02-19 12:53:51 -08006285 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006286 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006288 List<String> privilegedPackages = new ArrayList<>();
6289 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006290 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6291 // has UICC in that slot.
6292 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006293 if (card.hasCarrierPrivilegeRules()) {
6294 if (packages == null) {
6295 // Only check packages in user 0 for now
6296 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006297 PackageManager.MATCH_DISABLED_COMPONENTS
6298 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006299 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006300 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006301 }
6302 for (int p = packages.size() - 1; p >= 0; p--) {
6303 PackageInfo pkgInfo = packages.get(p);
6304 if (pkgInfo != null && pkgInfo.packageName != null
6305 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006306 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006307 privilegedPackages.add(pkgInfo.packageName);
6308 }
6309 }
6310 }
6311 }
6312 return privilegedPackages;
6313 }
6314
chen xuf7e9fe82019-05-09 19:31:02 -07006315 @Override
6316 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006317 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6318
6319 final long identity = Binder.clearCallingIdentity();
6320
chen xuf7e9fe82019-05-09 19:31:02 -07006321 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006322 try {
6323 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6324 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006328 }
6329 return privilegedPackages;
6330 }
6331
Wink Savilleb564aae2014-10-23 10:18:09 -07006332 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006333 final Phone phone = getPhone(subId);
6334 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006335 if (card == null) {
6336 loge("getIccId: No UICC");
6337 return null;
6338 }
6339 String iccId = card.getIccId();
6340 if (TextUtils.isEmpty(iccId)) {
6341 loge("getIccId: ICC ID is null or empty.");
6342 return null;
6343 }
6344 return iccId;
6345 }
6346
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006347 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006348 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6349 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006350 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 final String iccId = getIccId(subId);
6356 final Phone phone = getPhone(subId);
6357 if (phone == null) {
6358 return false;
6359 }
6360 final String subscriberId = phone.getSubscriberId();
6361
6362 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006363 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 + subscriberId + " to " + number);
6365 }
6366
6367 if (TextUtils.isEmpty(iccId)) {
6368 return false;
6369 }
6370
6371 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6372
6373 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6374 if (alphaTag == null) {
6375 editor.remove(alphaTagPrefKey);
6376 } else {
6377 editor.putString(alphaTagPrefKey, alphaTag);
6378 }
6379
6380 // Record both the line number and IMSI for this ICCID, since we need to
6381 // track all merged IMSIs based on line number
6382 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6383 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6384 if (number == null) {
6385 editor.remove(numberPrefKey);
6386 editor.remove(subscriberPrefKey);
6387 } else {
6388 editor.putString(numberPrefKey, number);
6389 editor.putString(subscriberPrefKey, subscriberId);
6390 }
6391
6392 editor.commit();
6393 return true;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006396 }
Derek Tan7226c842014-07-02 17:42:23 -07006397 }
6398
6399 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006400 public String getLine1NumberForDisplay(int subId, String callingPackage,
6401 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006402 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006404 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006405 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006406 return null;
6407 }
Derek Tan97ebb422014-09-05 16:55:38 -07006408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 String iccId = getIccId(subId);
6412 if (iccId != null) {
6413 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6414 if (DBG_MERGE) {
6415 log("getLine1NumberForDisplay returning "
6416 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6417 }
6418 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6421 return null;
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006424 }
Derek Tan7226c842014-07-02 17:42:23 -07006425 }
6426
6427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006428 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6429 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006431 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006432 return null;
6433 }
Derek Tan97ebb422014-09-05 16:55:38 -07006434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 String iccId = getIccId(subId);
6438 if (iccId != null) {
6439 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6440 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6441 }
6442 return null;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006445 }
Derek Tan7226c842014-07-02 17:42:23 -07006446 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006447
6448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006449 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6450 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006451 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6452 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006454 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006455 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006456 return null;
6457 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006458
Jordan Liub49b04b2019-05-06 14:45:15 -07006459 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6460 // the process, where TelephonyManager was instantiated.
6461 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006462 final long identity = Binder.clearCallingIdentity();
6463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006464 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 final TelephonyManager tele = TelephonyManager.from(context);
6466 final SubscriptionManager sub = SubscriptionManager.from(context);
6467
6468 // Figure out what subscribers are currently active
6469 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470
Jordan Liub49b04b2019-05-06 14:45:15 -07006471 // Only consider subs which match the current subId
6472 // This logic can be simplified. See b/131189269 for progress.
6473 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006474 activeSubscriberIds.add(tele.getSubscriberId(subId));
6475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476
6477 // First pass, find a number override for an active subscriber
6478 String mergeNumber = null;
6479 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6480 for (String key : prefs.keySet()) {
6481 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6482 final String subscriberId = (String) prefs.get(key);
6483 if (activeSubscriberIds.contains(subscriberId)) {
6484 final String iccId = key.substring(
6485 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6486 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6487 mergeNumber = (String) prefs.get(numberKey);
6488 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006489 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 + " for active subscriber " + subscriberId);
6491 }
6492 if (!TextUtils.isEmpty(mergeNumber)) {
6493 break;
6494 }
6495 }
6496 }
6497 }
6498
6499 // Shortcut when no active merged subscribers
6500 if (TextUtils.isEmpty(mergeNumber)) {
6501 return null;
6502 }
6503
6504 // Second pass, find all subscribers under that line override
6505 final ArraySet<String> result = new ArraySet<>();
6506 for (String key : prefs.keySet()) {
6507 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6508 final String number = (String) prefs.get(key);
6509 if (mergeNumber.equals(number)) {
6510 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6511 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6512 final String subscriberId = (String) prefs.get(subscriberKey);
6513 if (!TextUtils.isEmpty(subscriberId)) {
6514 result.add(subscriberId);
6515 }
6516 }
6517 }
6518 }
6519
6520 final String[] resultArray = result.toArray(new String[result.size()]);
6521 Arrays.sort(resultArray);
6522 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006523 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6525 }
6526 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006527 } finally {
6528 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006529 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006530 }
6531
6532 @Override
zoey chen38003472019-12-13 17:16:31 +08006533 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6534 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006535
6536 final long identity = Binder.clearCallingIdentity();
6537 try {
6538 final TelephonyManager telephonyManager = mApp.getSystemService(
6539 TelephonyManager.class);
6540 String subscriberId = telephonyManager.getSubscriberId(subId);
6541 if (subscriberId == null) {
6542 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006543 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006544 + subId);
6545 }
6546 return null;
6547 }
6548
6549 final SubscriptionInfo info = SubscriptionController.getInstance()
6550 .getSubscriptionInfo(subId);
6551 final ParcelUuid groupUuid = info.getGroupUuid();
6552 // If it doesn't belong to any group, return just subscriberId of itself.
6553 if (groupUuid == null) {
6554 return new String[]{subscriberId};
6555 }
6556
6557 // Get all subscriberIds from the group.
6558 final List<String> mergedSubscriberIds = new ArrayList<>();
6559 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006560 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006561 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006562 for (SubscriptionInfo subInfo : groupInfos) {
6563 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6564 if (subscriberId != null) {
6565 mergedSubscriberIds.add(subscriberId);
6566 }
6567 }
6568
6569 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572
6573 }
6574 }
6575
6576 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006577 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006578 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006579 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 final Phone phone = getPhone(subId);
6584 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
6587 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006588 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006589
6590 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006591 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006592 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6593 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006594 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6595 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 final Phone phone = getPhone(subId);
6600 if (phone == null) {
6601 return false;
6602 }
6603 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6604 cdmaNonRoamingList);
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006607 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006608 }
6609
6610 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006611 @Deprecated
6612 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6613 enforceModifyPermission();
6614
6615 int returnValue = 0;
6616 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006617 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006618 if(result.exception == null) {
6619 if (result.result != null) {
6620 byte[] responseData = (byte[])(result.result);
6621 if(responseData.length > oemResp.length) {
6622 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6623 responseData.length + "bytes. Buffer Size is " +
6624 oemResp.length + "bytes.");
6625 }
6626 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6627 returnValue = responseData.length;
6628 }
6629 } else {
6630 CommandException ex = (CommandException) result.exception;
6631 returnValue = ex.getCommandError().ordinal();
6632 if(returnValue > 0) returnValue *= -1;
6633 }
6634 } catch (RuntimeException e) {
6635 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6636 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6637 if(returnValue > 0) returnValue *= -1;
6638 }
6639
6640 return returnValue;
6641 }
6642
6643 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006644 public void setRadioCapability(RadioAccessFamily[] rafs) {
6645 try {
6646 ProxyController.getInstance().setRadioCapability(rafs);
6647 } catch (RuntimeException e) {
6648 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6649 }
6650 }
6651
6652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006653 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006654 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006655 try {
6656 TelephonyPermissions
6657 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6658 mApp, phone.getSubId(), "getRadioAccessFamily");
6659 } catch (SecurityException e) {
6660 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6661 throw e;
6662 }
chen xub97461a2018-10-26 14:17:57 -07006663 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006664 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006665 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 final long identity = Binder.clearCallingIdentity();
6668 try {
chen xub97461a2018-10-26 14:17:57 -07006669 TelephonyPermissions
6670 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6671 mApp, phone.getSubId(), "getRadioAccessFamily");
6672 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
chen xub97461a2018-10-26 14:17:57 -07006676 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006677 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006678
6679 @Override
6680 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006681 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006686 ImsManager.getInstance(defaultPhone.getContext(),
6687 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006691 }
6692
6693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006694 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006695 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6697 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006698 return false;
6699 }
Svet Ganovb320e182015-04-16 12:30:10 -07006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 // Check the user preference and the system-level IMS setting. Even if the user has
6704 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6705 // In the long run, we may instead need to check if there exists a connection service
6706 // which can support video calling.
6707 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006708 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709 return imsManager.isVtEnabledByPlatform()
6710 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6711 && imsManager.isVtEnabledByUser();
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006715 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006716
Andrew Leea1239f22015-03-02 17:44:07 -08006717 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006718 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6719 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006721 mApp, subId, callingPackage, callingFeatureId,
6722 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 return false;
6724 }
6725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 CarrierConfigManager configManager =
6729 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006730 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Andrew Leea1239f22015-03-02 17:44:07 -08006735 }
6736
6737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006738 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006740 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 return false;
6742 }
6743
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
6746 CarrierConfigManager configManager =
6747 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006748 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Andrew Leea1239f22015-03-02 17:44:07 -08006753 }
6754
Andrew Lee9431b832015-03-09 18:46:45 -07006755 @Override
6756 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006757 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006758 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006759 }
6760
6761 @Override
6762 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 final long identity = Binder.clearCallingIdentity();
6764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006765 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
Andrew Lee9431b832015-03-09 18:46:45 -07006769 }
6770
Hall Liuf6668912018-10-31 17:05:23 -07006771 /**
6772 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6773 * support for the feature and device firmware support.
6774 *
6775 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6776 */
6777 @Override
6778 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006780 final Phone phone = getPhone(subscriptionId);
6781 if (phone == null) {
6782 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6783 return false;
6784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006786 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6788 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006789 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 return isCarrierSupported && isDeviceSupported;
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
Hall Liu98187582018-01-22 19:15:32 -08006794 }
6795
Hall Liuf6668912018-10-31 17:05:23 -07006796 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006797 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6798 * RTT setting, will return true if the device and carrier both support RTT.
6799 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006800 */
6801 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 final long identity = Binder.clearCallingIdentity();
6803 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006804 boolean isRttSupported = isRttSupported(subscriptionId);
6805 boolean isUserRttSettingOn = Settings.Secure.getInt(
6806 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6807 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6808 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6809 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006813 }
6814
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006815 @Deprecated
6816 @Override
6817 public String getDeviceId(String callingPackage) {
6818 return getDeviceIdWithFeature(callingPackage, null);
6819 }
6820
Sanket Padawe7310cc72015-01-14 09:53:20 -08006821 /**
6822 * Returns the unique device ID of phone, for example, the IMEI for
6823 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6824 *
6825 * <p>Requires Permission:
6826 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6827 */
6828 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006829 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006830 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006831 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006832 return null;
6833 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006834 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006835 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006836 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006837 return null;
6838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 return phone.getDeviceId();
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006846 }
6847
Ping Sunc67b7c22016-03-02 19:16:45 +08006848 /**
6849 * {@hide}
6850 * Returns the IMS Registration Status on a particular subid
6851 *
6852 * @param subId
6853 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006854 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006855 Phone phone = getPhone(subId);
6856 if (phone != null) {
6857 return phone.isImsRegistered();
6858 } else {
6859 return false;
6860 }
6861 }
6862
Santos Cordon7a1885b2015-02-03 11:15:19 -08006863 @Override
6864 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006871 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006872
Tyler Gunnf70ed162019-04-03 15:28:53 -07006873 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006874 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006875 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006877 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006878 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6879 }
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006889 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006890 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6891 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 Phone phone = getPhone(subscriptionId);
6895 if (phone == null) {
6896 return null;
6897 }
6898 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
6901 }
6902 }
6903
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006904 /**
6905 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006906 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006907 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 final long identity = Binder.clearCallingIdentity();
6909 try {
6910 Phone phone = getPhone(subId);
6911 if (phone != null) {
6912 return phone.isWifiCallingEnabled();
6913 } else {
6914 return false;
6915 }
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006918 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006919 }
6920
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006921 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006922 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006923 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006924 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 final long identity = Binder.clearCallingIdentity();
6926 try {
6927 Phone phone = getPhone(subId);
6928 if (phone != null) {
6929 return phone.isVideoEnabled();
6930 } else {
6931 return false;
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006935 }
6936 }
6937
6938 /**
6939 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6940 * defined in {@link ImsRegistrationImplBase}.
6941 */
6942 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 Phone phone = getPhone(subId);
6946 if (phone != null) {
6947 return phone.getImsRegistrationTech();
6948 } else {
6949 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6950 }
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006953 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006954 }
6955
Stuart Scott8eef64f2015-04-08 15:13:54 -07006956 @Override
6957 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006958 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006959 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6960 return;
6961 }
6962
Svet Ganovcc087f82015-05-12 20:35:54 -07006963 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006964
Svet Ganovcc087f82015-05-12 20:35:54 -07006965 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006966 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6967 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006968 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006969 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006970 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006971 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006972 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6973 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006974 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006975 // There has been issues when Sms raw table somehow stores orphan
6976 // fragments. They lead to garbled message when new fragments come
6977 // in and combined with those stale ones. In case this happens again,
6978 // user can reset all network settings which will clean up this table.
6979 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006980 // Clean up IMS settings as well here.
6981 int slotId = getSlotIndex(subId);
6982 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6983 ImsManager.getInstance(mApp, slotId).factoryReset();
6984 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006985
6986 // Erase modem config if erase modem on network setting is enabled.
6987 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6988 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6989 if (configValue != null && Boolean.parseBoolean(configValue)) {
6990 sendEraseModemConfig(getDefaultPhone());
6991 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006992 } finally {
6993 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006994 }
6995 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006996
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006997 private void cleanUpSmsRawTable(Context context) {
6998 ContentResolver resolver = context.getContentResolver();
6999 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7000 resolver.delete(uri, null, null);
7001 }
7002
Narayan Kamath1c496c22015-04-16 14:40:19 +01007003 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007004 public String getSimLocaleForSubscriber(int subId) {
7005 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7006 final Phone phone = getPhone(subId);
7007 if (phone == null) {
7008 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007009 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 final long identity = Binder.clearCallingIdentity();
7012 try {
chen xu5d3637b2019-01-21 23:31:38 -08007013 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007014 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007015 if (info == null) {
7016 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7017 return null;
7018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 // Try and fetch the locale from the carrier properties or from the SIM language
7020 // preferences (EF-PL and EF-LI)...
7021 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007023 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7024 if (localeFromDefaultSim != null) {
7025 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7026 if (DBG) log("Using locale from subId: " + subId + " locale: "
7027 + localeFromDefaultSim);
7028 return localeFromDefaultSim.toLanguageTag();
7029 } else {
7030 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 }
7032 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 // The SIM language preferences only store a language (e.g. fr = French), not an
7035 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7036 // the SIM and carrier preferences does not include a country we add the country
7037 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007038 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007040 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 return mccLocale.toLanguageTag();
7042 }
7043
7044 if (DBG) log("No locale found - returning null");
7045 return null;
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007049 }
7050
7051 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007052 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007053 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007054 }
7055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 /**
7057 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7058 */
7059 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007060 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007061 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007062 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007063
Chenjie Yu1ba97252018-01-11 18:16:20 -08007064 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007065 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007066
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007067 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007068 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7069 * representing the state of the modem.
7070 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007071 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7072 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007073 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007074 */
7075 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007076 public void requestModemActivityInfo(ResultReceiver result) {
7077 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079
7080 final long identity = Binder.clearCallingIdentity();
7081 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007082 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007085 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007086 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007087
Siddharth Rayb8114062018-06-17 15:02:38 -07007088 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7089 // less than total activity duration.
7090 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7091 if (info == null) {
7092 return false;
7093 }
7094 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007095 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7096 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7097
Siddharth Rayb8114062018-06-17 15:02:38 -07007098 return (info.isValid()
7099 && (info.getSleepTimeMillis() <= activityDurationMs)
7100 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007101 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007102 && (totalTxTimeMs <= activityDurationMs));
7103 }
7104
Jack Yu85bd38a2015-11-09 11:34:32 -08007105 /**
7106 * {@hide}
7107 * Returns the service state information on specified subscription.
7108 */
7109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007110 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7111 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007113 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007114 return null;
7115 }
7116
Hall Liuf19c44f2018-11-27 14:38:17 -08007117 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7118 LocationAccessPolicy.checkLocationPermission(mApp,
7119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7120 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007121 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007122 .setCallingPid(Binder.getCallingPid())
7123 .setCallingUid(Binder.getCallingUid())
7124 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007125 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007126 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007127 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7128 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007129 .build());
7130
7131 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7132 LocationAccessPolicy.checkLocationPermission(mApp,
7133 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7134 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007135 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007136 .setCallingPid(Binder.getCallingPid())
7137 .setCallingUid(Binder.getCallingUid())
7138 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007139 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007140 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007141 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7142 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007143 .build());
7144 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7145 boolean hasFinePermission =
7146 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7147 boolean hasCoarsePermission =
7148 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7149
Jack Yu479f40e2020-10-27 21:29:25 -07007150 final Phone phone = getPhone(subId);
7151 if (phone == null) {
7152 return null;
7153 }
7154
7155 boolean isCallingPackageDataService = phone.getDataServicePackages()
7156 .contains(callingPackage);
7157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 final long identity = Binder.clearCallingIdentity();
7159 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007160 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7161 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7162 Rlog.d(LOG_TAG,
7163 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7164 return null;
7165 }
7166
Hall Liuf19c44f2018-11-27 14:38:17 -08007167 ServiceState ss = phone.getServiceState();
7168
7169 // Scrub out the location info in ServiceState depending on what level of access
7170 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007171 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007172 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7173 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 } finally {
7175 Binder.restoreCallingIdentity(identity);
7176 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007177 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007178
7179 /**
7180 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7181 *
7182 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7183 * voicemail ringtone.
7184 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7185 * PhoneAccount.
7186 */
7187 @Override
7188 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 final long identity = Binder.clearCallingIdentity();
7190 try {
7191 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7192 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007193 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007200 }
7201
7202 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007203 * Sets the per-account voicemail ringtone.
7204 *
7205 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7206 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7207 *
7208 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7209 * voicemail ringtone.
7210 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7211 * PhoneAccount.
7212 */
7213 @Override
7214 public void setVoicemailRingtoneUri(String callingPackage,
7215 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007216 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007217 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007218 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7219 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7221 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7222 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7228 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007229 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 }
7231 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007234 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007235 }
7236
7237 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007238 * Returns whether vibration is set for voicemail notification in Phone settings.
7239 *
7240 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7241 * voicemail vibration setting.
7242 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7243 */
7244 @Override
7245 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7249 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007250 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007257 }
7258
Youhan Wange64578a2016-05-02 15:32:42 -07007259 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007260 * Sets the per-account voicemail vibration.
7261 *
7262 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7263 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7264 *
7265 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7266 * voicemail vibration setting.
7267 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7268 * specific PhoneAccount.
7269 */
7270 @Override
7271 public void setVoicemailVibrationEnabled(String callingPackage,
7272 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007275 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7276 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7278 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7279 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007280 }
7281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7285 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007286 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007287 }
7288 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007291 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007292 }
7293
7294 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007295 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7296 *
7297 * @throws SecurityException if the caller does not have the required permission
7298 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007299 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007300 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007301 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007302 }
7303
7304 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007305 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7306 * permission.
7307 *
7308 * @throws SecurityException if the caller does not have the required permission
7309 */
7310 private void enforceSendSmsPermission() {
7311 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7312 }
7313
7314 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007315 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007316 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007317 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007318 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007319 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007323 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 if (componentName == null) {
7325 throw new SecurityException(
7326 "Caller not current active visual voicemail package[null]");
7327 }
7328 String vvmPackage = componentName.getPackageName();
7329 if (!callingPackage.equals(vvmPackage)) {
7330 throw new SecurityException("Caller not current active visual voicemail package["
7331 + vvmPackage + "]");
7332 }
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007335 }
7336 }
7337
7338 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007339 * Return the application ID for the app type.
7340 *
7341 * @param subId the subscription ID that this request applies to.
7342 * @param appType the uicc app type.
7343 * @return Application ID for specificied app type, or null if no uicc.
7344 */
7345 @Override
7346 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007347 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007348 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349
7350 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007351 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 if (phone == null) {
7353 return null;
7354 }
7355 String aid = null;
7356 try {
7357 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7358 .getApplicationByType(appType).getAid();
7359 } catch (Exception e) {
7360 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7361 }
7362 return aid;
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007365 }
Youhan Wange64578a2016-05-02 15:32:42 -07007366 }
7367
Youhan Wang4001d252016-05-11 10:29:41 -07007368 /**
7369 * Return the Electronic Serial Number.
7370 *
7371 * @param subId the subscription ID that this request applies to.
7372 * @return ESN or null if error.
7373 */
7374 @Override
7375 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007376 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007377 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
7379 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007380 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 if (phone == null) {
7382 return null;
7383 }
7384 String esn = null;
7385 try {
7386 esn = phone.getEsn();
7387 } catch (Exception e) {
7388 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7389 }
7390 return esn;
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007393 }
Youhan Wang4001d252016-05-11 10:29:41 -07007394 }
7395
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007396 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007397 * Return the Preferred Roaming List Version.
7398 *
7399 * @param subId the subscription ID that this request applies to.
7400 * @return PRLVersion or null if error.
7401 */
7402 @Override
7403 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007404 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007405 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406
7407 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007408 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 if (phone == null) {
7410 return null;
7411 }
7412 String cdmaPrlVersion = null;
7413 try {
7414 cdmaPrlVersion = phone.getCdmaPrlVersion();
7415 } catch (Exception e) {
7416 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7417 }
7418 return cdmaPrlVersion;
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007421 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007422 }
7423
7424 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007425 * Get snapshot of Telephony histograms
7426 * @return List of Telephony histograms
7427 * @hide
7428 */
7429 @Override
7430 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7432 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433
7434 final long identity = Binder.clearCallingIdentity();
7435 try {
7436 return RIL.getTelephonyRILTimingHistograms();
7437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007440 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007441
7442 /**
7443 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007444 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7445 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007446 * Require system privileges. In the future we may add this to carrier APIs.
7447 *
Michele Berionne482f8202018-11-27 18:57:59 -08007448 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007449 */
7450 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007451 @TelephonyManager.SetCarrierRestrictionResult
7452 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007453 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007455
Michele Berionne482f8202018-11-27 18:57:59 -08007456 if (carrierRestrictionRules == null) {
7457 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007458 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007462 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007463 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007467 }
7468
7469 /**
7470 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007471 * Get the allowed carrier list and the excluded carrier list, including the priority between
7472 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007473 * Require system privileges. In the future we may add this to carrier APIs.
7474 *
Michele Berionne482f8202018-11-27 18:57:59 -08007475 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007476 */
7477 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007478 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007479 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007484 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7485 if (response instanceof CarrierRestrictionRules) {
7486 return (CarrierRestrictionRules) response;
7487 }
7488 // Response is an Exception of some kind,
7489 // which is signalled to the user as a NULL retval
7490 return null;
7491 } catch (Exception e) {
7492 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7493 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007497 }
7498
fionaxu59545b42016-05-25 15:53:37 -07007499 /**
fionaxu59545b42016-05-25 15:53:37 -07007500 * Action set from carrier signalling broadcast receivers to enable/disable radio
7501 * @param subId the subscription ID that this action applies to.
7502 * @param enabled control enable or disable radio.
7503 * {@hide}
7504 */
7505 @Override
7506 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7507 enforceModifyPermission();
7508 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
7510 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007511 if (phone == null) {
7512 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7513 return;
7514 }
7515 try {
7516 phone.carrierActionSetRadioEnabled(enabled);
7517 } catch (Exception e) {
7518 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 } finally {
7520 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007521 }
7522 }
7523
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007524 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007525 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7526 * network status based on which carrier apps could apply actions accordingly,
7527 * enable/disable default url handler for example.
7528 *
7529 * @param subId the subscription ID that this action applies to.
7530 * @param report control start/stop reporting the default network status.
7531 * {@hide}
7532 */
7533 @Override
7534 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7535 enforceModifyPermission();
7536 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537
7538 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007539 if (phone == null) {
7540 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7541 return;
7542 }
7543 try {
7544 phone.carrierActionReportDefaultNetworkStatus(report);
7545 } catch (Exception e) {
7546 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 } finally {
7548 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007549 }
7550 }
7551
7552 /**
fionaxud9622282017-07-17 17:51:30 -07007553 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7554 * @param subId the subscription ID that this action applies to.
7555 * {@hide}
7556 */
7557 @Override
7558 public void carrierActionResetAll(int subId) {
7559 enforceModifyPermission();
7560 final Phone phone = getPhone(subId);
7561 if (phone == null) {
7562 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7563 return;
7564 }
7565 try {
7566 phone.carrierActionResetAll();
7567 } catch (Exception e) {
7568 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7569 }
7570 }
7571
7572 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007573 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7574 * bug report is being generated.
7575 */
7576 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007577 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7579 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007580 writer.println("Permission Denial: can't dump Phone from pid="
7581 + Binder.getCallingPid()
7582 + ", uid=" + Binder.getCallingUid()
7583 + "without permission "
7584 + android.Manifest.permission.DUMP);
7585 return;
7586 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007588 }
Jack Yueb89b242016-06-22 13:27:47 -07007589
Brad Ebingerdac2f002018-04-03 15:17:52 -07007590 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007591 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7592 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7593 @NonNull String[] args) {
7594 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7595 this, in.getFileDescriptor(), out.getFileDescriptor(),
7596 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007597 }
7598
Jack Yueb89b242016-06-22 13:27:47 -07007599 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007601 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 * @param reason the reason the data enable change is taking place
7603 * @param enabled True if enabling the data, otherwise disabling.
7604 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007605 */
7606 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007607 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 boolean enabled) {
7609 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7610 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7611 try {
7612 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007613 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007614 } catch (SecurityException se) {
7615 enforceModifyPermission();
7616 }
7617 } else {
7618 enforceModifyPermission();
7619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Phone phone = getPhone(subId);
7624 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007625 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7626 phone.carrierActionSetMeteredApnsEnabled(enabled);
7627 } else {
7628 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 }
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007633 }
7634 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007635
7636 /**
7637 * Get Client request stats
7638 * @return List of Client Request Stats
7639 * @hide
7640 */
7641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007642 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7643 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007646 return null;
7647 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007648 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 if (phone != null) {
7653 return phone.getClientRequestStats();
7654 }
7655
7656 return null;
7657 } finally {
7658 Binder.restoreCallingIdentity(identity);
7659 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007660 }
7661
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007662 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007663 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007664 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007665 }
Jack Yueb4124c2017-02-16 15:32:43 -08007666
7667 /**
Grace Chen70990072017-03-24 17:21:30 -07007668 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007669 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007670 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007671 * @param state State of SIM (power down, power up, pass through)
7672 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007675 *
7676 **/
7677 @Override
Grace Chen70990072017-03-24 17:21:30 -07007678 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007679 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007680 Phone phone = PhoneFactory.getPhone(slotIndex);
7681
vagdeviaf9a5b92018-08-15 16:01:53 -07007682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007687 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007691 }
7692 }
Shuo Qiandd210312017-04-12 22:11:33 +00007693
Tyler Gunn65d45c22017-06-05 11:22:26 -07007694 private boolean isUssdApiAllowed(int subId) {
7695 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007696 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007697 if (configManager == null) {
7698 return false;
7699 }
7700 PersistableBundle pb = configManager.getConfigForSubId(subId);
7701 if (pb == null) {
7702 return false;
7703 }
7704 return pb.getBoolean(
7705 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7706 }
7707
Shuo Qiandd210312017-04-12 22:11:33 +00007708 /**
7709 * Check if phone is in emergency callback mode
7710 * @return true if phone is in emergency callback mode
7711 * @param subId sub id
7712 */
goneil9c5f4872017-12-05 14:07:56 -08007713 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007714 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007715 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717
7718 final long identity = Binder.clearCallingIdentity();
7719 try {
7720 if (phone != null) {
7721 return phone.isInEcm();
7722 } else {
7723 return false;
7724 }
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007727 }
7728 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007729
7730 /**
7731 * Get the current signal strength information for the given subscription.
7732 * Because this information is not updated when the device is in a low power state
7733 * it should not be relied-upon to be current.
7734 * @param subId Subscription index
7735 * @return the most recent cached signal strength info from the modem
7736 */
7737 @Override
7738 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 final long identity = Binder.clearCallingIdentity();
7740 try {
7741 Phone p = getPhone(subId);
7742 if (p == null) {
7743 return null;
7744 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 return p.getSignalStrength();
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007750 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007751
Pengquan Meng77b7f132018-08-22 14:49:57 -07007752 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007753 * Get the current modem radio state for the given slot.
7754 * @param slotIndex slot index.
7755 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007756 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007757 * @return the current radio power state from the modem
7758 */
7759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007760 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007761 Phone phone = PhoneFactory.getPhone(slotIndex);
7762 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7764 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007765 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7766 }
7767
7768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 return phone.getRadioPowerState();
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
7774 }
7775 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7776 }
7777
7778 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007779 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7780 *
7781 * <p>Requires one of the following permissions:
7782 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7783 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7784 * privileges.
7785 *
7786 * @param subId subscription id
7787 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7788 * {@code false}.
7789 */
7790 @Override
7791 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007792 try {
7793 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7794 null);
7795 } catch (Exception e) {
7796 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7797 mApp, subId, "isDataRoamingEnabled");
7798 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007799
Pengquan Menga1bb6272018-09-06 09:59:22 -07007800 boolean isEnabled = false;
7801 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007802 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007803 Phone phone = getPhone(subId);
7804 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007805 } finally {
7806 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007807 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007808 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007809 }
7810
7811
7812 /**
7813 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7814 *
7815 * <p> Requires permission:
7816 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7817 * privileges.
7818 *
7819 * @param subId subscription id
7820 * @param isEnabled {@code true} means enable, {@code false} means disable.
7821 */
7822 @Override
7823 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7825 mApp, subId, "setDataRoamingEnabled");
7826
Pengquan Menga1bb6272018-09-06 09:59:22 -07007827 final long identity = Binder.clearCallingIdentity();
7828 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007829 Phone phone = getPhone(subId);
7830 if (phone != null) {
7831 phone.setDataRoamingEnabled(isEnabled);
7832 }
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007835 }
7836 }
7837
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007838 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007839 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007840 TelephonyPermissions
7841 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007842 mApp, subId, "isManualNetworkSelectionAllowed");
7843
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007844 boolean isAllowed = true;
7845 final long identity = Binder.clearCallingIdentity();
7846 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007847 Phone phone = getPhone(subId);
7848 if (phone != null) {
7849 isAllowed = phone.isCspPlmnEnabled();
7850 }
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 return isAllowed;
7855 }
7856
7857 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007858 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007859 // Verify that tha callingPackage belongs to the calling UID
7860 mApp.getSystemService(AppOpsManager.class)
7861 .checkPackage(Binder.getCallingUid(), callingPackage);
7862
Jordan Liu1e142fc2019-04-22 15:10:43 -07007863 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007864 try {
7865 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007866 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007867 } catch (SecurityException e) {
7868 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7869 // has carrier privileges on an active UICC
7870 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7871 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007872 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007873 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007874 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007875
7876 final long identity = Binder.clearCallingIdentity();
7877 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007878 UiccController uiccController = UiccController.getInstance();
7879 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007880 if (hasReadPermission) {
7881 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007882 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007883
7884 // Remove private info if the caller doesn't have access
7885 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7886 for (UiccCardInfo cardInfo : cardInfos) {
7887 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7888 // is available
7889 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7890 if (card == null || card.getUiccProfile() == null) {
7891 // assume no access if the card or profile is unavailable
7892 filteredInfos.add(cardInfo.getUnprivileged());
7893 continue;
7894 }
7895 UiccProfile profile = card.getUiccProfile();
7896 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7897 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7898 filteredInfos.add(cardInfo);
7899 } else {
7900 filteredInfos.add(cardInfo.getUnprivileged());
7901 }
7902 }
7903 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
7908
7909 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007910 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007911 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7916 if (slots == null) {
7917 Rlog.i(LOG_TAG, "slots is null.");
7918 return null;
7919 }
7920
7921 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7922 for (int i = 0; i < slots.length; i++) {
7923 UiccSlot slot = slots[i];
7924 if (slot == null) {
7925 continue;
7926 }
7927
Jordan Liu7be7e652019-05-06 18:55:02 +00007928 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929 UiccCard card = slot.getUiccCard();
7930 if (card != null) {
7931 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007932 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007933 cardId = slot.getEid();
7934 if (TextUtils.isEmpty(cardId)) {
7935 cardId = slot.getIccId();
7936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 }
7938
Jordan Liu857451f2019-05-09 16:35:35 -07007939 if (cardId != null) {
7940 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7941 // if cardId is an EID, it's all digits so this is fine
7942 cardId = IccUtils.stripTrailingFs(cardId);
7943 }
7944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 int cardState = 0;
7946 switch (slot.getCardState()) {
7947 case CARDSTATE_ABSENT:
7948 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7949 break;
7950 case CARDSTATE_PRESENT:
7951 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7952 break;
7953 case CARDSTATE_ERROR:
7954 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7955 break;
7956 case CARDSTATE_RESTRICTED:
7957 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7958 break;
7959 default:
7960 break;
7961
7962 }
7963
7964 infos[i] = new UiccSlotInfo(
7965 slot.isActive(),
7966 slot.isEuicc(),
7967 cardId,
7968 cardState,
7969 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007970 slot.isExtendedApduSupported(),
7971 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 }
7973 return infos;
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007976 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007977 }
7978
7979 @Override
7980 public boolean switchSlots(int[] physicalSlots) {
7981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982
7983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
7988 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007989 }
Jack Yu4c988042018-02-27 15:30:01 -08007990
7991 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007992 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007993 final long identity = Binder.clearCallingIdentity();
7994 try {
7995 return UiccController.getInstance().getCardIdForDefaultEuicc();
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
Pengquan Meng85728fb2018-03-12 16:31:21 -07008001 /**
goneil47ffb6e2018-04-06 15:40:58 -07008002 * A test API to reload the UICC profile.
8003 *
8004 * <p>Requires that the calling app has permission
8005 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8006 * @hide
8007 */
8008 @Override
8009 public void refreshUiccProfile(int subId) {
8010 enforceModifyPermission();
8011
8012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 Phone phone = getPhone(subId);
8015 if (phone == null) {
8016 return;
8017 }
8018 UiccCard uiccCard = phone.getUiccCard();
8019 if (uiccCard == null) {
8020 return;
8021 }
8022 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8023 if (uiccProfile == null) {
8024 return;
8025 }
8026 uiccProfile.refresh();
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
8030 }
8031
8032 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008033 * Returns false if the mobile data is disabled by default, otherwise return true.
8034 */
8035 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008036 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008037 }
8038
8039 /**
8040 * Returns true if the data roaming is enabled by default, i.e the system property
8041 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8042 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8043 */
8044 private boolean getDefaultDataRoamingEnabled(int subId) {
8045 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008046 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008047 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008048 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8049 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8050 return isDataRoamingEnabled;
8051 }
8052
8053 /**
8054 * Returns the default network type for the given {@code subId}, if the default network type is
8055 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8056 */
8057 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008058 List<Integer> list = TelephonyProperties.default_network();
8059 int phoneId = mSubscriptionController.getPhoneId(subId);
8060 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8061 return list.get(phoneId);
8062 }
8063 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008064 }
fionaxua13278b2018-03-21 00:08:13 -07008065
8066 @Override
8067 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008068 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008069 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070
8071 final long identity = Binder.clearCallingIdentity();
8072 try {
8073 final Phone phone = getPhone(subId);
8074 if (phone == null) {
8075 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8076 return;
8077 }
chen xueaba88a2019-03-15 13:15:10 -07008078 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8079 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008080 if (carrierPrivilegeRules == null) {
8081 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8082 } else {
8083 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 } finally {
8086 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008087 }
fionaxua13278b2018-03-21 00:08:13 -07008088 }
8089
8090 @Override
8091 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008092 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
8094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 final Phone phone = getPhone(subId);
8097 if (phone == null) {
8098 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8099 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8100 }
8101 return phone.getCarrierIdListVersion();
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008104 }
fionaxua13278b2018-03-21 00:08:13 -07008105 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008106
8107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008108 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8109 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008111 mApp, subId, callingPackage, callingFeatureId,
8112 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008113 return -1;
8114 }
8115
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
8122 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008123
8124 @Override
8125 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008126 TelephonyPermissions
8127 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008128 mApp, subId, "getCdmaRoamingMode");
8129
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
8136 }
8137
8138 @Override
8139 public boolean setCdmaRoamingMode(int subId, int mode) {
8140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8141 mApp, subId, "setCdmaRoamingMode");
8142
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
8145 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
8149 }
8150
8151 @Override
8152 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8154 mApp, subId, "setCdmaSubscriptionMode");
8155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
8161 }
8162 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008163
sqianc5eccab2018-10-19 18:46:41 -07008164 @Override
sqian8c685422019-02-22 15:55:18 -08008165 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008166 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008168 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8169 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008170 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8171 }
8172 final long identity = Binder.clearCallingIdentity();
8173 try {
sqian854d44b2018-12-12 16:48:18 -08008174 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8175 for (Phone phone: PhoneFactory.getPhones()) {
8176 if (phone.getEmergencyNumberTracker() != null
8177 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8178 emergencyNumberListInternal.put(
8179 phone.getSubId(),
8180 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8181 }
sqian11b7a0e2018-12-05 18:48:28 -08008182 }
sqian854d44b2018-12-12 16:48:18 -08008183 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008184 } finally {
8185 Binder.restoreCallingIdentity(identity);
8186 }
sqianc5eccab2018-10-19 18:46:41 -07008187 }
8188
8189 @Override
sqian8c685422019-02-22 15:55:18 -08008190 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008191 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008192 if (!exactMatch) {
8193 TelephonyPermissions
8194 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008195 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008196 }
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
sqian854d44b2018-12-12 16:48:18 -08008199 for (Phone phone: PhoneFactory.getPhones()) {
8200 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008201 && phone.getEmergencyNumberTracker()
8202 .isEmergencyNumber(number, exactMatch)) {
8203 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008204 }
sqian11b7a0e2018-12-05 18:48:28 -08008205 }
8206 return false;
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
8210 }
8211
sqianf4ca7ed2019-01-15 18:32:07 -08008212 /**
8213 * Update emergency number list for test mode.
8214 */
8215 @Override
8216 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8218 "updateEmergencyNumberListTestMode");
8219
8220 final long identity = Binder.clearCallingIdentity();
8221 try {
8222 for (Phone phone: PhoneFactory.getPhones()) {
8223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8224 if (tracker != null) {
8225 tracker.executeEmergencyNumberTestModeCommand(action, num);
8226 }
8227 }
8228 } finally {
8229 Binder.restoreCallingIdentity(identity);
8230 }
8231 }
8232
8233 /**
8234 * Get the full emergency number list for test mode.
8235 */
8236 @Override
8237 public List<String> getEmergencyNumberListTestMode() {
8238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8239 "getEmergencyNumberListTestMode");
8240
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 Set<String> emergencyNumbers = new HashSet<>();
8244 for (Phone phone: PhoneFactory.getPhones()) {
8245 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8246 if (tracker != null) {
8247 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8248 emergencyNumbers.add(num.getNumber());
8249 }
8250 }
8251 }
8252 return new ArrayList<>(emergencyNumbers);
8253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
8256 }
8257
chen xud6b45bd2018-10-30 22:27:10 -07008258 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008259 public int getEmergencyNumberDbVersion(int subId) {
8260 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8261
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 final Phone phone = getPhone(subId);
8265 if (phone == null) {
8266 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8267 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8268 }
8269 return phone.getEmergencyNumberDbVersion();
8270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
8273 }
8274
8275 @Override
8276 public void notifyOtaEmergencyNumberDbInstalled() {
8277 enforceModifyPermission();
8278
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 for (Phone phone: PhoneFactory.getPhones()) {
8282 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8283 if (tracker != null) {
8284 tracker.updateOtaEmergencyNumberDatabase();
8285 }
8286 }
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
8290 }
8291
8292 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008293 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008294 enforceActiveEmergencySessionPermission();
8295
8296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 for (Phone phone: PhoneFactory.getPhones()) {
8299 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8300 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008301 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8302 }
8303 }
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
8307 }
8308
8309 @Override
8310 public void resetOtaEmergencyNumberDbFilePath() {
8311 enforceActiveEmergencySessionPermission();
8312
8313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 for (Phone phone: PhoneFactory.getPhones()) {
8316 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8317 if (tracker != null) {
8318 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008319 }
8320 }
8321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
8324 }
8325
8326 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008327 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8328 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8329 Phone phone = getPhone(subId);
8330 if (phone == null) {
8331 return null;
8332 }
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 UiccProfile profile = UiccController.getInstance()
8336 .getUiccProfileForPhone(phone.getPhoneId());
8337 if (profile != null) {
8338 return profile.getCertsFromCarrierPrivilegeAccessRules();
8339 }
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 return null;
8344 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008345
8346 /**
8347 * Enable or disable a modem stack.
8348 */
8349 @Override
8350 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8351 enforceModifyPermission();
8352
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 Phone phone = PhoneFactory.getPhone(slotIndex);
8356 if (phone == null) {
8357 return false;
8358 } else {
8359 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8360 }
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
8364 }
Michelecea4cf22018-12-21 15:00:11 -08008365
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008366 /**
8367 * Whether a modem stack is enabled or not.
8368 */
8369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008370 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8371 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008372 Phone phone = PhoneFactory.getPhone(slotIndex);
8373 if (phone == null) return false;
8374
8375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008376 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8377 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008378 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8379 }
8380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008383 try {
8384 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8385 } catch (NoSuchElementException ex) {
8386 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8387 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
8391 }
8392
Michelecea4cf22018-12-21 15:00:11 -08008393 @Override
Michele0ea7d782019-03-19 14:58:42 -07008394 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008395 enforceModifyPermission();
8396
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008400 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008401 .commit();
8402 } finally {
8403 Binder.restoreCallingIdentity(identity);
8404 }
8405 }
8406
8407 @Override
Michele0ea7d782019-03-19 14:58:42 -07008408 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008409 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008411 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8412 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008413 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008414 }
Michelecea4cf22018-12-21 15:00:11 -08008415
8416 final long identity = Binder.clearCallingIdentity();
8417 try {
Michele0ea7d782019-03-19 14:58:42 -07008418 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
8422 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008423
Michele0ea7d782019-03-19 14:58:42 -07008424 @TelephonyManager.IsMultiSimSupportedResult
8425 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008426 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8427 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8428 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008429 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8430 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008431 }
8432 // Check if the hardware supports multisim functionality. If usage of multisim is not
8433 // supported by the modem, indicate that it is restricted.
8434 PhoneCapability staticCapability =
8435 mPhoneConfigurationManager.getStaticPhoneCapability();
8436 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008437 loge("isMultiSimSupportedInternal: no static configuration available");
8438 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008439 }
Sarah Chin7caee492020-02-18 20:49:02 +00008440 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008441 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8442 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008443 }
8444 // Check if support of multiple SIMs is restricted by carrier
8445 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008446 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008447 }
8448
Michele0ea7d782019-03-19 14:58:42 -07008449 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008450 }
8451
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008452 /**
8453 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008454 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8455 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8456 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008457 * @param numOfSims number of active sims we want to switch to
8458 */
8459 @Override
8460 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008461 if (numOfSims == 1) {
8462 enforceModifyPermission();
8463 } else {
8464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8465 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8466 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008467 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008468
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008469 try {
Michele30b57b22019-03-01 12:01:14 -08008470 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008471 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008472 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8473 return;
8474 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008475 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
8479 }
8480
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008481 @Override
8482 public boolean isApplicationOnUicc(int subId, int appType) {
8483 enforceReadPrivilegedPermission("isApplicationOnUicc");
8484 Phone phone = getPhone(subId);
8485 if (phone == null) {
8486 return false;
8487 }
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 UiccCard uiccCard = phone.getUiccCard();
8491 if (uiccCard == null) {
8492 return false;
8493 }
8494 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8495 if (uiccProfile == null) {
8496 return false;
8497 }
8498 if (TelephonyManager.APPTYPE_SIM <= appType
8499 && appType <= TelephonyManager.APPTYPE_ISIM) {
8500 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8501 }
8502 return false;
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
8507
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008508 /**
chen xub4baa772019-04-03 10:23:41 -07008509 * Get whether making changes to modem configurations will trigger reboot.
8510 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008511 */
8512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008513 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8514 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008516 mApp, subId, callingPackage, callingFeatureId,
8517 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008518 return false;
8519 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
8525 }
8526 }
8527
Nathan Harold29f5f052019-02-15 13:41:57 -08008528 private void updateModemStateMetrics() {
8529 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8530 // TODO: check the state for each modem if the api is ready.
8531 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8532 }
8533
Pengquan Meng3889a572019-01-23 11:16:29 -08008534 @Override
8535 public int[] getSlotsMapping() {
8536 enforceReadPrivilegedPermission("getSlotsMapping");
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8541 // All logical slots should have a mapping to a physical slot.
8542 int[] logicalSlotsMapping = new int[phoneCount];
8543 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8544 for (int i = 0; i < slotInfos.length; i++) {
8545 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8546 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8547 }
8548 }
8549 return logicalSlotsMapping;
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
8552 }
8553 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008554
8555 /**
8556 * Get the IRadio HAL Version
8557 */
8558 @Override
8559 public int getRadioHalVersion() {
8560 Phone phone = getDefaultPhone();
8561 if (phone == null) return -1;
8562 HalVersion hv = phone.getHalVersion();
8563 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8564 return hv.major * 100 + hv.minor;
8565 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008566
8567 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008568 * Get the current calling package name.
8569 * @return the current calling package name
8570 */
8571 @Override
8572 public String getCurrentPackageName() {
8573 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8574 }
8575
8576 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008577 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8578 * corresponding network requests on a subId.
8579 *
8580 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008581 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008582 * 2) APN is un-metered for this subscription, or
8583 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008584 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008585 *
8586 * @return whether data is allowed for a apn type.
8587 *
8588 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008589 */
8590 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008591 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008592 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8593 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008594
8595 // Now that all security checks passes, perform the operation as ourselves.
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 Phone phone = getPhone(subId);
8599 if (phone == null) return false;
8600
Jack Yu41407ee2019-05-13 16:54:09 -07008601 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008602 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
8607
8608 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008609 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008610 enforceReadPrivilegedPermission("isApnMetered");
8611
8612 // Now that all security checks passes, perform the operation as ourselves.
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 Phone phone = getPhone(subId);
8616 if (phone == null) return true; // By default return true.
8617
Jack Yu41407ee2019-05-13 16:54:09 -07008618 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008619 } finally {
8620 Binder.restoreCallingIdentity(identity);
8621 }
8622 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008623
8624 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008625 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8626 int subscriptionId, IBooleanConsumer resultCallback) {
8627 enforceModifyPermission();
8628 long token = Binder.clearCallingIdentity();
8629 try {
8630 Phone phone = getPhone(subscriptionId);
8631 if (phone == null) {
8632 try {
8633 if (resultCallback != null) {
8634 resultCallback.accept(false);
8635 }
8636 } catch (RemoteException e) {
8637 // ignore
8638 }
8639 return;
8640 }
8641 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8642 Pair.create(specifiers, (x) -> {
8643 try {
8644 if (resultCallback != null) {
8645 resultCallback.accept(x);
8646 }
8647 } catch (RemoteException e) {
8648 // ignore
8649 }
8650 });
8651 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8652 } finally {
8653 Binder.restoreCallingIdentity(token);
8654 }
8655 }
8656
8657 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008658 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008659 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008660 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8661 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8662 if (iccRecords == null) {
8663 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8664 return false;
8665 }
8666 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8667 }
8668
8669 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008670 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8671 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008672 if (callingPackage == null) {
8673 callingPackage = getCurrentPackageName();
8674 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008675 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8676 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008677 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8678 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008679 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8680 }
8681 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8682 Intent intent = new Intent();
8683 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8684 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8685 // Bring up choose default SMS subscription dialog right now
8686 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8687 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8688 mApp.startActivity(intent);
8689 }
chen xud5ca2d52019-05-28 15:20:57 -07008690
8691 @Override
8692 public String getMmsUAProfUrl(int subId) {
8693 //TODO investigate if this API should require proper permission check in R b/133791609
8694 final long identity = Binder.clearCallingIdentity();
8695 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008696 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8697 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8698 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8699 return carrierUAProfUrl;
8700 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008701 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8702 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
8708 @Override
8709 public String getMmsUserAgent(int subId) {
8710 //TODO investigate if this API should require proper permission check in R b/133791609
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008713 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8714 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8715 if (!TextUtils.isEmpty(carrierUserAgent)) {
8716 return carrierUserAgent;
8717 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008718 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8719 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008720 } finally {
8721 Binder.restoreCallingIdentity(identity);
8722 }
8723 }
Jack Yub07d4972019-05-28 16:12:25 -07008724
8725 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008726 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8727 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008728
Jack Yub07d4972019-05-28 16:12:25 -07008729 final long identity = Binder.clearCallingIdentity();
8730 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008731 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008732 if (phone == null) return false;
8733
Hall Liua62f5da2020-09-25 10:42:19 -07008734 switch (policy) {
8735 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8736 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8737 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8738 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8739 default:
8740 throw new IllegalArgumentException(policy + " is not a valid policy");
8741 }
Jack Yub07d4972019-05-28 16:12:25 -07008742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 }
8746
8747 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008748 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8749 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008750 enforceModifyPermission();
8751
changbettyd5c246e2019-12-24 15:40:37 +08008752 final long identity = Binder.clearCallingIdentity();
8753 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008754 Phone phone = getPhone(subscriptionId);
8755 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008756
Hall Liua62f5da2020-09-25 10:42:19 -07008757 switch (policy) {
8758 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8759 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8760 break;
8761 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8762 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8763 break;
8764 default:
8765 throw new IllegalArgumentException(policy + " is not a valid policy");
8766 }
changbettyd5c246e2019-12-24 15:40:37 +08008767 } finally {
8768 Binder.restoreCallingIdentity(identity);
8769 }
8770 }
8771
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008772 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008773 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008774 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8775 * otherwise.
8776 */
8777 @Override
8778 public void setCepEnabled(boolean isCepEnabled) {
8779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8780
8781 final long identity = Binder.clearCallingIdentity();
8782 try {
8783 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8784 for (Phone phone : PhoneFactory.getPhones()) {
8785 Phone defaultPhone = phone.getImsPhone();
8786 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8787 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8788 ImsPhoneCallTracker imsPhoneCallTracker =
8789 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8790 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8791 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8792 + imsPhone.getMsisdn());
8793 }
8794 }
8795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
allenwtsu46dcc572020-01-08 18:24:03 +08008799
8800 /**
8801 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8802 *
8803 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8804 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8805 * before being read.
8806 */
8807 @Override
8808 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8809 isCompressed) {
8810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8811 mApp, subId, "notifyRcsAutoConfigurationReceived");
8812 try {
8813 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8814 if (configBinder == null) {
8815 Rlog.e(LOG_TAG, "null result for getImsConfig");
8816 } else {
8817 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8818 }
8819 } catch (RemoteException e) {
8820 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8821 }
8822 }
zoey chene02881a2019-12-30 16:11:23 +08008823
8824 @Override
8825 public boolean isIccLockEnabled(int subId) {
8826 enforceReadPrivilegedPermission("isIccLockEnabled");
8827
8828 // Now that all security checks passes, perform the operation as ourselves.
8829 final long identity = Binder.clearCallingIdentity();
8830 try {
8831 Phone phone = getPhone(subId);
8832 if (phone != null && phone.getIccCard() != null) {
8833 return phone.getIccCard().getIccLockEnabled();
8834 } else {
8835 return false;
8836 }
8837 } finally {
8838 Binder.restoreCallingIdentity(identity);
8839 }
8840 }
8841
8842 /**
8843 * Set the ICC pin lock enabled or disabled.
8844 *
8845 * @return an integer representing the status of IccLock enabled or disabled in the following
8846 * three cases:
8847 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8848 * successfully.
8849 * - Positive number and zero for remaining password attempts.
8850 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8851 *
8852 */
8853 @Override
8854 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8855 enforceModifyPermission();
8856
8857 Phone phone = getPhone(subId);
8858 if (phone == null) {
8859 return 0;
8860 }
8861 // Now that all security checks passes, perform the operation as ourselves.
8862 final long identity = Binder.clearCallingIdentity();
8863 try {
8864 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8865 new Pair<Boolean, String>(enabled, password), phone, null);
8866 return attemptsRemaining;
8867
8868 } catch (Exception e) {
8869 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8870 } finally {
8871 Binder.restoreCallingIdentity(identity);
8872 }
8873 return 0;
8874 }
8875
8876 /**
8877 * Change the ICC password used in ICC pin lock.
8878 *
8879 * @return an integer representing the status of IccLock changed in the following three cases:
8880 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8881 * - Positive number and zero for remaining password attempts.
8882 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8883 *
8884 */
8885 @Override
8886 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8887 enforceModifyPermission();
8888
8889 Phone phone = getPhone(subId);
8890 if (phone == null) {
8891 return 0;
8892 }
8893 // Now that all security checks passes, perform the operation as ourselves.
8894 final long identity = Binder.clearCallingIdentity();
8895 try {
8896 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8897 new Pair<String, String>(oldPassword, newPassword), phone, null);
8898 return attemptsRemaining;
8899
8900 } catch (Exception e) {
8901 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
8905 return 0;
8906 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008907
8908 /**
8909 * Request for receiving user activity notification
8910 */
8911 @Override
8912 public void requestUserActivityNotification() {
8913 if (!mNotifyUserActivity.get()
8914 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8915 mNotifyUserActivity.set(true);
8916 }
8917 }
8918
8919 /**
8920 * Called when userActivity is signalled in the power manager.
8921 * This is safe to call from any thread, with any window manager locks held or not.
8922 */
8923 @Override
8924 public void userActivity() {
8925 // ***************************************
8926 // * Inherited from PhoneWindowManager *
8927 // ***************************************
8928 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8929 // WITH ITS LOCKS HELD.
8930 //
8931 // This code must be VERY careful about the locks
8932 // it acquires.
8933 // In fact, the current code acquires way too many,
8934 // and probably has lurking deadlocks.
8935
8936 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8937 throw new SecurityException("Only the OS may call notifyUserActivity()");
8938 }
8939
8940 if (mNotifyUserActivity.getAndSet(false)) {
8941 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8942 USER_ACTIVITY_NOTIFICATION_DELAY);
8943 }
8944 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008945
8946 @Override
8947 public boolean canConnectTo5GInDsdsMode() {
8948 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8949 }
Jack Yud10cdd42020-09-28 20:28:01 -07008950
8951 @Override
8952 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8953 String callingFeatureId) {
8954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8955 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8956 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8957 }
8958
8959 Phone phone = getPhone(subId);
8960 if (phone == null) {
8961 throw new RuntimeException("phone is not available");
8962 }
8963 // Now that all security checks passes, perform the operation as ourselves.
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
8966 return phone.getEquivalentHomePlmns();
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
8970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008971}